Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement episode type filtering #1098

Merged
merged 1 commit into from
Sep 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/routes/shows/+page.server.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { cache } from '$lib/cache/cache';
import { PER_PAGE, SHOW_QUERY } from '$server/ai/queries';
import { $Enums } from '@prisma/client';
import type { PageServerLoad } from './$types';

const epoch_day = new Date().getTime() / 86400;
Expand All @@ -12,14 +13,20 @@ export const load: PageServerLoad = async function ({ locals, url, setHeaders })
const order_val = url.searchParams.get('order');
const take = parseInt(url.searchParams.get('perPage') || PER_PAGE.toString());
const order = order_val === 'desc' || !order_val ? 'desc' : 'asc'; // Ensure order can only be 'asc' or 'desc'
const filter = url.searchParams.get('type');
const show_type = url.searchParams.get('type')?.toUpperCase();
const page = parseInt(url.searchParams.get('page') || '1');
// const limit = url.searchParams.get('limit') || 100;

function isShowType(type: string | null | undefined): type is $Enums.ShowType {
if(!type) return false;
return $Enums.ShowType.hasOwnProperty(type);
}

const query = SHOW_QUERY({
take,
order,
skip: page ? (page * take) - take : 0
skip: page ? (page * take) - take : 0,
show_type: isShowType(show_type) ? show_type : undefined
});
return {
shows: locals.prisma.show.findMany(query),
Expand Down
1 change: 1 addition & 0 deletions src/routes/shows/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@

<div class="shows">
{#each shows as show (show.id)}
<!-- <pre>{JSON.stringify(show, null, ' ')}</pre> -->
<ShowCard {show} display="list" heading="h2" />
{/each}
</div>
Expand Down
11 changes: 8 additions & 3 deletions src/server/ai/queries.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Prisma } from '@prisma/client';
import { Prisma, $Enums } from '@prisma/client';

export const transcript_with_utterances = Prisma.validator<Prisma.TranscriptDefaultArgs>()({
include: {
Expand Down Expand Up @@ -135,18 +135,23 @@ export const example_response = {
guests: ['Guest 2']
};



type QueryInputs = {
take?: number;
order?: 'asc' | 'desc';
skip?: number;
show_type?: $Enums.ShowType
};


export const PER_PAGE = 10;
export const SHOW_QUERY = ({ take, order, skip }: QueryInputs = { take: PER_PAGE, order: 'desc', skip: 0}) => Prisma.validator<Prisma.ShowFindManyArgs>()({
export const SHOW_QUERY = ({ take, order, skip, show_type }: QueryInputs = { take: PER_PAGE, order: 'desc', skip: 0}) => Prisma.validator<Prisma.ShowFindManyArgs>()({
take,
orderBy: { number: order },
skip,
where: {
...(show_type && { show_type: show_type }),
},
include: {
guests: {
select: {
Expand Down
4 changes: 2 additions & 2 deletions src/styles/buttons.css
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
:is(button, .button).subtle {
--button-bg: var(--black-1);
--button-color: var(--yellow-8);
box-shadow: inset 0 0 0 2px oklch(var(--blacklch) / 0.2);
box-shadow: inset 0 0 0 var(--button-border-size) oklch(var(--blacklch) / 0.2);
}

:is(button, .button).big {
Expand Down Expand Up @@ -94,6 +94,6 @@
border-radius: 50%;
border-width: 1px;
padding: 10px;
box-shadow: inset 0 0 0 2px oklch(var(--blacklch) / 0.2);
box-shadow: inset 0 0 0 var(--button-border-size) oklch(var(--blacklch) / 0.2);
}
}
Loading