From fb9dc133cf9071b04f6f3f7c434991e5f28be620 Mon Sep 17 00:00:00 2001 From: Alperen Elhan Date: Thu, 13 Oct 2022 23:45:14 +0300 Subject: [PATCH] feat: add interval option to manga selection --- src/components/newMangaCard.tsx | 76 ++++++++++++++++++++++++++++++--- src/server/trpc/router/manga.ts | 5 ++- 2 files changed, 73 insertions(+), 8 deletions(-) diff --git a/src/components/newMangaCard.tsx b/src/components/newMangaCard.tsx index 4c7178b..e341832 100644 --- a/src/components/newMangaCard.tsx +++ b/src/components/newMangaCard.tsx @@ -12,6 +12,7 @@ import { LoadingOverlay, Paper, Select, + Stack, Stepper, Text, TextInput, @@ -22,7 +23,7 @@ import { useForm, UseFormReturnType, zodResolver } from '@mantine/form'; import { getHotkeyHandler } from '@mantine/hooks'; import { useModals } from '@mantine/modals'; import { showNotification } from '@mantine/notifications'; -import { IconArrowRight, IconCheck, IconPlus, IconSearch, IconX } from '@tabler/icons'; +import { IconArrowRight, IconCheck, IconFolderPlus, IconPlus, IconSearch, IconX } from '@tabler/icons'; import { useState } from 'react'; import { z } from 'zod'; import { trpc } from '../utils/trpc'; @@ -72,11 +73,14 @@ const useStyles = createStyles((theme) => ({ }, })); +const availableIntervals = ['daily', 'hourly', 'weekly', 'minutely']; + const schema = z.object({ source: z.string().min(1, { message: 'You must select a source' }), query: z.string().min(1, { message: 'Cannot be empty' }), mangaOrder: z.number().gte(0, { message: 'Please select a manga' }), mangaTitle: z.string().min(1, { message: 'Please select a manga' }), + interval: z.string().min(1, { message: 'Please select an interval' }), }); type FormType = z.TypeOf; @@ -107,6 +111,47 @@ function SourceStep({ form }: { form: UseFormReturnType }) { ); } +function DownloadStep({ form }: { form: UseFormReturnType }) { + const libraryQuery = trpc.library.query.useQuery(); + + const libraryPath = libraryQuery.data?.path; + + const intervalSelectData = availableIntervals.map((k) => ({ label: k, value: k })); + + if (libraryQuery.isLoading) { + return ; + } + + const sanitizeMangaName = form.values.mangaTitle + .replaceAll(/[\\/<>:;"'|?!*{}#%&^+,~\s]/g, '_') + .replaceAll(/__+/g, '_') + .replaceAll(/^[_\-.]+|[_\-.]+$/g, '_'); + + const downloadPath = `${libraryPath}/${sanitizeMangaName}`; + + return ( + + +