Changed way of declaring Zustand functions
This commit is contained in:
parent
ca7193476d
commit
17fd965231
6 changed files with 11 additions and 16 deletions
|
|
@ -53,7 +53,7 @@ export default function CodeTabsComponent({
|
||||||
const [isCopied, setIsCopied] = useState<Boolean>(false);
|
const [isCopied, setIsCopied] = useState<Boolean>(false);
|
||||||
const [data, setData] = useState(flow ? flow["data"]!["nodes"] : null);
|
const [data, setData] = useState(flow ? flow["data"]!["nodes"] : null);
|
||||||
const [openAccordion, setOpenAccordion] = useState<string[]>([]);
|
const [openAccordion, setOpenAccordion] = useState<string[]>([]);
|
||||||
const dark = useDarkStore((state) => state.dark);
|
const {dark} = useDarkStore();
|
||||||
|
|
||||||
const { setNodes } = useContext(FlowsContext);
|
const { setNodes } = useContext(FlowsContext);
|
||||||
const [errorDuplicateKey, setErrorDuplicateKey] = useState(false);
|
const [errorDuplicateKey, setErrorDuplicateKey] = useState(false);
|
||||||
|
|
|
||||||
|
|
@ -31,10 +31,7 @@ export default function Header(): JSX.Element {
|
||||||
const { hasStore } = useContext(StoreContext);
|
const { hasStore } = useContext(StoreContext);
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|
||||||
const dark = useDarkStore((state) => state.dark);
|
const {dark, setDark, stars, gradientIndex} = useDarkStore();
|
||||||
const setDark = useDarkStore((state) => state.updateDark);
|
|
||||||
const stars = useDarkStore((state) => state.stars);
|
|
||||||
const gradientIndex = useDarkStore((state) => state.gradientIndex);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (dark) {
|
if (dark) {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
import { useEffect, useRef, useState } from "react";
|
import { useEffect, useRef, useState } from "react";
|
||||||
import { useDarkStore } from "../../stores/darkStore";
|
|
||||||
import { cn } from "../../utils/utils";
|
import { cn } from "../../utils/utils";
|
||||||
import { Badge } from "../ui/badge";
|
import { Badge } from "../ui/badge";
|
||||||
|
|
||||||
|
|
@ -24,7 +23,6 @@ export function TagsSelector({
|
||||||
: selectedTags.filter((_, i) => i !== index);
|
: selectedTags.filter((_, i) => i !== index);
|
||||||
setSelectedTags(newArray);
|
setSelectedTags(newArray);
|
||||||
};
|
};
|
||||||
const dark = useDarkStore((state) => state.dark);
|
|
||||||
|
|
||||||
const scrollContainerRef = useRef<HTMLDivElement>(null);
|
const scrollContainerRef = useRef<HTMLDivElement>(null);
|
||||||
const fadeContainerRef = useRef<HTMLDivElement>(null);
|
const fadeContainerRef = useRef<HTMLDivElement>(null);
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ export default function CodeAreaModal({
|
||||||
readonly = false,
|
readonly = false,
|
||||||
}: codeAreaModalPropsType): JSX.Element {
|
}: codeAreaModalPropsType): JSX.Element {
|
||||||
const [code, setCode] = useState(value);
|
const [code, setCode] = useState(value);
|
||||||
const dark = useDarkStore((state) => state.dark);
|
const {dark} = useDarkStore();
|
||||||
|
|
||||||
const [height, setHeight] = useState<string | null>(null);
|
const [height, setHeight] = useState<string | null>(null);
|
||||||
const { setErrorData, setSuccessData } = useContext(alertContext);
|
const { setErrorData, setSuccessData } = useContext(alertContext);
|
||||||
|
|
|
||||||
|
|
@ -8,9 +8,9 @@ type State = {
|
||||||
};
|
};
|
||||||
|
|
||||||
type Action = {
|
type Action = {
|
||||||
updateDark: (dark: State["dark"]) => void;
|
setDark: (dark: State["dark"]) => void;
|
||||||
updateStars: (starts: State["stars"]) => void;
|
setStars: (starts: State["stars"]) => void;
|
||||||
updateGradientIndex: (gradientIndex: State["gradientIndex"]) => void;
|
setGradientIndex: (gradientIndex: State["gradientIndex"]) => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
function gradientIndexInitialState() {
|
function gradientIndexInitialState() {
|
||||||
|
|
@ -23,9 +23,9 @@ export const useDarkStore = create<State & Action>((set) => ({
|
||||||
dark: JSON.parse(window.localStorage.getItem("isDark")!) ?? false,
|
dark: JSON.parse(window.localStorage.getItem("isDark")!) ?? false,
|
||||||
stars: 0,
|
stars: 0,
|
||||||
gradientIndex: gradientIndexInitialState(),
|
gradientIndex: gradientIndexInitialState(),
|
||||||
updateDark: (dark) => set(() => ({ dark: dark })),
|
setDark: (dark) => set(() => ({ dark: dark })),
|
||||||
updateStars: (starts) => set(() => ({ stars: starts })),
|
setStars: (starts) => set(() => ({ stars: starts })),
|
||||||
updateGradientIndex: (gradientIndex) =>
|
setGradientIndex: (gradientIndex) =>
|
||||||
set(() => ({ gradientIndex: gradientIndex })),
|
set(() => ({ gradientIndex: gradientIndex })),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ type RFState = {
|
||||||
};
|
};
|
||||||
|
|
||||||
// this is our useStore hook that we can use in our components to get parts of the store and call actions
|
// this is our useStore hook that we can use in our components to get parts of the store and call actions
|
||||||
const useStore = create<RFState>((set, get) => ({
|
const useFlow = create<RFState>((set, get) => ({
|
||||||
nodes: [],
|
nodes: [],
|
||||||
edges: [],
|
edges: [],
|
||||||
isBuilt: false,
|
isBuilt: false,
|
||||||
|
|
@ -75,4 +75,4 @@ const useStore = create<RFState>((set, get) => ({
|
||||||
isPending: false,
|
isPending: false,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
export default useStore;
|
export default useFlow;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue