diff --git a/package-lock.json b/package-lock.json index 641630a..ab7cc54 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15,6 +15,7 @@ "@aws-sdk/credential-providers": "^3.445.0", "@aws-sdk/s3-request-presigner": "^3.445.0", "@nextui-org/react": "^2.2.8", + "@preact/signals-react": "^1.3.6", "@prisma/client": "^5.5.2", "@react-email/button": "0.0.11", "@react-email/components": "^0.0.11", @@ -3243,6 +3244,31 @@ "url": "https://github.com/sponsors/panva" } }, + "node_modules/@preact/signals-core": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/@preact/signals-core/-/signals-core-1.5.0.tgz", + "integrity": "sha512-U2diO1Z4i1n2IoFgMYmRdHWGObNrcuTRxyNEn7deSq2cru0vj0583HYQZHsAqcs7FE+hQyX3mjIV7LAfHCvy8w==", + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/preact" + } + }, + "node_modules/@preact/signals-react": { + "version": "1.3.6", + "resolved": "https://registry.npmjs.org/@preact/signals-react/-/signals-react-1.3.6.tgz", + "integrity": "sha512-jr/4lhcRo5W3hfieCJGDPbxq3YjfZDvpmTcisJ+lRhjWvnoYrgMKBoTiLsFPACO8VIEATaIBZXYiGAV08YvnfQ==", + "dependencies": { + "@preact/signals-core": "^1.4.0", + "use-sync-external-store": "^1.2.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/preact" + }, + "peerDependencies": { + "react": "^16.14.0 || 17.x || 18.x" + } + }, "node_modules/@prisma/client": { "version": "5.5.2", "resolved": "https://registry.npmjs.org/@prisma/client/-/client-5.5.2.tgz", diff --git a/package.json b/package.json index 83aa4de..c2ece65 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,7 @@ "@aws-sdk/credential-providers": "^3.445.0", "@aws-sdk/s3-request-presigner": "^3.445.0", "@nextui-org/react": "^2.2.8", + "@preact/signals-react": "^1.3.6", "@prisma/client": "^5.5.2", "@react-email/button": "0.0.11", "@react-email/components": "^0.0.11", diff --git a/src/app/(site)/components/providers/DarkModeProvider.tsx b/src/app/(site)/components/providers/DarkModeProvider.tsx index b1e7b06..85a426f 100644 --- a/src/app/(site)/components/providers/DarkModeProvider.tsx +++ b/src/app/(site)/components/providers/DarkModeProvider.tsx @@ -4,6 +4,7 @@ import {createGenericContext} from "@/utils/client/client-data-utils"; import {FC, PropsWithChildren, useCallback, useEffect, useState} from "react"; import useLocalStorage from "@/app/(site)/hooks/useLocalStorage"; import {useTheme} from "next-themes"; +import {signal} from "@preact/signals-react"; const [DarkModeContext, hook] = createGenericContext<[boolean, (newVal: boolean) => void]>("useDarkMode must be used in a DarkModeProvider!") diff --git a/src/app/(site)/components/providers/signals/LocalStorageSignal.ts b/src/app/(site)/components/providers/signals/LocalStorageSignal.ts new file mode 100644 index 0000000..4ac6d4b --- /dev/null +++ b/src/app/(site)/components/providers/signals/LocalStorageSignal.ts @@ -0,0 +1,14 @@ +"use client" + +import {signal} from "@preact/signals-react"; +import {LocalStorage} from "@/app/(site)/hooks/useLocalStorage"; + +export const LocalStorageSignal = () => { + const localStorageObj = signal(new LocalStorage(localStorage)) + + const updateDarkMode = (newVal: boolean) => { + localStorageObj.value.darkMode = newVal + } + + return {localStorageObj, updateDarkMode} +} \ No newline at end of file diff --git a/src/app/(site)/hooks/useLocalStorage.ts b/src/app/(site)/hooks/useLocalStorage.ts index ecd2d5f..b20e078 100644 --- a/src/app/(site)/hooks/useLocalStorage.ts +++ b/src/app/(site)/hooks/useLocalStorage.ts @@ -3,7 +3,7 @@ import {useEffect, useMemo, useState} from "react"; import {defaultTutorialsState, TutorialsState} from "@/app/(site)/(internal)/dashboard/components/TutorialsProvider"; -class LocalStorage { +export class LocalStorage { constructor(private readonly storage: Storage) { }