diff --git a/db/migrations/1733513436_update_sortable_attributes_duration.go b/db/migrations/1733513436_update_sortable_attributes_duration.go new file mode 100644 index 00000000..dbabc773 --- /dev/null +++ b/db/migrations/1733513436_update_sortable_attributes_duration.go @@ -0,0 +1,36 @@ +package migrations + +import ( + "os" + + "github.com/meilisearch/meilisearch-go" + "github.com/pocketbase/dbx" + + m "github.com/pocketbase/pocketbase/migrations" +) + +func init() { + client := meilisearch.New(os.Getenv("MEILI_URL"), meilisearch.WithAPIKey(os.Getenv("MEILI_MASTER_KEY"))) + + m.Register(func(db dbx.Builder) error { + _, err := client.Index("trails").UpdateSortableAttributes(&[]string{ + "created", "date", "difficulty", "distance", "elevation_gain", "elevation_loss", "name", "duration", "author", + }) + + if err != nil { + return err + } + + return nil + }, func(db dbx.Builder) error { + _, err := client.Index("trails").UpdateSortableAttributes(&[]string{ + "created", "date", "difficulty", "distance", "elevation_gain", "elevation_loss", "name", + }) + + if err != nil { + return err + } + + return nil + }) +} diff --git a/web/src/lib/components/trail/trail_list.svelte b/web/src/lib/components/trail/trail_list.svelte index e01e2866..fb6afe43 100644 --- a/web/src/lib/components/trail/trail_list.svelte +++ b/web/src/lib/components/trail/trail_list.svelte @@ -7,6 +7,7 @@ import EmptyStateSearch from "../empty_states/empty_state_search.svelte"; import TrailCard from "./trail_card.svelte"; import TrailListItem from "./trail_list_item.svelte"; + import TrailTable from "./trail_table.svelte"; import SkeletonCard from "../base/skeleton_card.svelte"; import SkeletonListItem from "../base/skeleton_list_item.svelte"; @@ -22,6 +23,7 @@ const displayOptions: SelectItem[] = [ { text: $_("card", { values: { n: 2 } }), value: "cards" }, { text: $_("list", { values: { n: 1 } }), value: "list" }, + { text: $_("table"), value: "table" }, ]; let selectedDisplayOption = displayOptions[0].value; @@ -29,13 +31,14 @@ let dispatch = createEventDispatcher(); const sortOptions: SelectItem[] = [ - { text: $_("alphabetical"), value: "name" }, - { text: $_("creation-date"), value: "created" }, - { text: $_("date"), value: "date" }, - { text: $_("difficulty"), value: "difficulty" }, + { text: $_("name"), value: "name" }, { text: $_("distance"), value: "distance" }, + { text: $_("duration"), value: "duration" }, + { text: $_("difficulty"), value: "difficulty" }, { text: $_("elevation-gain"), value: "elevation_gain" }, { text: $_("elevation-loss"), value: "elevation_loss" }, + { text: $_("creation-date"), value: "created" }, + { text: $_("date"), value: "date" }, ]; onMount(() => { @@ -81,6 +84,19 @@ localStorage.setItem("sort_order", filter.sortOrder); dispatch("update", filter); } + + function handleSortUpdate(sort: any) { + if (!filter) { + return; + } + if (sort.detail === filter.sort) { + setSortOrder(); + } else { + filter.sort = sort.detail; + filter.sortOrder = "+"; + setSort(); + } + }
{$_("sort")}
-{$_("sort")}
+| dispatch("sort", column.value)}
+ >
+
+ {column.text}
+ {#if filter && filter.sort === column.value}
+
+ {/if}
+
+ |
+ {/each}
+ ||||||
|---|---|---|---|---|---|---|
|
+
+ {trail.name}
+
+
+ {#if trail.expand && trail.expand.author}
+
+ {/if}
+
+
+ {#if trail.public}
+
+ {/if}
+ {#if trail.expand?.trail_share_via_trail?.length}
+
+ |
+ + {formatDistance(trail.distance)} + | ++ {formatTimeHHMM(trail.duration)} + | ++ {trail.difficulty} + | ++ {formatElevation(trail.elevation_gain)} + | ++ {#if trail.created} + {new Date(trail.created).toLocaleDateString( + undefined, + { + month: "2-digit", + day: "2-digit", + year: "numeric", + timeZone: "UTC", + }, + )} + {/if} + | ++ {#if trail.date} + {new Date(trail.date).toLocaleDateString( + undefined, + { + month: "2-digit", + day: "2-digit", + year: "numeric", + timeZone: "UTC", + }, + )} + {/if} + | +
| + {/each} + |