Skip to content

Commit 1dfe589

Browse files
committed
✨ feat: Made configuration persistent onReload (localStorage Atom)
1 parent 0b78382 commit 1dfe589

3 files changed

Lines changed: 10 additions & 6 deletions

File tree

app/Components/ConfigMenu/DisableTabs.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ import { useState } from "react";
66
export function DisableTabsOption() {
77
const { config, updateConfig } = useConfig();
88

9-
const disableTabs = config.disableTabs
9+
const disableTabs = config.disableTabs;
1010

1111
function toogleTabsFunctionality() {
12-
updateConfig({ disableTabs: !disableTabs });
12+
updateConfig({ ...config, disableTabs: !disableTabs });
1313
}
1414

1515
return (

app/Components/TasksApp/_TaskApp.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ import { useConfig } from "@/app/_lib/contexts/ConfigContext";
1212
import clsx from "clsx";
1313

1414
const initialTasks: Task[] = [
15-
{ id: "2", text: "Drink matcha", done: false, date: new Date() },
16-
{ id: "1", text: "Call grandma", done: false, date: new Date() },
15+
{ id: "2", text: "Drink matcha", done: false, date: new Date(99, 0) },
16+
{ id: "1", text: "Call grandma", done: false, date: new Date(99, 0) },
1717
{
1818
id: "0",
1919
text: "Contemplate the inevitable increase of entropy in the universe",
2020
done: true,
21-
date: new Date(),
21+
date: new Date(99, 0 ),
2222
},
2323
];
2424

app/_lib/contexts/ConfigContext.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"use client";
22

3+
import { useAtom } from "jotai";
4+
import { atomWithStorage } from "jotai/utils";
35
// ConfigContext.tsx
46
import React, { createContext, useState, useContext, ReactNode } from "react";
57

@@ -21,12 +23,14 @@ const initialConfig: TasksConfig = {
2123
disableTabs: false,
2224
};
2325

26+
const configAtom = atomWithStorage("config", initialConfig);
27+
2428
export const ConfigContextProvider = ({
2529
children,
2630
}: Readonly<{
2731
children: React.ReactNode;
2832
}>) => {
29-
const [config, setConfig] = useState<TasksConfig>(initialConfig);
33+
const [config, setConfig] = useAtom(configAtom);
3034

3135
const updateConfig = (newConfig: TasksConfig) => {
3236
setConfig({ ...newConfig });

0 commit comments

Comments
 (0)