pl-fe: WIP migrate settings store to zustand
Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
@ -1,13 +1,12 @@
|
||||
import React from 'react';
|
||||
|
||||
import { getSettings } from 'pl-fe/actions/settings';
|
||||
import { useAppSelector } from 'pl-fe/hooks';
|
||||
import { useSettingsStore } from 'pl-fe/stores/settings';
|
||||
|
||||
import DevelopersChallenge from './developers-challenge';
|
||||
import DevelopersMenu from './developers-menu';
|
||||
|
||||
const Developers: React.FC = () => {
|
||||
const isDeveloper = useAppSelector((state) => getSettings(state).get('isDeveloper'));
|
||||
const { isDeveloper } = useSettingsStore().settings;
|
||||
|
||||
return isDeveloper ? <DevelopersMenu /> : <DevelopersChallenge />;
|
||||
};
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { useIntl, FormattedMessage, defineMessages } from 'react-intl';
|
||||
|
||||
import { SETTINGS_UPDATE, changeSetting, updateSettingsStore } from 'pl-fe/actions/settings';
|
||||
import { changeSetting, updateSettingsStore } from 'pl-fe/actions/settings';
|
||||
import List, { ListItem } from 'pl-fe/components/list';
|
||||
import {
|
||||
CardHeader,
|
||||
@ -14,7 +14,8 @@ import {
|
||||
Textarea,
|
||||
} from 'pl-fe/components/ui';
|
||||
import SettingToggle from 'pl-fe/features/notifications/components/setting-toggle';
|
||||
import { useAppSelector, useAppDispatch, useSettings } from 'pl-fe/hooks';
|
||||
import { useAppDispatch } from 'pl-fe/hooks';
|
||||
import { useSettingsStore } from 'pl-fe/stores/settings';
|
||||
import toast from 'pl-fe/toast';
|
||||
|
||||
const isJSONValid = (text: any): boolean => {
|
||||
@ -35,10 +36,9 @@ const messages = defineMessages({
|
||||
const SettingsStore: React.FC = () => {
|
||||
const intl = useIntl();
|
||||
const dispatch = useAppDispatch();
|
||||
const settings = useSettings();
|
||||
const settingsStore = useAppSelector(state => state.settings);
|
||||
const { settings, userSettings, loadUserSettings } = useSettingsStore();
|
||||
|
||||
const [rawJSON, setRawJSON] = useState<string>(JSON.stringify(settingsStore, null, 2));
|
||||
const [rawJSON, setRawJSON] = useState<string>(JSON.stringify(userSettings, null, 2));
|
||||
const [jsonValid, setJsonValid] = useState(true);
|
||||
const [isLoading, setLoading] = useState(false);
|
||||
|
||||
@ -57,7 +57,7 @@ const SettingsStore: React.FC = () => {
|
||||
|
||||
setLoading(true);
|
||||
dispatch(updateSettingsStore(settings)).then(() => {
|
||||
dispatch({ type: SETTINGS_UPDATE, settings });
|
||||
loadUserSettings(settings);
|
||||
setLoading(false);
|
||||
}).catch(error => {
|
||||
toast.showAlertForError(error);
|
||||
@ -66,9 +66,9 @@ const SettingsStore: React.FC = () => {
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
setRawJSON(JSON.stringify(settingsStore, null, 2));
|
||||
setRawJSON(JSON.stringify(userSettings, null, 2));
|
||||
setJsonValid(true);
|
||||
}, [settingsStore]);
|
||||
}, [userSettings]);
|
||||
|
||||
return (
|
||||
<Column label={intl.formatMessage(messages.heading)} backHref='/developers'>
|
||||
|
||||
Reference in New Issue
Block a user