fix: pass english and japanese titles to watchlist dropdown
This commit is contained in:
@@ -83,16 +83,7 @@ func (h *WatchlistHandler) HandleUpdateWatchlist(w http.ResponseWriter, r *http.
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Determine display title (prefer English)
|
templates.WatchlistDropdown(int(animeID), animeTitle, animeTitleEnglish, animeTitleJapanese, animeImage, status).Render(r.Context(), w)
|
||||||
displayTitle := animeTitleEnglish
|
|
||||||
if displayTitle == "" {
|
|
||||||
displayTitle = animeTitleJapanese
|
|
||||||
}
|
|
||||||
if displayTitle == "" {
|
|
||||||
displayTitle = animeTitle
|
|
||||||
}
|
|
||||||
|
|
||||||
templates.WatchlistDropdown(int(animeID), displayTitle, animeImage, status).Render(r.Context(), w)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *WatchlistHandler) HandleDeleteWatchlist(w http.ResponseWriter, r *http.Request) {
|
func (h *WatchlistHandler) HandleDeleteWatchlist(w http.ResponseWriter, r *http.Request) {
|
||||||
@@ -138,18 +129,18 @@ func (h *WatchlistHandler) HandleDeleteWatchlist(w http.ResponseWriter, r *http.
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Determine display title for dropdown (prefer English)
|
// Extract nullable strings
|
||||||
displayTitle := ""
|
titleEnglish := ""
|
||||||
if anime.TitleEnglish.Valid && anime.TitleEnglish.String != "" {
|
if anime.TitleEnglish.Valid {
|
||||||
displayTitle = anime.TitleEnglish.String
|
titleEnglish = anime.TitleEnglish.String
|
||||||
} else if anime.TitleJapanese.Valid && anime.TitleJapanese.String != "" {
|
}
|
||||||
displayTitle = anime.TitleJapanese.String
|
titleJapanese := ""
|
||||||
} else {
|
if anime.TitleJapanese.Valid {
|
||||||
displayTitle = anime.TitleOriginal
|
titleJapanese = anime.TitleJapanese.String
|
||||||
}
|
}
|
||||||
|
|
||||||
// Otherwise return updated dropdown for anime page
|
// Otherwise return updated dropdown for anime page
|
||||||
templates.WatchlistDropdown(int(animeID), displayTitle, anime.ImageUrl, "").Render(r.Context(), w)
|
templates.WatchlistDropdown(int(animeID), anime.TitleOriginal, titleEnglish, titleJapanese, anime.ImageUrl, "").Render(r.Context(), w)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *WatchlistHandler) HandleGetWatchlist(w http.ResponseWriter, r *http.Request) {
|
func (h *WatchlistHandler) HandleGetWatchlist(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ templ AnimeDetails(anime jikan.Anime, currentStatus string) {
|
|||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
<div class="anime-actions">
|
<div class="anime-actions">
|
||||||
@WatchlistDropdown(anime.MalID, anime.Title, anime.ImageURL(), currentStatus)
|
@WatchlistDropdown(anime.MalID, anime.Title, anime.TitleEnglish, anime.TitleJapanese, anime.ImageURL(), currentStatus)
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -146,7 +146,7 @@ func joinNames(entities []jikan.NamedEntity) string {
|
|||||||
return strings.Join(names, ", ")
|
return strings.Join(names, ", ")
|
||||||
}
|
}
|
||||||
|
|
||||||
templ WatchlistDropdown(animeID int, animeTitle string, animeImage string, currentStatus string) {
|
templ WatchlistDropdown(animeID int, animeTitle string, animeTitleEnglish string, animeTitleJapanese string, animeImage string, currentStatus string) {
|
||||||
<div class="dropdown" id="watchlist-dropdown">
|
<div class="dropdown" id="watchlist-dropdown">
|
||||||
<button class="dropdown-trigger" onclick="toggleDropdown()">
|
<button class="dropdown-trigger" onclick="toggleDropdown()">
|
||||||
if currentStatus != "" {
|
if currentStatus != "" {
|
||||||
@@ -157,11 +157,11 @@ templ WatchlistDropdown(animeID int, animeTitle string, animeImage string, curre
|
|||||||
<span class="dropdown-arrow">▾</span>
|
<span class="dropdown-arrow">▾</span>
|
||||||
</button>
|
</button>
|
||||||
<div class="dropdown-menu">
|
<div class="dropdown-menu">
|
||||||
@dropdownStatusOption(animeID, animeTitle, animeImage, "watching", currentStatus)
|
@dropdownStatusOption(animeID, animeTitle, animeTitleEnglish, animeTitleJapanese, animeImage, "watching", currentStatus)
|
||||||
@dropdownStatusOption(animeID, animeTitle, animeImage, "completed", currentStatus)
|
@dropdownStatusOption(animeID, animeTitle, animeTitleEnglish, animeTitleJapanese, animeImage, "completed", currentStatus)
|
||||||
@dropdownStatusOption(animeID, animeTitle, animeImage, "on_hold", currentStatus)
|
@dropdownStatusOption(animeID, animeTitle, animeTitleEnglish, animeTitleJapanese, animeImage, "on_hold", currentStatus)
|
||||||
@dropdownStatusOption(animeID, animeTitle, animeImage, "dropped", currentStatus)
|
@dropdownStatusOption(animeID, animeTitle, animeTitleEnglish, animeTitleJapanese, animeImage, "dropped", currentStatus)
|
||||||
@dropdownStatusOption(animeID, animeTitle, animeImage, "plan_to_watch", currentStatus)
|
@dropdownStatusOption(animeID, animeTitle, animeTitleEnglish, animeTitleJapanese, animeImage, "plan_to_watch", currentStatus)
|
||||||
if currentStatus != "" {
|
if currentStatus != "" {
|
||||||
<div class="dropdown-divider"></div>
|
<div class="dropdown-divider"></div>
|
||||||
<button
|
<button
|
||||||
@@ -175,11 +175,11 @@ templ WatchlistDropdown(animeID int, animeTitle string, animeImage string, curre
|
|||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
|
||||||
templ dropdownStatusOption(animeID int, animeTitle string, animeImage string, status string, currentStatus string) {
|
templ dropdownStatusOption(animeID int, animeTitle string, animeTitleEnglish string, animeTitleJapanese string, animeImage string, status string, currentStatus string) {
|
||||||
<button
|
<button
|
||||||
class={ "dropdown-item", templ.KV("active", status == currentStatus) }
|
class={ "dropdown-item", templ.KV("active", status == currentStatus) }
|
||||||
hx-post="/api/watchlist"
|
hx-post="/api/watchlist"
|
||||||
hx-vals={ fmt.Sprintf(`{"anime_id": "%d", "anime_title": "%s", "anime_image": "%s", "status": "%s"}`, animeID, animeTitle, animeImage, status) }
|
hx-vals={ fmt.Sprintf(`{"anime_id": "%d", "anime_title": "%s", "anime_title_english": "%s", "anime_title_japanese": "%s", "anime_image": "%s", "status": "%s"}`, animeID, animeTitle, animeTitleEnglish, animeTitleJapanese, animeImage, status) }
|
||||||
hx-target="#watchlist-dropdown"
|
hx-target="#watchlist-dropdown"
|
||||||
hx-swap="outerHTML"
|
hx-swap="outerHTML"
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -206,7 +206,7 @@ func AnimeDetails(anime jikan.Anime, currentStatus string) templ.Component {
|
|||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
templ_7745c5c3_Err = WatchlistDropdown(anime.MalID, anime.Title, anime.ImageURL(), currentStatus).Render(ctx, templ_7745c5c3_Buffer)
|
templ_7745c5c3_Err = WatchlistDropdown(anime.MalID, anime.Title, anime.TitleEnglish, anime.TitleJapanese, anime.ImageURL(), currentStatus).Render(ctx, templ_7745c5c3_Buffer)
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
@@ -477,7 +477,7 @@ func joinNames(entities []jikan.NamedEntity) string {
|
|||||||
return strings.Join(names, ", ")
|
return strings.Join(names, ", ")
|
||||||
}
|
}
|
||||||
|
|
||||||
func WatchlistDropdown(animeID int, animeTitle string, animeImage string, currentStatus string) templ.Component {
|
func WatchlistDropdown(animeID int, animeTitle string, animeTitleEnglish string, animeTitleJapanese string, animeImage string, currentStatus string) templ.Component {
|
||||||
return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
|
return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
|
||||||
templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
|
templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
|
||||||
if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil {
|
if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil {
|
||||||
@@ -526,23 +526,23 @@ func WatchlistDropdown(animeID int, animeTitle string, animeImage string, curren
|
|||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
templ_7745c5c3_Err = dropdownStatusOption(animeID, animeTitle, animeImage, "watching", currentStatus).Render(ctx, templ_7745c5c3_Buffer)
|
templ_7745c5c3_Err = dropdownStatusOption(animeID, animeTitle, animeTitleEnglish, animeTitleJapanese, animeImage, "watching", currentStatus).Render(ctx, templ_7745c5c3_Buffer)
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
templ_7745c5c3_Err = dropdownStatusOption(animeID, animeTitle, animeImage, "completed", currentStatus).Render(ctx, templ_7745c5c3_Buffer)
|
templ_7745c5c3_Err = dropdownStatusOption(animeID, animeTitle, animeTitleEnglish, animeTitleJapanese, animeImage, "completed", currentStatus).Render(ctx, templ_7745c5c3_Buffer)
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
templ_7745c5c3_Err = dropdownStatusOption(animeID, animeTitle, animeImage, "on_hold", currentStatus).Render(ctx, templ_7745c5c3_Buffer)
|
templ_7745c5c3_Err = dropdownStatusOption(animeID, animeTitle, animeTitleEnglish, animeTitleJapanese, animeImage, "on_hold", currentStatus).Render(ctx, templ_7745c5c3_Buffer)
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
templ_7745c5c3_Err = dropdownStatusOption(animeID, animeTitle, animeImage, "dropped", currentStatus).Render(ctx, templ_7745c5c3_Buffer)
|
templ_7745c5c3_Err = dropdownStatusOption(animeID, animeTitle, animeTitleEnglish, animeTitleJapanese, animeImage, "dropped", currentStatus).Render(ctx, templ_7745c5c3_Buffer)
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
templ_7745c5c3_Err = dropdownStatusOption(animeID, animeTitle, animeImage, "plan_to_watch", currentStatus).Render(ctx, templ_7745c5c3_Buffer)
|
templ_7745c5c3_Err = dropdownStatusOption(animeID, animeTitle, animeTitleEnglish, animeTitleJapanese, animeImage, "plan_to_watch", currentStatus).Render(ctx, templ_7745c5c3_Buffer)
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
@@ -573,7 +573,7 @@ func WatchlistDropdown(animeID int, animeTitle string, animeImage string, curren
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func dropdownStatusOption(animeID int, animeTitle string, animeImage string, status string, currentStatus string) templ.Component {
|
func dropdownStatusOption(animeID int, animeTitle string, animeTitleEnglish string, animeTitleJapanese string, animeImage string, status string, currentStatus string) templ.Component {
|
||||||
return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
|
return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
|
||||||
templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
|
templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
|
||||||
if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil {
|
if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil {
|
||||||
@@ -617,9 +617,9 @@ func dropdownStatusOption(animeID int, animeTitle string, animeImage string, sta
|
|||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
var templ_7745c5c3_Var29 string
|
var templ_7745c5c3_Var29 string
|
||||||
templ_7745c5c3_Var29, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf(`{"anime_id": "%d", "anime_title": "%s", "anime_image": "%s", "status": "%s"}`, animeID, animeTitle, animeImage, status))
|
templ_7745c5c3_Var29, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf(`{"anime_id": "%d", "anime_title": "%s", "anime_title_english": "%s", "anime_title_japanese": "%s", "anime_image": "%s", "status": "%s"}`, animeID, animeTitle, animeTitleEnglish, animeTitleJapanese, animeImage, status))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/templates/anime.templ`, Line: 182, Col: 144}
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/templates/anime.templ`, Line: 182, Col: 242}
|
||||||
}
|
}
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var29))
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var29))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user