-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
218 additions
and
177 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
This file was deleted.
Oops, something went wrong.
103 changes: 103 additions & 0 deletions
103
drama-queen/src/ui/pages/synchronize-old/SynchronizePage.tsx
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,103 @@ | ||
import LinearProgress from '@mui/material/LinearProgress'; | ||
import Typography from '@mui/material/Typography'; | ||
import Stack from '@mui/material/Stack'; | ||
import { useTranslate } from "hooks/useTranslate"; | ||
import preloader from 'ui/assets/preloader.svg'; | ||
import { tss } from "tss-react/mui"; | ||
import { Fragment, useEffect, useState } from "react"; | ||
import { type PullData, usePullData } from 'hooks/usePullData'; | ||
import type { SurveyUnitWithId } from "core/ports/QueenApi/SurveyUnit"; | ||
import { SyncError } from "hooks/queries/SyncError"; | ||
import { storeSyncProgress } from "./storeSyncProgress"; | ||
import { db } from 'core/indexedDb'; | ||
|
||
type SyncState = "Idle" | "Push" | "Pull" | "End"; | ||
|
||
|
||
export const SynchronizePage = () => { | ||
const { classes } = useStyles(); | ||
const [state, setState] = useState<SyncState>("Pull") | ||
|
||
useEffect(() => { | ||
storeSyncProgress() | ||
}, []); | ||
|
||
const handlePullEnd = (data: PullData, errors: SyncError[]) => { | ||
storeSyncProgress( | ||
data, | ||
errors | ||
) | ||
db.surveyUnit.bulkAdd(data.surveyUnits); | ||
setState("End") | ||
} | ||
|
||
return <Stack spacing={3} alignItems="center"> | ||
{state !== 'End' && <img src={preloader} alt="" className={classes.spinner} />} | ||
{state === "Pull" && <PullProgress onEnd={handlePullEnd} />} | ||
{state === "End" && <h1>Finished pulling data</h1>} | ||
</Stack>; | ||
} | ||
|
||
const IndexProgress = () => { | ||
return <>Index</> | ||
} | ||
|
||
type DownloadProgressProps = { | ||
onEnd: (data: PullData, errors: SyncError[]) => void | ||
} | ||
|
||
const PullProgress = ({ onEnd }: DownloadProgressProps) => { | ||
const { __ } = useTranslate(); | ||
const { classes } = useStyles(); | ||
const { progress, data, errors, status } = usePullData({ | ||
onEnd: onEnd | ||
}); | ||
const progressBars = [{ | ||
progress: progress.surveyUnits, | ||
label: __('sync.surveyUnits') | ||
}, | ||
{ | ||
progress: progress.nomenclatures, | ||
label: __('sync.nomenclatures') | ||
}, | ||
{ | ||
progress: progress.questionnaires, | ||
label: __('sync.questionnaires') | ||
}] | ||
.filter(bar => bar.progress !== null) | ||
|
||
return <> | ||
<Stack spacing={1} alignItems="center"> | ||
<Typography variant="h3" fontWeight="bold">{__('sync.progress')}</Typography> | ||
<Typography variant="h6" className={classes.lightText}>{__('sync.download')}</Typography> | ||
</Stack> | ||
<Stack spacing={2}> | ||
{progressBars.map(bar => | ||
<Fragment key={bar.label}> | ||
<Stack spacing={1}> | ||
<Typography variant="body2" fontWeight="bold" | ||
className={classes.lightText}>{bar.label}</Typography> | ||
<LinearProgress variant="determinate" value={bar.progress! * 100} | ||
className={classes.progressBar} /> | ||
</Stack> | ||
</Fragment>)} | ||
</Stack> | ||
</> | ||
} | ||
|
||
const useStyles = tss | ||
.create(() => ({ | ||
lightText: { | ||
opacity: .75, | ||
}, | ||
spinner: { | ||
width: 200, | ||
height: 200 | ||
}, | ||
progressBar: { | ||
maxWidth: 700, | ||
width: '80vw', | ||
height: 10, | ||
borderRadius: 10 | ||
} | ||
})); |
File renamed without changes.
File renamed without changes.
Oops, something went wrong.