From 61cb205f935d28d85c9f34bcbae209e399fcfbda Mon Sep 17 00:00:00 2001 From: Fredrik Burmester Date: Fri, 30 Aug 2024 12:54:31 +0200 Subject: [PATCH] fix: refactor to use enums --- utils/atoms/filters.ts | 88 +++++++++++++++++++++++++----------------- 1 file changed, 52 insertions(+), 36 deletions(-) diff --git a/utils/atoms/filters.ts b/utils/atoms/filters.ts index a1228be6..f49b17d4 100644 --- a/utils/atoms/filters.ts +++ b/utils/atoms/filters.ts @@ -1,51 +1,67 @@ -import { - ItemFilter, - ItemSortBy, - NameGuidPair, - SortOrder, -} from "@jellyfin/sdk/lib/generated-client/models"; -import { atom, useAtom } from "jotai"; +import { atom } from "jotai"; + +export enum SortByOption { + Default = "Default", + SortName = "SortName", + CommunityRating = "CommunityRating", + CriticRating = "CriticRating", + DateCreated = "DateCreated", + DatePlayed = "DatePlayed", + PlayCount = "PlayCount", + ProductionYear = "ProductionYear", + Runtime = "Runtime", + OfficialRating = "OfficialRating", + PremiereDate = "PremiereDate", + StartDate = "StartDate", + IsUnplayed = "IsUnplayed", + IsPlayed = "IsPlayed", + AirTime = "AirTime", + Studio = "Studio", + IsFavoriteOrLiked = "IsFavoriteOrLiked", + Random = "Random", +} + +export enum SortOrderOption { + Ascending = "Ascending", + Descending = "Descending", +} export const sortOptions: { - key: ItemSortBy; + key: SortByOption; value: string; }[] = [ - { key: "Default", value: "Default" }, - { key: "SortName", value: "Name" }, - { key: "CommunityRating", value: "Community Rating" }, - { key: "CriticRating", value: "Critics Rating" }, - { key: "DateCreated", value: "Date Added" }, - // Only works for shows (last episode added) keeping for future ref. - // { key: "DateLastContentAdded", value: "Content Added" }, - { key: "DatePlayed", value: "Date Played" }, - { key: "PlayCount", value: "Play Count" }, - { key: "ProductionYear", value: "Production Year" }, - { key: "Runtime", value: "Runtime" }, - { key: "OfficialRating", value: "Official Rating" }, - { key: "PremiereDate", value: "Premiere Date" }, - { key: "StartDate", value: "Start Date" }, - { key: "IsUnplayed", value: "Is Unplayed" }, - { key: "IsPlayed", value: "Is Played" }, - // Broken in JF - // { key: "VideoBitRate", value: "Video Bit Rate" }, - { key: "AirTime", value: "Air Time" }, - { key: "Studio", value: "Studio" }, - { key: "IsFavoriteOrLiked", value: "Is Favorite Or Liked" }, - { key: "Random", value: "Random" }, + { key: SortByOption.Default, value: "Default" }, + { key: SortByOption.SortName, value: "Name" }, + { key: SortByOption.CommunityRating, value: "Community Rating" }, + { key: SortByOption.CriticRating, value: "Critics Rating" }, + { key: SortByOption.DateCreated, value: "Date Added" }, + { key: SortByOption.DatePlayed, value: "Date Played" }, + { key: SortByOption.PlayCount, value: "Play Count" }, + { key: SortByOption.ProductionYear, value: "Production Year" }, + { key: SortByOption.Runtime, value: "Runtime" }, + { key: SortByOption.OfficialRating, value: "Official Rating" }, + { key: SortByOption.PremiereDate, value: "Premiere Date" }, + { key: SortByOption.StartDate, value: "Start Date" }, + { key: SortByOption.IsUnplayed, value: "Is Unplayed" }, + { key: SortByOption.IsPlayed, value: "Is Played" }, + { key: SortByOption.AirTime, value: "Air Time" }, + { key: SortByOption.Studio, value: "Studio" }, + { key: SortByOption.IsFavoriteOrLiked, value: "Is Favorite Or Liked" }, + { key: SortByOption.Random, value: "Random" }, ]; export const sortOrderOptions: { - key: SortOrder; + key: SortOrderOption; value: string; }[] = [ - { key: "Ascending", value: "Ascending" }, - { key: "Descending", value: "Descending" }, + { key: SortOrderOption.Ascending, value: "Ascending" }, + { key: SortOrderOption.Descending, value: "Descending" }, ]; export const genreFilterAtom = atom([]); export const tagsFilterAtom = atom([]); export const yearFilterAtom = atom([]); -export const sortByAtom = atom<[typeof sortOptions][number]>([sortOptions[0]]); -export const sortOrderAtom = atom<[typeof sortOrderOptions][number]>([ - sortOrderOptions[0], +export const sortByAtom = atom([SortByOption.Default]); +export const sortOrderAtom = atom([ + SortOrderOption.Ascending, ]);