♻️ refactor: Refactor store

pull/290/head
canisminor1990 2023-07-20 11:19:42 +08:00
parent 68ab3d2bd6
commit c220794967
11 changed files with 70 additions and 66 deletions

File diff suppressed because one or more lines are too long

View File

@ -9,7 +9,7 @@ import { useAppStore } from '@/store';
import manifest from './manifest';
const App = memo(() => {
export const App = memo(() => {
const [loading, setLoading] = useState(true);
const { setCurrentTab, onInit, storeLoading } = useAppStore(
(st) => ({

View File

@ -1,5 +1,4 @@
import { FluentEmoji, Logo as LobeLogo } from '@lobehub/ui';
import { getEmoji } from '@lobehub/ui/es/utils/getEmojiByCharacter';
import { FluentEmoji, Logo as LobeLogo, getEmoji } from '@lobehub/ui';
import { Space } from 'antd';
import { type CSSProperties, memo } from 'react';

View File

@ -7,8 +7,13 @@ import { useTranslation } from 'react-i18next';
import { shallow } from 'zustand/shallow';
import { CustomLogo } from '@/components';
import { selectors, useAppStore } from '@/store';
import { DEFAULT_SETTING, type WebuiSetting, type WebuiSettingKeys } from '@/store/initialState';
import {
DEFAULT_SETTING,
type WebuiSetting,
type WebuiSettingKeys,
selectors,
useAppStore,
} from '@/store';
import {
type NeutralColor,

View File

@ -2,8 +2,7 @@ import i18next from 'i18next';
import HttpBackend, { HttpBackendOptions } from 'i18next-http-backend';
import { initReactI18next } from 'react-i18next';
import { SETTING_KEY } from '@/store/action';
import type { WebuiSetting } from '@/store/initialState';
import { SETTING_KEY, type WebuiSetting } from '@/store';
const localSetting = JSON.parse(localStorage.getItem(SETTING_KEY) as any) as WebuiSetting;

View File

@ -1,10 +1,11 @@
import { type DivProps, ThemeProvider } from '@lobehub/ui';
import {
type DivProps,
ThemeProvider,
colorScales,
generateColorNeutralPalette,
generateColorPalette,
} from '@lobehub/ui/es/styles/algorithms/generateColorPalette';
import { colorScales } from '@lobehub/ui/es/styles/colors';
import { neutralColorScales } from '@lobehub/ui/es/styles/neutralColors';
neutralColorScales,
} from '@lobehub/ui';
import isEqual from 'fast-deep-equal';
import qs from 'query-string';
import { memo, useCallback, useEffect } from 'react';

View File

@ -1,10 +1,10 @@
import { SelectProps } from 'antd';
import type { SelectProps } from 'antd';
import semver from 'semver';
import defualtLocaleOptions from '@/../locales/options.json';
import { homepage, version } from '@/../package.json';
import { WebuiSetting } from './initialState';
import type { WebuiSetting } from './initialState';
export const DEFAULT_VERSION: string = version;
export const DEFAULT_LOCALE_OPTIONS: SelectProps['options'] = defualtLocaleOptions;

View File

@ -5,5 +5,7 @@ import { type Store, createStore } from './store';
export const useAppStore = create<Store>()(devtools(createStore));
export * from './action';
export * from './initialState';
export { selectors } from './selectors';
export { type Store } from './store';

View File

@ -1,8 +1,8 @@
import { SelectProps } from 'antd';
import type { SelectProps } from 'antd';
import type { NeutralColor, PrimaryColor } from '@/components/Setting/data';
import { DEFAULT_LOCALE_OPTIONS, DEFAULT_VERSION } from '@/store/api';
import { I18n } from '@/types';
import type { I18n } from '@/types';
export interface WebuiSetting {
enableExtraNetworkSidebar: boolean;

View File

@ -1,9 +1,7 @@
import { defaults } from 'lodash-es';
import { DEFAULT_SETTING } from './initialState';
import { Store } from './store';
import type { Store } from './store';
const currentSetting = (s: Store) => defaults(s.setting, DEFAULT_SETTING);
const currentSetting = (s: Store) => ({ ...DEFAULT_SETTING, ...s.setting });
const currentTab = (s: Store) => s.currentTab;
const themeMode = (s: Store) => s.themeMode;
export const selectors = {

View File

@ -1,4 +1,4 @@
import { StateCreator } from 'zustand/vanilla';
import type { StateCreator } from 'zustand/vanilla';
import { type StoreAction, createSettings } from './action';
import { type StroeState, initialState } from './initialState';