mirror of
https://github.com/FranP-code/spend-ia.git
synced 2025-10-13 00:14:09 +00:00
integration of zustand
This commit is contained in:
16
lib/storage.ts
Normal file
16
lib/storage.ts
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
/* eslint-disable @typescript-eslint/ban-types */
|
||||||
|
import { create } from 'zustand';
|
||||||
|
import { type Tab } from '@/lib/types';
|
||||||
|
import { SPEND_SCREEN_ID, SPEND_SCREEN_NAME } from '@/lib/constants';
|
||||||
|
|
||||||
|
interface appStore {
|
||||||
|
tab: Tab;
|
||||||
|
setTab: (props: Tab) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const useAppStore = create<appStore>((set) => ({
|
||||||
|
setTab: (props: Tab) => {
|
||||||
|
set(() => ({ tab: props }));
|
||||||
|
},
|
||||||
|
tab: { id: SPEND_SCREEN_ID, title: SPEND_SCREEN_NAME },
|
||||||
|
}));
|
||||||
@@ -21,7 +21,8 @@
|
|||||||
"react": "^18.2.0",
|
"react": "^18.2.0",
|
||||||
"react-chartjs-2": "^5.2.0",
|
"react-chartjs-2": "^5.2.0",
|
||||||
"react-dom": "^18.2.0",
|
"react-dom": "^18.2.0",
|
||||||
"styled-components": "^5.3.9"
|
"styled-components": "^5.3.9",
|
||||||
|
"zustand": "^4.3.7"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/node": "18.15.11",
|
"@types/node": "18.15.11",
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import React, { useState } from 'react';
|
import React from 'react';
|
||||||
import { Header, SpendScreen } from '@/screens';
|
import { Header, SpendScreen } from '@/screens';
|
||||||
import { type Tab } from '@/lib/types';
|
import { type Tab } from '@/lib/types';
|
||||||
import { APP_NAME, SPEND_SCREEN_ID, SPEND_SCREEN_NAME } from '@/lib/constants';
|
import { APP_NAME, SPEND_SCREEN_ID } from '@/lib/constants';
|
||||||
|
|
||||||
import Head from 'next/head';
|
import Head from 'next/head';
|
||||||
|
import { useAppStore } from '@/lib/storage';
|
||||||
|
|
||||||
const HeadIndex = (): JSX.Element => {
|
const HeadIndex = (): JSX.Element => {
|
||||||
return (
|
return (
|
||||||
@@ -26,12 +26,11 @@ const appRender = ({ tab }: { tab: Tab }): JSX.Element => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
function App(): JSX.Element {
|
function App(): JSX.Element {
|
||||||
const [tab, setTab] = useState({ id: SPEND_SCREEN_ID, title: SPEND_SCREEN_NAME });
|
const tab = useAppStore((state) => state.tab);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<HeadIndex />
|
<HeadIndex />
|
||||||
<Header tab={tab} setTab={setTab} />
|
<Header />
|
||||||
{appRender({ tab })}
|
{appRender({ tab })}
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,15 +1,12 @@
|
|||||||
|
/* eslint-disable no-empty-pattern */
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { tabs } from './data';
|
|
||||||
import { type Tab } from '@/lib/types';
|
|
||||||
import styled from 'styled-components';
|
import styled from 'styled-components';
|
||||||
|
import { useAppStore } from '@/lib/storage';
|
||||||
|
import { tabs } from './data';
|
||||||
|
|
||||||
export const Header = ({
|
export const Header = (): JSX.Element => {
|
||||||
tab,
|
const tab = useAppStore((state) => state.tab);
|
||||||
setTab,
|
const setTab = useAppStore((state) => state.setTab);
|
||||||
}: {
|
|
||||||
tab: Tab;
|
|
||||||
setTab: React.Dispatch<React.SetStateAction<Tab>>;
|
|
||||||
}): JSX.Element => {
|
|
||||||
return (
|
return (
|
||||||
<TabsContainer>
|
<TabsContainer>
|
||||||
{tabs.map((tabData) => (
|
{tabs.map((tabData) => (
|
||||||
|
|||||||
@@ -21,7 +21,7 @@
|
|||||||
"@/*": ["*"]
|
"@/*": ["*"]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"include": ["next-env.d.ts", "pages", "components", "screens", "lib/constants.ts", "lib/types.d.ts"],
|
"include": ["next-env.d.ts", "pages", "components", "screens", "lib"],
|
||||||
"references": [
|
"references": [
|
||||||
{
|
{
|
||||||
"path": "./tsconfig.node.json"
|
"path": "./tsconfig.node.json"
|
||||||
|
|||||||
Reference in New Issue
Block a user