-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4483 from omnivore-app/jacksonh/export-direct-dow…
…nload Export direct download links + progress updates
- Loading branch information
Showing
5 changed files
with
157 additions
and
7 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 |
---|---|---|
@@ -1,11 +1,40 @@ | ||
import { useQuery, useQueryClient } from '@tanstack/react-query' | ||
import { apiFetcher } from './networkHelpers' | ||
import { TaskState } from './mutations/exportToIntegrationMutation' | ||
|
||
type Export = { | ||
id: string | ||
state: TaskState | ||
totalItems?: number | ||
processedItems?: number | ||
createdAt: string | ||
signedUrl: string | ||
} | ||
|
||
type ExportsResponse = { | ||
exports: Export[] | ||
} | ||
|
||
export const createExport = async (): Promise<boolean> => { | ||
try { | ||
const response = await apiFetcher(`/api/export/`) | ||
console.log('RESPONSE: ', response) | ||
if ('error' in (response as any)) { | ||
return false | ||
} | ||
return true | ||
} catch (error) { | ||
console.log('error scheduling export. ') | ||
return false | ||
} | ||
} | ||
|
||
export function useGetExports() { | ||
return useQuery({ | ||
queryKey: ['exports'], | ||
queryFn: async () => { | ||
const response = (await apiFetcher(`/api/export/list`)) as ExportsResponse | ||
return response.exports | ||
}, | ||
}) | ||
} |
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 |
---|---|---|
|
@@ -2,6 +2,7 @@ import { useCallback, useEffect, useMemo, useState } from 'react' | |
import { Button } from '../../components/elements/Button' | ||
import { | ||
Box, | ||
HStack, | ||
SpanBox, | ||
VStack, | ||
} from '../../components/elements/LayoutPrimitives' | ||
|
@@ -27,7 +28,13 @@ import { useGetViewerQuery } from '../../lib/networking/queries/useGetViewerQuer | |
import { useValidateUsernameQuery } from '../../lib/networking/queries/useValidateUsernameQuery' | ||
import { applyStoredTheme } from '../../lib/themeUpdater' | ||
import { showErrorToast, showSuccessToast } from '../../lib/toastHelpers' | ||
import { createExport } from '../../lib/networking/useCreateExport' | ||
import { | ||
createExport, | ||
useGetExports, | ||
} from '../../lib/networking/useCreateExport' | ||
import { TaskState } from '../../lib/networking/mutations/exportToIntegrationMutation' | ||
import { timeAgo } from '../../lib/textFormatting' | ||
import { Download, DownloadSimple } from '@phosphor-icons/react' | ||
|
||
const ACCOUNT_LIMIT = 50_000 | ||
|
||
|
@@ -475,6 +482,8 @@ export default function Account(): JSX.Element { | |
} | ||
|
||
const ExportSection = (): JSX.Element => { | ||
const { data: recentExports } = useGetExports() | ||
console.log('recentExports: ', recentExports) | ||
const doExport = useCallback(async () => { | ||
const result = await createExport() | ||
if (result) { | ||
|
@@ -502,6 +511,12 @@ const ExportSection = (): JSX.Element => { | |
you should receive an email with a link to your data within an hour. The | ||
download link will be available for 24 hours. | ||
</StyledText> | ||
<StyledText style="footnote" css={{ mt: '10px', mb: '20px' }}> | ||
If you do not receive your completed export within 24hrs please contact{' '} | ||
<a href="mailto:[email protected]"> | ||
Contact us via email | ||
</a> | ||
</StyledText> | ||
<Button | ||
style="ctaDarkYellow" | ||
onClick={(event) => { | ||
|
@@ -512,6 +527,51 @@ const ExportSection = (): JSX.Element => { | |
> | ||
Export Data | ||
</Button> | ||
|
||
{recentExports && ( | ||
<VStack css={{ width: '100% ', mt: '20px' }}> | ||
<StyledLabel>Recent exports</StyledLabel> | ||
{recentExports.map((item) => { | ||
return ( | ||
<HStack | ||
key={item.id} | ||
css={{ width: '100%', height: '55px' }} | ||
distribution="start" | ||
alignment="center" | ||
> | ||
<SpanBox css={{ width: '180px' }} title={item.createdAt}> | ||
{timeAgo(item.createdAt)} | ||
</SpanBox> | ||
<SpanBox css={{ width: '180px' }}>{item.state}</SpanBox> | ||
{item.totalItems && ( | ||
<VStack css={{ width: '180px', height: '50px', pt: '12px' }}> | ||
<ProgressBar | ||
fillPercentage={ | ||
((item.processedItems ?? 0) / item.totalItems) * 100 | ||
} | ||
fillColor={theme.colors.omnivoreCtaYellow.toString()} | ||
backgroundColor={theme.colors.grayText.toString()} | ||
borderRadius={'2px'} | ||
/> | ||
<StyledText style="footnote" css={{ mt: '0px' }}> | ||
{`${item.processedItems ?? 0} of ${ | ||
item.totalItems | ||
} items.`} | ||
</StyledText> | ||
</VStack> | ||
)} | ||
{item.signedUrl && ( | ||
<SpanBox css={{ marginLeft: 'auto' }}> | ||
<a href={item.signedUrl} target="_blank" rel="noreferrer"> | ||
Download | ||
</a> | ||
</SpanBox> | ||
)} | ||
</HStack> | ||
) | ||
})} | ||
</VStack> | ||
)} | ||
</VStack> | ||
) | ||
} | ||
|