Skip to content

Commit

Permalink
feat(export): show last export date
Browse files Browse the repository at this point in the history
  • Loading branch information
stephane-r committed Dec 1, 2023
1 parent a89a960 commit 11bfd39
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 5 deletions.
23 changes: 22 additions & 1 deletion src/components/ExportData.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { Box } from "@mantine/core";
import { Box, Text } from "@mantine/core";
import { notifications } from "@mantine/notifications";
import { format } from "date-fns";
import { memo, useCallback, useMemo, useState } from "react";
import { useTranslation } from "react-i18next";

import { getAllPlaylists } from "../database/utils";
import { useSettings } from "../providers/Settings";
import { generateAndDownloadFile } from "../utils/generateAndDownloadFile";
import { ModalExportFilename } from "./ModalExportFilename";
import { TransferList } from "./TransferList";
Expand Down Expand Up @@ -38,6 +40,7 @@ export const ExportData = memo(() => {

return (
<Box mt="lg">
<BlockLastExport />
<TransferList
data={userData}
handleSubmit={handleSubmit}
Expand All @@ -51,3 +54,21 @@ export const ExportData = memo(() => {
</Box>
);
});

const BlockLastExport = memo(() => {
const settings = useSettings();
const { t } = useTranslation();

if (settings.exportLastDate === "") {
return null;
}

return (
<Text mb="md">
{t("settings.data.export.last.date")} :{" "}
<strong>
{format(new Date(settings.exportLastDate as string), "dd-MM-yyyy")}
</strong>
</Text>
);
});
9 changes: 6 additions & 3 deletions src/components/ModalExportFilename.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { useTranslation } from "react-i18next";

import { db } from "../database";
import { useSetSettings, useSettings } from "../providers/Settings";
import type { Settings } from "../types/interfaces/Settings";
import { Modal } from "./Modal";

const getDefaultExportFileName = () =>
Expand All @@ -28,13 +27,17 @@ export const ModalExportFilename: FC<ModalExportFilenameProps> = memo(

const handleSubmit = () => {
if (fileName !== getDefaultExportFileName()) {
db.update("settings", { ID: 1 }, (data: Settings) => ({
const settingsUpdated = {
exportFileName: fileName,
exportLastDate: new Date().toISOString(),
};
db.update("settings", { ID: 1 }, () => ({
...settingsUpdated,
}));
db.commit();
setSettings((previousState) => ({
...previousState,
filename: fileName,
...settingsUpdated,
}));
}

Expand Down
7 changes: 6 additions & 1 deletion src/database/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,17 @@ const initDb = () => {
db.commit();
}

if (!db.columnExists("settings", "exportLastDate")) {
db.alterTable("settings", "exportLastDate", "");
db.commit();
}

if (!db.columnExists("settings", "analytics")) {
db.alterTable("settings", "analytics", true);
db.commit();

db.update("settings", { ID: 1 }, (data: Settings) => ({
analytics: true
analytics: true,
}));
db.commit();
}
Expand Down
1 change: 1 addition & 0 deletions src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"settings.data.export.button.submit": "Export my data",
"settings.data.export.notification.title": "Export data",
"settings.data.export.notification.message": "Your data has been exported",
"settings.data.export.last.date": "Last export date",
"settings.data.save": "Save",
"settings.data.save.text": "Save your data and sync from other device",
"settings.data.save.notification.title": "Data saved",
Expand Down
1 change: 1 addition & 0 deletions src/translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"settings.data.export.button.submit": "Exporter mes données",
"settings.data.export.notification.title": "Export de données",
"settings.data.export.notification.message": "Les données ont été exportées",
"settings.data.export.last.date": "Date du dernier export",
"settings.data.save": "Sauvegarder",
"settings.data.save.text": "Sauvegarder vos données afin de les synchroniser sur un autre appareil.",
"settings.data.save.notification.title": "Données sauvegardées",
Expand Down
1 change: 1 addition & 0 deletions src/types/interfaces/Settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ export interface Settings {
sponsorBlockCategories: string[];
analytics: boolean;
exportFileName: string | null;
exportLastDate: string | null;
}

0 comments on commit 11bfd39

Please sign in to comment.