channels_templ.go
16030 bytes
1// Code generated by templ - DO NOT EDIT.
2
3// templ: version: v0.3.1020
4package pages
5
6//lint:file-ignore SA4006 This context is only used if a nested component is present.
7
8import "github.com/a-h/templ"
9import templruntime "github.com/a-h/templ/runtime"
10
11import (
12 "fmt"
13
14 "github.com/TheEdgeOfRage/ytrssil-api/models"
15)
16
17func unsubscribeModal(channelID string) templ.Component {
18 return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
19 templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
20 if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil {
21 return templ_7745c5c3_CtxErr
22 }
23 templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
24 if !templ_7745c5c3_IsBuffer {
25 defer func() {
26 templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
27 if templ_7745c5c3_Err == nil {
28 templ_7745c5c3_Err = templ_7745c5c3_BufErr
29 }
30 }()
31 }
32 ctx = templ.InitializeContext(ctx)
33 templ_7745c5c3_Var1 := templ.GetChildren(ctx)
34 if templ_7745c5c3_Var1 == nil {
35 templ_7745c5c3_Var1 = templ.NopComponent
36 }
37 ctx = templ.ClearChildren(ctx)
38 templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 1, "<div class=\"modal fade\" id=\"")
39 if templ_7745c5c3_Err != nil {
40 return templ_7745c5c3_Err
41 }
42 var templ_7745c5c3_Var2 string
43 templ_7745c5c3_Var2, templ_7745c5c3_Err = templ.ResolveAttributeValue(fmt.Sprintf("unsubscribe-modal-%s", channelID))
44 if templ_7745c5c3_Err != nil {
45 return templ.Error{Err: templ_7745c5c3_Err, FileName: `pages/channels.templ`, Line: 10, Col: 76}
46 }
47 _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var2)
48 if templ_7745c5c3_Err != nil {
49 return templ_7745c5c3_Err
50 }
51 templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 2, "\" tabindex=\"-1\"><div class=\"modal-dialog\"><div class=\"modal-content\"><div class=\"modal-header\"><h1 class=\"modal-title fs-5\">Confirm Unsubscribe</h1><button type=\"button\" class=\"btn-close\" data-bs-dismiss=\"modal\"></button></div><div class=\"modal-body\"><p>Are you sure you want to unsubscribe from this channel?</p></div><div class=\"modal-footer\"><button type=\"button\" class=\"btn btn-secondary\" data-bs-dismiss=\"modal\">Cancel</button> <button type=\"button\" class=\"btn btn-danger\" data-bs-dismiss=\"modal\" data-on:click=\"")
52 if templ_7745c5c3_Err != nil {
53 return templ_7745c5c3_Err
54 }
55 var templ_7745c5c3_Var3 string
56 templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.ResolveAttributeValue(fmt.Sprintf("@post('/channels/%s/unsubscribe')", channelID))
57 if templ_7745c5c3_Err != nil {
58 return templ.Error{Err: templ_7745c5c3_Err, FileName: `pages/channels.templ`, Line: 26, Col: 81}
59 }
60 _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var3)
61 if templ_7745c5c3_Err != nil {
62 return templ_7745c5c3_Err
63 }
64 templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 3, "\">Unsubscribe</button></div></div></div></div>")
65 if templ_7745c5c3_Err != nil {
66 return templ_7745c5c3_Err
67 }
68 return nil
69 })
70}
71
72func shortsToggle(channel models.Channel) templ.Component {
73 return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
74 templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
75 if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil {
76 return templ_7745c5c3_CtxErr
77 }
78 templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
79 if !templ_7745c5c3_IsBuffer {
80 defer func() {
81 templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
82 if templ_7745c5c3_Err == nil {
83 templ_7745c5c3_Err = templ_7745c5c3_BufErr
84 }
85 }()
86 }
87 ctx = templ.InitializeContext(ctx)
88 templ_7745c5c3_Var4 := templ.GetChildren(ctx)
89 if templ_7745c5c3_Var4 == nil {
90 templ_7745c5c3_Var4 = templ.NopComponent
91 }
92 ctx = templ.ClearChildren(ctx)
93 var templ_7745c5c3_Var5 = []any{fmt.Sprintf("btn btn-sm %s", ifShortsEnabled(channel.EnableShorts))}
94 templ_7745c5c3_Err = templ.RenderCSSItems(ctx, templ_7745c5c3_Buffer, templ_7745c5c3_Var5...)
95 if templ_7745c5c3_Err != nil {
96 return templ_7745c5c3_Err
97 }
98 templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 4, "<button type=\"button\" class=\"")
99 if templ_7745c5c3_Err != nil {
100 return templ_7745c5c3_Err
101 }
102 var templ_7745c5c3_Var6 string
103 templ_7745c5c3_Var6, templ_7745c5c3_Err = templ.ResolveAttributeValue(templ.CSSClasses(templ_7745c5c3_Var5).String())
104 if templ_7745c5c3_Err != nil {
105 return templ.Error{Err: templ_7745c5c3_Err, FileName: `pages/channels.templ`, Line: 1, Col: 0}
106 }
107 _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var6)
108 if templ_7745c5c3_Err != nil {
109 return templ_7745c5c3_Err
110 }
111 templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 5, "\" data-on:click=\"")
112 if templ_7745c5c3_Err != nil {
113 return templ_7745c5c3_Err
114 }
115 var templ_7745c5c3_Var7 string
116 templ_7745c5c3_Var7, templ_7745c5c3_Err = templ.ResolveAttributeValue(fmt.Sprintf("$enable = %t; @post('/channels/%s/toggle-shorts')", !channel.EnableShorts, channel.ID))
117 if templ_7745c5c3_Err != nil {
118 return templ.Error{Err: templ_7745c5c3_Err, FileName: `pages/channels.templ`, Line: 40, Col: 117}
119 }
120 _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var7)
121 if templ_7745c5c3_Err != nil {
122 return templ_7745c5c3_Err
123 }
124 templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 6, "\" title=\"")
125 if templ_7745c5c3_Err != nil {
126 return templ_7745c5c3_Err
127 }
128 var templ_7745c5c3_Var8 string
129 templ_7745c5c3_Var8, templ_7745c5c3_Err = templ.ResolveAttributeValue(toggleLabel(channel.EnableShorts))
130 if templ_7745c5c3_Err != nil {
131 return templ.Error{Err: templ_7745c5c3_Err, FileName: `pages/channels.templ`, Line: 41, Col: 43}
132 }
133 _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var8)
134 if templ_7745c5c3_Err != nil {
135 return templ_7745c5c3_Err
136 }
137 templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 7, "\"><svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24\" viewBox=\"0 0 24 24\" width=\"24\" focusable=\"false\" fill=\"currentColor\"><path d=\"m13.974 2.052-8 4.7a4 4 0 00.385 7.097l.942.423-1.327.78a4 4 0 004.052 6.897l8-4.7a4.001 4.001 0 00-.384-7.096L16.7 9.73l1.326-.78a4 4 0 10-4.052-6.897ZM10 15V9l5 3-5 3Z\"></path></svg></button>")
138 if templ_7745c5c3_Err != nil {
139 return templ_7745c5c3_Err
140 }
141 return nil
142 })
143}
144
145func ifShortsEnabled(enabled bool) string {
146 if enabled {
147 return "btn-success"
148 }
149 return "btn-outline-secondary"
150}
151
152func toggleLabel(enabled bool) string {
153 if enabled {
154 return "Shorts: ON"
155 }
156 return "Shorts: OFF"
157}
158
159func ChannelCard(channel models.Channel) templ.Component {
160 return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
161 templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
162 if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil {
163 return templ_7745c5c3_CtxErr
164 }
165 templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
166 if !templ_7745c5c3_IsBuffer {
167 defer func() {
168 templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
169 if templ_7745c5c3_Err == nil {
170 templ_7745c5c3_Err = templ_7745c5c3_BufErr
171 }
172 }()
173 }
174 ctx = templ.InitializeContext(ctx)
175 templ_7745c5c3_Var9 := templ.GetChildren(ctx)
176 if templ_7745c5c3_Var9 == nil {
177 templ_7745c5c3_Var9 = templ.NopComponent
178 }
179 ctx = templ.ClearChildren(ctx)
180 templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 8, "<div id=\"")
181 if templ_7745c5c3_Err != nil {
182 return templ_7745c5c3_Err
183 }
184 var templ_7745c5c3_Var10 string
185 templ_7745c5c3_Var10, templ_7745c5c3_Err = templ.ResolveAttributeValue(fmt.Sprintf("channel-card-%s", channel.ID))
186 if templ_7745c5c3_Err != nil {
187 return templ.Error{Err: templ_7745c5c3_Err, FileName: `pages/channels.templ`, Line: 69, Col: 53}
188 }
189 _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var10)
190 if templ_7745c5c3_Err != nil {
191 return templ_7745c5c3_Err
192 }
193 templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 9, "\" class=\"channel-card col-md-3 p-2\">")
194 if templ_7745c5c3_Err != nil {
195 return templ_7745c5c3_Err
196 }
197 templ_7745c5c3_Err = unsubscribeModal(channel.ID).Render(ctx, templ_7745c5c3_Buffer)
198 if templ_7745c5c3_Err != nil {
199 return templ_7745c5c3_Err
200 }
201 templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 10, "<div class=\"card\"><div class=\"card-body d-flex align-items-center\">")
202 if templ_7745c5c3_Err != nil {
203 return templ_7745c5c3_Err
204 }
205 if channel.ImageURL != "" {
206 templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 11, "<img src=\"")
207 if templ_7745c5c3_Err != nil {
208 return templ_7745c5c3_Err
209 }
210 var templ_7745c5c3_Var11 string
211 templ_7745c5c3_Var11, templ_7745c5c3_Err = templ.ResolveAttributeValue(channel.ImageURL)
212 if templ_7745c5c3_Err != nil {
213 return templ.Error{Err: templ_7745c5c3_Err, FileName: `pages/channels.templ`, Line: 75, Col: 28}
214 }
215 _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var11)
216 if templ_7745c5c3_Err != nil {
217 return templ_7745c5c3_Err
218 }
219 templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 12, "\" alt=\"")
220 if templ_7745c5c3_Err != nil {
221 return templ_7745c5c3_Err
222 }
223 var templ_7745c5c3_Var12 string
224 templ_7745c5c3_Var12, templ_7745c5c3_Err = templ.ResolveAttributeValue(channel.Name)
225 if templ_7745c5c3_Err != nil {
226 return templ.Error{Err: templ_7745c5c3_Err, FileName: `pages/channels.templ`, Line: 76, Col: 24}
227 }
228 _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var12)
229 if templ_7745c5c3_Err != nil {
230 return templ_7745c5c3_Err
231 }
232 templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 13, "\" class=\"rounded-circle me-3\" style=\"width: 48px; height: 48px; object-fit: cover;\">")
233 if templ_7745c5c3_Err != nil {
234 return templ_7745c5c3_Err
235 }
236 }
237 templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 14, "<div class=\"flex-grow-1\"><h5 class=\"card-title mb-1\"><a href=\"")
238 if templ_7745c5c3_Err != nil {
239 return templ_7745c5c3_Err
240 }
241 var templ_7745c5c3_Var13 templ.SafeURL
242 templ_7745c5c3_Var13, templ_7745c5c3_Err = templ.JoinURLErrs(templ.SafeURL(fmt.Sprintf("https://www.youtube.com/channel/%s", channel.ID)))
243 if templ_7745c5c3_Err != nil {
244 return templ.Error{Err: templ_7745c5c3_Err, FileName: `pages/channels.templ`, Line: 84, Col: 90}
245 }
246 _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var13))
247 if templ_7745c5c3_Err != nil {
248 return templ_7745c5c3_Err
249 }
250 templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 15, "\" target=\"_blank\" rel=\"noopener\" data-open-in-safari class=\"link-light link-underline-opacity-0\">")
251 if templ_7745c5c3_Err != nil {
252 return templ_7745c5c3_Err
253 }
254 var templ_7745c5c3_Var14 string
255 templ_7745c5c3_Var14, templ_7745c5c3_Err = templ.JoinStringErrs(channel.Name)
256 if templ_7745c5c3_Err != nil {
257 return templ.Error{Err: templ_7745c5c3_Err, FileName: `pages/channels.templ`, Line: 90, Col: 21}
258 }
259 _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var14))
260 if templ_7745c5c3_Err != nil {
261 return templ_7745c5c3_Err
262 }
263 templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 16, "</a></h5><p class=\"card-text mb-0 text-muted\">")
264 if templ_7745c5c3_Err != nil {
265 return templ_7745c5c3_Err
266 }
267 var templ_7745c5c3_Var15 string
268 templ_7745c5c3_Var15, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d", channel.UnwatchedCount))
269 if templ_7745c5c3_Err != nil {
270 return templ.Error{Err: templ_7745c5c3_Err, FileName: `pages/channels.templ`, Line: 94, Col: 49}
271 }
272 _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var15))
273 if templ_7745c5c3_Err != nil {
274 return templ_7745c5c3_Err
275 }
276 templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 17, " unwatched</p></div><div class=\"d-flex gap-2 align-items-center\">")
277 if templ_7745c5c3_Err != nil {
278 return templ_7745c5c3_Err
279 }
280 templ_7745c5c3_Err = shortsToggle(channel).Render(ctx, templ_7745c5c3_Buffer)
281 if templ_7745c5c3_Err != nil {
282 return templ_7745c5c3_Err
283 }
284 templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 18, "<button class=\"btn btn-danger ms-2\" data-bs-toggle=\"modal\" data-bs-target=\"")
285 if templ_7745c5c3_Err != nil {
286 return templ_7745c5c3_Err
287 }
288 var templ_7745c5c3_Var16 string
289 templ_7745c5c3_Var16, templ_7745c5c3_Err = templ.ResolveAttributeValue(fmt.Sprintf("#unsubscribe-modal-%s", channel.ID))
290 if templ_7745c5c3_Err != nil {
291 return templ.Error{Err: templ_7745c5c3_Err, FileName: `pages/channels.templ`, Line: 102, Col: 71}
292 }
293 _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var16)
294 if templ_7745c5c3_Err != nil {
295 return templ_7745c5c3_Err
296 }
297 templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 19, "\"><i class=\"bi bi-bookmark-dash\"></i></button></div></div></div></div>")
298 if templ_7745c5c3_Err != nil {
299 return templ_7745c5c3_Err
300 }
301 return nil
302 })
303}
304
305func ChannelsPage(channels []models.Channel) templ.Component {
306 return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
307 templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
308 if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil {
309 return templ_7745c5c3_CtxErr
310 }
311 templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
312 if !templ_7745c5c3_IsBuffer {
313 defer func() {
314 templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
315 if templ_7745c5c3_Err == nil {
316 templ_7745c5c3_Err = templ_7745c5c3_BufErr
317 }
318 }()
319 }
320 ctx = templ.InitializeContext(ctx)
321 templ_7745c5c3_Var17 := templ.GetChildren(ctx)
322 if templ_7745c5c3_Var17 == nil {
323 templ_7745c5c3_Var17 = templ.NopComponent
324 }
325 ctx = templ.ClearChildren(ctx)
326 templ_7745c5c3_Var18 := templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
327 templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
328 templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
329 if !templ_7745c5c3_IsBuffer {
330 defer func() {
331 templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
332 if templ_7745c5c3_Err == nil {
333 templ_7745c5c3_Err = templ_7745c5c3_BufErr
334 }
335 }()
336 }
337 ctx = templ.InitializeContext(ctx)
338 templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 20, "<div id=\"channels-list\" class=\"row\">")
339 if templ_7745c5c3_Err != nil {
340 return templ_7745c5c3_Err
341 }
342 for _, channel := range channels {
343 templ_7745c5c3_Err = ChannelCard(channel).Render(ctx, templ_7745c5c3_Buffer)
344 if templ_7745c5c3_Err != nil {
345 return templ_7745c5c3_Err
346 }
347 }
348 templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 21, "</div>")
349 if templ_7745c5c3_Err != nil {
350 return templ_7745c5c3_Err
351 }
352 return nil
353 })
354 templ_7745c5c3_Err = BaseLayout("ytrssil - Channels", "channels").Render(templ.WithChildren(ctx, templ_7745c5c3_Var18), templ_7745c5c3_Buffer)
355 if templ_7745c5c3_Err != nil {
356 return templ_7745c5c3_Err
357 }
358 return nil
359 })
360}
361
362var _ = templruntime.GeneratedTemplate