Clean up kind handling in the front

This commit is contained in:
Zoe Roux
2023-12-18 15:03:04 +01:00
parent 7b035411c0
commit 2e0a0e5eb0
25 changed files with 78 additions and 117 deletions
@@ -22,7 +22,7 @@ import { z } from "zod";
import { withImages, ResourceP } from "../traits";
export const CollectionP = withImages(
ResourceP.extend({
ResourceP("collection").extend({
/**
* The title of this collection.
*/
@@ -31,8 +31,7 @@ export const CollectionP = withImages(
* The summary of this show.
*/
overview: z.string().nullable(),
}),
"collections",
})
).transform((x) => ({
...x,
href: `/collection/${x.slug}`,
@@ -24,7 +24,7 @@ import { withImages, imageFn } from "../traits";
import { ResourceP } from "../traits/resource";
export const BaseEpisodeP = withImages(
ResourceP.extend({
ResourceP("episode").extend({
/**
* The season in witch this episode is in.
*/
@@ -72,7 +72,6 @@ export const BaseEpisodeP = withImages(
*/
showId: z.string(),
}),
"episodes",
)
.transform((x) => ({
...x,
@@ -23,28 +23,19 @@ import { CollectionP } from "./collection";
import { MovieP } from "./movie";
import { ShowP } from "./show";
/**
* The type of item, ether a show, a movie or a collection.
*/
export enum ItemKind {
Show = "Show",
Movie = "Movie",
Collection = "Collection",
}
export const LibraryItemP = z.union([
/*
* Either a Show
*/
ShowP.and(z.object({ kind: z.literal(ItemKind.Show) })),
ShowP,
/*
* Or a Movie
*/
MovieP.and(z.object({ kind: z.literal(ItemKind.Movie) })),
MovieP,
/*
* Or a Collection
*/
CollectionP.and(z.object({ kind: z.literal(ItemKind.Collection) })),
CollectionP,
]);
/**
+1 -2
View File
@@ -29,7 +29,7 @@ import { MetadataP } from "./metadata";
import { WatchStatusP } from "./watch-status";
export const MovieP = withImages(
ResourceP.extend({
ResourceP("movie").extend({
/**
* The title of this movie.
*/
@@ -105,7 +105,6 @@ export const MovieP = withImages(
*/
watchStatus: WatchStatusP.optional().nullable(),
}),
"movies",
)
.transform((x) => ({
...x,
+2 -10
View File
@@ -22,23 +22,15 @@ import { z } from "zod";
import { MovieP } from "./movie";
import { EpisodeP } from "./episode";
/**
* The type of item, ether a a movie or an episode.
*/
export enum NewsKind {
Episode = "Episode",
Movie = "Movie",
}
export const NewsP = z.union([
/*
* Either an episode
*/
EpisodeP.and(z.object({ kind: z.literal(NewsKind.Episode) })),
EpisodeP,
/*
* Or a Movie
*/
MovieP.and(z.object({ kind: z.literal(NewsKind.Movie) })),
MovieP,
]);
/**
@@ -23,7 +23,7 @@ import { withImages } from "../traits";
import { ResourceP } from "../traits/resource";
export const PersonP = withImages(
ResourceP.extend({
ResourceP("people").extend({
/**
* The name of this person.
*/
@@ -40,7 +40,6 @@ export const PersonP = withImages(
*/
role: z.string().optional(),
}),
"people",
);
/**
@@ -24,7 +24,7 @@ import { withImages } from "../traits";
import { ResourceP } from "../traits/resource";
export const SeasonP = withImages(
ResourceP.extend({
ResourceP("season").extend({
/**
* The name of this season.
*/
@@ -50,7 +50,6 @@ export const SeasonP = withImages(
*/
episodesCount: z.number(),
}),
"seasons",
);
/**
+1 -4
View File
@@ -22,10 +22,8 @@ import { z } from "zod";
import { zdate } from "../utils";
import { withImages, ResourceP } from "../traits";
import { Genre } from "./genre";
import { SeasonP } from "./season";
import { StudioP } from "./studio";
import { BaseEpisodeP } from "./episode.base";
import { CollectionP } from "./collection";
import { MetadataP } from "./metadata";
import { ShowWatchStatusP } from "./watch-status";
@@ -40,7 +38,7 @@ export enum Status {
}
export const ShowP = withImages(
ResourceP.extend({
ResourceP("show").extend({
/**
* The title of this show.
*/
@@ -106,7 +104,6 @@ export const ShowP = withImages(
*/
episodesCount: z.number().int().gte(0).optional(),
}),
"shows",
)
.transform((x) => {
if (!x.thumbnail && x.poster) {
@@ -21,7 +21,7 @@
import { z } from "zod";
import { ResourceP } from "../traits/resource";
export const StudioP = ResourceP.extend({
export const StudioP = ResourceP("studio").extend({
/**
* The name of this studio.
*/
+1 -4
View File
@@ -21,10 +21,7 @@
import { z } from "zod";
import { ResourceP } from "../traits/resource";
/**
* The library that will contain Shows, Collections...
*/
export const UserP = ResourceP.extend({
export const UserP = ResourceP("user").extend({
/**
* The name of this user.
*/
@@ -22,23 +22,15 @@ import { z } from "zod";
import { MovieP } from "./movie";
import { ShowP } from "./show";
/**
* The type of item, ether a show, a movie or an episode.
*/
export enum WatchlistKind {
Show = "Show",
Movie = "Movie",
}
export const WatchlistP = z.union([
/*
* Either a show
*/
ShowP.and(z.object({ kind: z.literal(WatchlistKind.Show) })),
ShowP,
/*
* Or a Movie
*/
MovieP.and(z.object({ kind: z.literal(WatchlistKind.Movie) })),
MovieP,
]);
/**