Skip to content

Commit

Permalink
Start signals implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
bombies committed Nov 12, 2023
1 parent caa9dd6 commit 4fe80df
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 1 deletion.
26 changes: 26 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions src/app/(site)/components/providers/DarkModeProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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!")
Expand Down
14 changes: 14 additions & 0 deletions src/app/(site)/components/providers/signals/LocalStorageSignal.ts
Original file line number Diff line number Diff line change
@@ -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}
}
2 changes: 1 addition & 1 deletion src/app/(site)/hooks/useLocalStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
}

Expand Down

0 comments on commit 4fe80df

Please sign in to comment.