wip: update event
This commit is contained in:
parent
0c623d1bf1
commit
d902a2b8c1
|
@ -4,6 +4,9 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"io"
|
"io"
|
||||||
|
|
||||||
|
"github.com/tigorlazuardi/redmage/pkg/errs"
|
||||||
|
"github.com/tigorlazuardi/redmage/views/components/progress"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ImageDownloadEvent string
|
type ImageDownloadEvent string
|
||||||
|
@ -31,12 +34,19 @@ type ImageDownload struct {
|
||||||
|
|
||||||
// Render the template.
|
// Render the template.
|
||||||
func (im ImageDownload) Render(ctx context.Context, w io.Writer) error {
|
func (im ImageDownload) Render(ctx context.Context, w io.Writer) error {
|
||||||
panic("not implemented") // TODO: Implement
|
switch im.EventKind {
|
||||||
|
case ImageDownloadStart:
|
||||||
|
return progress.ImageDownloadStartNotification(progress.ImageDownloadStartNotificationData{}).Render(ctx, w)
|
||||||
|
case ImageDownloadEnd:
|
||||||
|
return progress.ImageDownloadEndNotification(progress.ImageDownloadEndNotificationData{}).Render(ctx, w)
|
||||||
|
default:
|
||||||
|
return errs.Fail("events.ImageDownload: unknown event kind", "event", im)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Event returns the event name
|
// Event returns the event name
|
||||||
func (im ImageDownload) Event() string {
|
func (im ImageDownload) Event() string {
|
||||||
return "image.download"
|
return "image.download.notification"
|
||||||
}
|
}
|
||||||
|
|
||||||
// SerializeTo writes the event data to the writer.
|
// SerializeTo writes the event data to the writer.
|
||||||
|
|
|
@ -1,23 +1,69 @@
|
||||||
package progress
|
package progress
|
||||||
|
|
||||||
type ImageDownloadStartData struct {
|
import "time"
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
|
type ImageDownloadStartNotificationData struct {
|
||||||
ID string
|
ID string
|
||||||
Subreddit string
|
Subreddit string
|
||||||
PostURL string
|
PostURL string
|
||||||
PostName string
|
PostName string
|
||||||
PostTitle string
|
PostTitle string
|
||||||
|
AutoRemoveDuration time.Duration
|
||||||
}
|
}
|
||||||
|
|
||||||
templ ImageDownloadStart(data ImageDownloadStartData) {
|
templ ImageDownloadStartNotification(data ImageDownloadStartNotificationData) {
|
||||||
|
<div
|
||||||
|
id={ data.ID }
|
||||||
|
if data.AutoRemoveDuration > 0 {
|
||||||
|
x-data={ fmt.Sprintf("{ init() { setTimeout(() => $el.remove(), %d) }}", data.AutoRemoveDuration.Milliseconds()) }
|
||||||
|
}
|
||||||
|
onclick="this.remove()"
|
||||||
|
class="alert alert-info hover:bg-success-content transition-all"
|
||||||
|
>
|
||||||
|
<span>
|
||||||
|
<a
|
||||||
|
target="_blank"
|
||||||
|
href={ templ.SafeURL(fmt.Sprintf("https://www.reddit.com/r/%s", data.Subreddit)) }
|
||||||
|
>{ data.Subreddit }</a>:
|
||||||
|
Start Downloading
|
||||||
|
<a href={ templ.SafeURL(data.PostURL) }>{ truncateTitle(data.PostTitle) }</a>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
}
|
}
|
||||||
|
|
||||||
type ImageDownloadEndData struct {
|
func truncateTitle(s string) string {
|
||||||
|
if len(s) > 20 {
|
||||||
|
return s[:20] + "..."
|
||||||
|
}
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
type ImageDownloadEndNotificationData struct {
|
||||||
ID string
|
ID string
|
||||||
Subreddit string
|
Subreddit string
|
||||||
PostURL string
|
PostURL string
|
||||||
PostName string
|
PostName string
|
||||||
PostTitle string
|
PostTitle string
|
||||||
|
AutoRemoveDuration time.Duration
|
||||||
}
|
}
|
||||||
|
|
||||||
templ ImageDownloadEnd(data ImageDownloadEndData) {
|
templ ImageDownloadEndNotification(data ImageDownloadEndNotificationData) {
|
||||||
|
<div
|
||||||
|
id={ data.ID }
|
||||||
|
if data.AutoRemoveDuration > 0 {
|
||||||
|
x-data={ fmt.Sprintf("{ init() { setTimeout(() => $el.remove(), %d) }}", data.AutoRemoveDuration.Milliseconds()) }
|
||||||
|
}
|
||||||
|
onclick="this.remove()"
|
||||||
|
class="alert alert-info hover:bg-success-content transition-all"
|
||||||
|
>
|
||||||
|
<span>
|
||||||
|
<a
|
||||||
|
target="_blank"
|
||||||
|
href={ templ.SafeURL(fmt.Sprintf("https://www.reddit.com/r/%s", data.Subreddit)) }
|
||||||
|
>{ data.Subreddit }</a>:
|
||||||
|
Finished Downloading
|
||||||
|
<a href={ templ.SafeURL(data.PostURL) }>{ truncateTitle(data.PostTitle) }</a>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue