-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rename subscription bulk to recovery
- Loading branch information
Showing
14 changed files
with
259 additions
and
201 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { subscriptionSchema } from '@/subscriptions/models/subscription.model.ts'; | ||
import { z } from 'zod'; | ||
|
||
// TODO add support for exporting with tags as well | ||
export const recoverySchema = z.object({ | ||
dbVersion: z.number(), | ||
subscriptions: z.array( | ||
subscriptionSchema.omit({ | ||
id: true, | ||
tags: true, | ||
}), | ||
), | ||
}); | ||
export type RecoveryModel = z.infer<typeof recoverySchema>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { dbVersion } from '@/db/globals/db.ts'; | ||
import { SubscriptionsSelectTable } from '@/subscriptions/components/subscriptions-select-table.tsx'; | ||
import { findSubscriptions } from '@/subscriptions/models/subscription.table.ts'; | ||
import { cn } from '@/ui/utils/cn.ts'; | ||
import { Button, Switch } from '@mantine/core'; | ||
import { useLiveQuery } from 'dexie-react-hooks'; | ||
import { memo, useCallback, useState } from 'react'; | ||
import { recoverySchema } from '../models/recovery.model.ts'; | ||
|
||
export const RecoveryExportPage = memo(() => { | ||
const subscriptions = useLiveQuery(() => findSubscriptions(), [], []); | ||
const [selectedIds, setSelectedIds] = useState<number[]>([]); | ||
|
||
const [isPrettify, setIsPrettify] = useState(true); | ||
const toggleIsPrettify = useCallback(() => { | ||
setIsPrettify(!isPrettify); | ||
}, [isPrettify]); | ||
|
||
const exportSubscriptions = useCallback(() => { | ||
const subscriptionsToExport = subscriptions.filter((subscription) => | ||
selectedIds.includes(subscription.id), | ||
); | ||
const subscriptionsExport = recoverySchema.parse({ | ||
dbVersion, | ||
subscriptions: subscriptionsToExport, | ||
}); | ||
const jsonToExport = isPrettify | ||
? JSON.stringify(subscriptionsExport, null, 2) | ||
: JSON.stringify(subscriptionsExport); | ||
const blobToExport = new Blob([jsonToExport], { type: 'application/json' }); | ||
|
||
const exportLink = document.createElement('a'); | ||
exportLink.href = URL.createObjectURL(blobToExport); | ||
exportLink.download = 'subscriptions.json'; | ||
document.body.appendChild(exportLink); | ||
exportLink.click(); | ||
document.body.removeChild(exportLink); | ||
}, [isPrettify, selectedIds, subscriptions]); | ||
|
||
return ( | ||
<div className={cn(`flex flex-col gap-4`)}> | ||
<SubscriptionsSelectTable | ||
subscriptions={subscriptions} | ||
selectedIds={selectedIds} | ||
setSelectedIds={setSelectedIds} | ||
/> | ||
|
||
<div className={cn(`flex items-center`)}> | ||
<Switch | ||
checked={isPrettify} | ||
onChange={toggleIsPrettify} | ||
label="Prettify" | ||
/> | ||
|
||
<div className={cn('flex-1')} /> | ||
|
||
<Button | ||
disabled={selectedIds.length === 0} | ||
onClick={exportSubscriptions}> | ||
export | ||
</Button> | ||
</div> | ||
</div> | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { cn } from '@/ui/utils/cn.ts'; | ||
import { memo } from 'react'; | ||
|
||
export const RecoveryImportPage = memo(() => { | ||
return <div className={cn(`flex flex-col gap-4`)}>Work is in progress</div>; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { route } from '@/router/types/route.ts'; | ||
import { | ||
DefaultLayout, | ||
DefaultLayoutHeader, | ||
} from '@/ui/layouts/default.layout.tsx'; | ||
import { faDownload, faUpload } from '@fortawesome/free-solid-svg-icons'; | ||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; | ||
import { Card, Tabs } from '@mantine/core'; | ||
import { memo, useCallback, useMemo } from 'react'; | ||
import { Outlet, useLocation, useNavigate } from 'react-router-dom'; | ||
import { recoveryRoute } from '../types/recovery-route.ts'; | ||
|
||
export const RecoveryPage = memo(() => { | ||
const { pathname } = useLocation(); | ||
const activeTab = useMemo(() => { | ||
return pathname.split('/').at(-1); | ||
}, [pathname]); | ||
|
||
const navigate = useNavigate(); | ||
const navigateToTab = useCallback( | ||
(tab: string | null) => navigate(`/${route.recovery}/${tab}`), | ||
[navigate], | ||
); | ||
|
||
return ( | ||
<DefaultLayout header={<DefaultLayoutHeader />}> | ||
<Card | ||
shadow="xs" | ||
padding="xs" | ||
radius="md" | ||
withBorder> | ||
<Tabs | ||
value={activeTab} | ||
onChange={navigateToTab}> | ||
<Tabs.List> | ||
<Tabs.Tab | ||
value={recoveryRoute.import} | ||
leftSection={<FontAwesomeIcon icon={faUpload} />}> | ||
Import | ||
</Tabs.Tab> | ||
<Tabs.Tab | ||
value={recoveryRoute.export} | ||
leftSection={<FontAwesomeIcon icon={faDownload} />}> | ||
Export | ||
</Tabs.Tab> | ||
</Tabs.List> | ||
</Tabs> | ||
|
||
<Outlet /> | ||
</Card> | ||
</DefaultLayout> | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export const recoveryRoute = { | ||
import: 'import', | ||
export: 'export', | ||
} as const; | ||
|
||
export type RecoveryRoute = (typeof recoveryRoute)[keyof typeof recoveryRoute]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,7 @@ | ||
export const route = { | ||
root: '/', | ||
dashboard: '/dashboard', | ||
subscriptions: '/subscriptions', | ||
subscriptionsBulk: '/subscriptions-bulk', | ||
dashboard: 'dashboard', | ||
subscriptions: 'subscriptions', | ||
recovery: 'recovery', | ||
} as const; | ||
|
||
export type Route = (typeof route)[keyof typeof route]; |
Oops, something went wrong.