package progress import "time" import "fmt" type ImageDownloadStartNotificationData struct { ID string Subreddit string PostURL string PostName string PostTitle string AutoRemoveDuration time.Duration } templ ImageDownloadStartNotification(data ImageDownloadStartNotificationData) {
0 { x-data={ fmt.Sprintf("{ init() { setTimeout(() => $el.remove(), %d) }}", data.AutoRemoveDuration.Milliseconds()) } } onclick="this.remove()" class="alert alert-info hover:bg-info-content transition-all" > { data.Subreddit }: Start Downloading { truncateTitle(data.PostTitle) }
} func truncateTitle(s string) string { if len(s) > 20 { return s[:20] + "..." } return s } type ImageDownloadEndNotificationData struct { ID string Subreddit string PostURL string PostName string PostTitle string AutoRemoveDuration time.Duration } templ ImageDownloadEndNotification(data ImageDownloadEndNotificationData) {
0 { x-data={ fmt.Sprintf("{ init() { setTimeout(() => $el.remove(), %d) }}", data.AutoRemoveDuration.Milliseconds()) } } onclick="this.remove()" class="alert alert-success hover:bg-success-content transition-all" > { data.Subreddit }: Finished Downloading { truncateTitle(data.PostTitle) }
} type ImageDownloadErrorNotificationData struct { ID string Subreddit string PostURL string PostName string PostTitle string Error error AutoRemoveDuration time.Duration } templ ImageDownloadErrorNotification(data ImageDownloadErrorNotificationData) {
0 { x-data={ fmt.Sprintf("{ init() { setTimeout(() => $el.remove(), %d) }}", data.AutoRemoveDuration.Milliseconds()) } } onclick="this.remove()" class="alert alert-error hover:bg-error-content transition-all" > { data.Subreddit }: { data.Error.Error() } { truncateTitle(data.PostTitle) }
} type ImageDownloadProgressNotificationData struct { ID string Subreddit string PostURL string PostName string PostTitle string ContentLength int64 Downloaded int64 AutoRemoveDuration time.Duration } func (i ImageDownloadProgressNotificationData) GetProgress() float64 { return float64(i.Downloaded) / float64(i.ContentLength) } templ ImageDownloadProgressNotification(data ImageDownloadProgressNotificationData) {
0 { x-data={ fmt.Sprintf("{ init() { setTimeout(() => $el.remove(), %d) }}", data.AutoRemoveDuration.Milliseconds()) } } onclick="this.remove()" class="alert alert-info hover:bg-info-content transition-all" > { data.Subreddit }: Progress: { fmt.Sprintf("%.2f%%", data.GetProgress()*100) } { truncateTitle(data.PostTitle) }
}