Skip to content

Commit

Permalink
✨ Add proper copy to clipboard
Browse files Browse the repository at this point in the history
  • Loading branch information
wesen committed Dec 31, 2024
1 parent 09dda72 commit 7e9c964
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 302 deletions.
5 changes: 4 additions & 1 deletion pkg/server/handlers/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ func (h *Handlers) Index() http.HandlerFunc {
}

component := pages.Index(h.state.GetAllRepositories(), h.state.Repos)
component.Render(r.Context(), w)
err := component.Render(r.Context(), w)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
}
}
20 changes: 16 additions & 4 deletions pkg/server/handlers/prompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ func (h *Handlers) PromptList() http.HandlerFunc {

prompts := repository.GetPromptosByGroup(group)
component := components.PromptList(prompts)
component.Render(r.Context(), w)
err := component.Render(r.Context(), w)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
}
}

Expand All @@ -54,7 +57,10 @@ func (h *Handlers) PromptContent() http.HandlerFunc {
allPrompts = append(allPrompts, repo.GetPromptos()...)
}
component := components.PromptList(allPrompts)
component.Render(r.Context(), w)
err := component.Render(r.Context(), w)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
return
}

Expand All @@ -74,7 +80,10 @@ func (h *Handlers) PromptContent() http.HandlerFunc {
}

component := components.PromptList(prompts)
component.Render(r.Context(), w)
err := component.Render(r.Context(), w)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
return
}

Expand Down Expand Up @@ -153,6 +162,9 @@ func (h *Handlers) Search() http.HandlerFunc {
}

component := components.PromptList(matchingPrompts)
component.Render(r.Context(), w)
err := component.Render(r.Context(), w)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
}
}
100 changes: 0 additions & 100 deletions pkg/server/legacy-handlers/handlers.go

This file was deleted.

86 changes: 0 additions & 86 deletions pkg/server/legacy-handlers/prompt_handler.go

This file was deleted.

24 changes: 0 additions & 24 deletions pkg/server/legacy-handlers/refresh_handler.go

This file was deleted.

21 changes: 0 additions & 21 deletions pkg/server/legacy-handlers/repositories_handler.go

This file was deleted.

14 changes: 0 additions & 14 deletions pkg/server/static/templates/repoList.html

This file was deleted.

40 changes: 0 additions & 40 deletions pkg/server/static/templates/root.html

This file was deleted.

22 changes: 19 additions & 3 deletions pkg/server/templates/pages/index.templ
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,15 @@ import (
)

script copyToClipboard(text string) {
navigator.clipboard.writeText(text).then(() => {
// Could add a toast notification here
});
fetch("/prompts/" + text)
.then(response => response.text())
.then(content => {
navigator.clipboard.writeText(content).then(() => {
const toastEl = document.getElementById('copyToast');
const toast = new bootstrap.Toast(toastEl);
toast.show();
});
});
}

script addToFavorites(name string) {
Expand All @@ -17,6 +23,16 @@ script addToFavorites(name string) {

templ Index(repositories []string, repos map[string]*pkg.Repository) {
@templates.Layout() {
<div class="toast-container position-fixed bottom-0 end-0 p-3">
<div id="copyToast" class="toast align-items-center text-bg-success" role="alert" aria-live="assertive" aria-atomic="true">
<div class="d-flex">
<div class="toast-body">
<i class="bi bi-clipboard-check me-2"></i>Prompt copied to clipboard!
</div>
<button type="button" class="btn-close btn-close-white me-2 m-auto" data-bs-dismiss="toast" aria-label="Close"></button>
</div>
</div>
</div>
<div class="row g-4">
<div class="col-12 col-lg-8">
<div class="mb-4">
Expand Down
Loading

0 comments on commit 7e9c964

Please sign in to comment.