Skip to content

Commit

Permalink
Merge pull request #62 from noahstreller/feature/archiving-data
Browse files Browse the repository at this point in the history
feature: data archiving
  • Loading branch information
noahstreller authored Jul 18, 2024
2 parents e3dd7c1 + 883a258 commit 9af2c76
Show file tree
Hide file tree
Showing 16 changed files with 1,714 additions and 14 deletions.
43 changes: 35 additions & 8 deletions components/new-semester-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ import {
import { Label } from "@/components/ui/label";
import { Switch } from "@/components/ui/switch";
import { MediaQueries, useMediaQuery } from "@/lib/hooks/useMediaQuery";
import { prepareDataForExport } from "@/lib/services/export-service";
import {
archiveCategory,
prepareDataForExport,
} from "@/lib/services/export-service";
import { exportToJSONFile } from "@/lib/services/notAsyncLogic";
import {
clearUserGrades,
Expand All @@ -35,14 +38,15 @@ import { CalendarPlus } from "lucide-react";
import { useState } from "react";

export const NewSemesterButton = ({
expanded = false,
expanded = true,
}: {
expanded?: boolean;
}) => {
const [isOpen, setIsOpen] = useState<boolean>(false);
const [keepSubjects, setKeepSubjectsState] = useState<boolean>(true);
const [keepGrades, setKeepGradesState] = useState<boolean>(false);
const [exportData, setExportData] = useState<boolean>(true);
const [archiveData, setArchiveData] = useState<boolean>(true);
const categoryState = useCategory();

const isDesktop = useMediaQuery(MediaQueries.xxl);
Expand All @@ -66,6 +70,9 @@ export const NewSemesterButton = ({
categoryState.category?.id
);
if (exportData) exportToJSONFile(data, categoryState.category?.name);
if (archiveData) {
await archiveCategory(data);
}
if (!keepSubjects) await clearUserSubjectsGrades();
if (!keepGrades && keepSubjects) await clearUserGrades();
} finally {
Expand All @@ -82,7 +89,7 @@ export const NewSemesterButton = ({
variant={"secondary"}
>
<CalendarPlus className="size-4" />
{expanded && <span>New Term</span>}
<span>New Term</span>
</Button>
</DrawerTrigger>
<DrawerContent>
Expand Down Expand Up @@ -113,16 +120,26 @@ export const NewSemesterButton = ({
<Highlight colorName="blue">file</Highlight>
</Label>
</div>
<div className="flex flex-row items-center gap-4">
<Switch checked={archiveData} onCheckedChange={setArchiveData} />
<Label>
<Highlight colorName="blue">Archive</Highlight> your current data
</Label>
</div>
</div>

<DrawerFooter>
{!(exportData || keepGrades) && (
{!(exportData || archiveData || keepGrades) && (
<span className="text-muted-foreground self-center">
This action is irreversible
</span>
)}
<Button
variant={exportData || keepGrades ? "default" : "destructive"}
variant={
exportData || archiveData || keepGrades
? "default"
: "destructive"
}
onClick={handleSubmit}
>
Do it!
Expand All @@ -137,7 +154,7 @@ export const NewSemesterButton = ({
<Dialog open={isOpen} onOpenChange={setIsOpen}>
<DialogTrigger asChild>
<Button className="w-full" variant={"secondary"}>
<CalendarPlus className="size-5 mr-2" />
<CalendarPlus className="size-4 mr-2" />
New Term
</Button>
</DialogTrigger>
Expand Down Expand Up @@ -169,9 +186,15 @@ export const NewSemesterButton = ({
<Highlight colorName="blue">file</Highlight>
</Label>
</div>
<div className="flex flex-row items-center gap-4">
<Switch checked={archiveData} onCheckedChange={setArchiveData} />
<Label>
<Highlight colorName="blue">Archive</Highlight> your current data
</Label>
</div>
</div>
<DialogFooter>
{!(exportData || keepGrades) && (
{!(exportData || archiveData || keepGrades) && (
<span className="text-muted-foreground self-center">
This action is irreversible
</span>
Expand All @@ -180,7 +203,11 @@ export const NewSemesterButton = ({
<Button variant="secondary">Cancel</Button>
</DialogClose>
<Button
variant={exportData || keepGrades ? "default" : "destructive"}
variant={
exportData || archiveData || keepGrades
? "default"
: "destructive"
}
onClick={handleSubmit}
>
Do it!
Expand Down
5 changes: 4 additions & 1 deletion components/settings-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
FormMessage,
} from "@/components/ui/form";
import { LoadingSpinner } from "@/components/ui/spinner";
import { ViewArchiveButton } from "@/components/view-archive-button";
import { NewPreferences } from "@/db/schema";
import { useDevice } from "@/lib/hooks/useMediaQuery";
import { savePreferences } from "@/lib/services/preferences-service";
Expand Down Expand Up @@ -676,13 +677,15 @@ export function SettingsModal({
</Button>
</ClearDataButton>
<NewSemesterButton expanded />
<ViewArchiveButton />
</div>
</div>
<Separator />
</>
) : (
<div className="my-5 flex-1">
<div className="my-5 flex-1 space-y-3">
<NewSemesterButton />
<ViewArchiveButton />
</div>
)}
<Separator />
Expand Down
Loading

0 comments on commit 9af2c76

Please sign in to comment.