From fdb6ef3b7635c8d5c3b81ab9b5eefc32f73cd5e0 Mon Sep 17 00:00:00 2001 From: Christian Beutel <> Date: Fri, 22 Aug 2025 17:19:12 +0200 Subject: [PATCH] adds category to trail card/item/feed --- db/main.go | 9 ++++++- .../lib/components/profile/feed_card.svelte | 24 ++++++++++++----- .../lib/components/trail/trail_card.svelte | 27 ++++++++++++------- .../components/trail/trail_list_item.svelte | 17 +++++++++--- 4 files changed, 57 insertions(+), 20 deletions(-) diff --git a/db/main.go b/db/main.go index ebea0094..dead885b 100644 --- a/db/main.go +++ b/db/main.go @@ -931,7 +931,14 @@ func listFeedHandler() func(e *core.RecordsListRequestEvent) error { errs := e.App.ExpandRecord(item, []string{"author"}, nil) if len(errs) > 0 { - return fmt.Errorf("failed to expand: %v", errs) + return fmt.Errorf("failed to expand author: %v", errs) + } + + if typ == string(util.TrailFeed) { + errs := e.App.ExpandRecord(item, []string{"category"}, nil) + if len(errs) > 0 { + return fmt.Errorf("failed to expand category: %v", errs) + } } r.MergeExpand(map[string]any{"item": item}) diff --git a/web/src/lib/components/profile/feed_card.svelte b/web/src/lib/components/profile/feed_card.svelte index 87cf1dca..fa8d761e 100644 --- a/web/src/lib/components/profile/feed_card.svelte +++ b/web/src/lib/components/profile/feed_card.svelte @@ -20,10 +20,13 @@ let fullDescription = $state(false); - const timeSince = $derived(formatTimeSince(new Date(feedItem.created ?? ""))); + const timeSince = $derived( + formatTimeSince(new Date(feedItem.created ?? "")), + ); const photos = $derived((feedItem.expand.item as Trail).photos); const location = $derived((feedItem.expand.item as Trail).location); + const category = $derived((feedItem.expand.item as Trail).expand?.category?.name); const trails = $derived((feedItem.expand.item as List).trails); @@ -69,14 +72,21 @@ `@${author?.preferred_username}@${author?.domain}/${feedItem.item}`} >
-

+

{feedItem.expand.item.name}

- {#if location} -
- {location} -
- {/if} +
+ {#if category} +

+ {$_(category)} +

+ {/if} + {#if location} +

+ {location} +

+ {/if} +
diff --git a/web/src/lib/components/trail/trail_card.svelte b/web/src/lib/components/trail/trail_card.svelte index 104d32ec..4b450e40 100644 --- a/web/src/lib/components/trail/trail_card.svelte +++ b/web/src/lib/components/trail/trail_card.svelte @@ -13,7 +13,6 @@ import { _ } from "svelte-i18n"; import type { MouseEventHandler } from "svelte/elements"; import Chip from "../base/chip.svelte"; - import { fade, slide } from "svelte/transition"; interface Props { trail: Trail; @@ -70,6 +69,7 @@ class="trail-card relative rounded-2xl border border-input-border min-w-72 h-[386px] {fullWidth ? '' : 'lg:w-72'} cursor-pointer flex flex-col" + class:bg-secondary-hover={selected} {onmouseenter} {onmouseleave} role="listitem" @@ -133,7 +133,10 @@ {/if} {#if $currentUser && trail.like_count > 0}
@@ -194,17 +197,23 @@ {/if}
{/if} -
- {#if trail.location} -
- {trail.location} -
+ +
+ {#if trail.category} +

+ {$_(trail.category)} +

{/if} -
+ {#if trail.location} +

+ {trail.location} +

+ {/if} +

{$_( trail.difficulty ?? "?", )} -

+

{#if isVideoURL(thumbnail)} @@ -150,10 +151,20 @@ {/if}
{/if} -
- {#if trail.location} -
{trail.location}
+
+ {#if trail.category} +

+ {$_(trail.category)} +

{/if} + {#if trail.location} +

+ {trail.location} +

+ {/if} +

+ {$_(trail.difficulty ?? "?")} +