♻️ refactor: Refactor store
parent
68ab3d2bd6
commit
c220794967
File diff suppressed because one or more lines are too long
|
|
@ -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) => ({
|
||||
|
|
|
|||
|
|
@ -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';
|
||||
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
|
|
@ -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';
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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';
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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 = {
|
||||
|
|
|
|||
|
|
@ -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';
|
||||
|
|
|
|||
Loading…
Reference in New Issue