Skip to content

Commit

Permalink
chore: change download file name
Browse files Browse the repository at this point in the history
  • Loading branch information
apotdevin committed Aug 3, 2021
1 parent d74e932 commit 042dd12
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/views/tools/backups/DownloadBackups.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React, { useEffect } from 'react';
import { toast } from 'react-toastify';
import { useGetBackupsLazyQuery } from 'src/graphql/queries/__generated__/getBackups.generated';
import { useAccount } from 'src/hooks/UseAccount';
import { format } from 'date-fns';
import { useNodeInfo } from 'src/hooks/UseNodeInfo';
import { DarkSubTitle, SingleLine } from '../../../components/generic/Styled';
import { saveToPc } from '../../../utils/helpers';
import { getErrorContent } from '../../../utils/error';
Expand All @@ -12,15 +13,16 @@ export const DownloadBackups = () => {
onError: error => toast.error(getErrorContent(error)),
});

const account = useAccount();
const { publicKey } = useNodeInfo();

useEffect(() => {
if (account && !loading && data && data.getBackups) {
saveToPc(data.getBackups, `ChannelBackup-${account.name}-${account.id}`);
localStorage.setItem(`lastBackup-${account.id}`, new Date().toString());
toast.success('Downloaded');
}
}, [data, loading, account]);
if (loading || !data?.getBackups) return;

const date = format(new Date(), 'ddMMyyyyhhmmss');
saveToPc(data.getBackups, `ChannelBackup-${publicKey}-${date}`);
localStorage.setItem(`lastBackup-${publicKey}`, new Date().toString());
toast.success('Downloaded');
}, [data, loading, publicKey]);

return (
<SingleLine>
Expand Down

0 comments on commit 042dd12

Please sign in to comment.