chore: rename useComponentState to useStoreState
This commit is contained in:
parent
690beda0b9
commit
00d90f49de
10 changed files with 21 additions and 21 deletions
|
@ -1,5 +1,5 @@
|
||||||
import React, { useState, useEffect, useRef } from 'react';
|
import React, { useState, useEffect, useRef } from 'react';
|
||||||
import { useComponentState, useActions } from 'm/store';
|
import { useStoreState, useActions } from 'm/store';
|
||||||
|
|
||||||
import Input from 'c/Input';
|
import Input from 'c/Input';
|
||||||
import Button from 'c/Button';
|
import Button from 'c/Button';
|
||||||
|
@ -13,7 +13,7 @@ const mapStateToProps = s => ({
|
||||||
});
|
});
|
||||||
|
|
||||||
function APIConfig2() {
|
function APIConfig2() {
|
||||||
const { apiConfig } = useComponentState(mapStateToProps);
|
const { apiConfig } = useStoreState(mapStateToProps);
|
||||||
const [hostname, setHostname] = useState(apiConfig.hostname);
|
const [hostname, setHostname] = useState(apiConfig.hostname);
|
||||||
const [port, setPort] = useState(apiConfig.port);
|
const [port, setPort] = useState(apiConfig.port);
|
||||||
const [secret, setSecret] = useState(apiConfig.secret);
|
const [secret, setSecret] = useState(apiConfig.secret);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import React, { useEffect } from 'react';
|
import React, { useEffect } from 'react';
|
||||||
import { useActions, useComponentState } from 'm/store';
|
import { useActions, useStoreState } from 'm/store';
|
||||||
|
|
||||||
import Modal from 'c/Modal';
|
import Modal from 'c/Modal';
|
||||||
import APIConfig from 'c/APIConfig';
|
import APIConfig from 'c/APIConfig';
|
||||||
|
@ -19,7 +19,7 @@ const actions = {
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function APIDiscovery() {
|
export default function APIDiscovery() {
|
||||||
const { modals } = useComponentState(mapStateToProps);
|
const { modals } = useStoreState(mapStateToProps);
|
||||||
const { closeModal, fetchConfigs } = useActions(actions);
|
const { closeModal, fetchConfigs } = useActions(actions);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fetchConfigs();
|
fetchConfigs();
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import React, { useEffect, useState } from 'react';
|
import React, { useEffect, useState } from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import { useComponentState, useActions } from 'm/store';
|
import { useStoreState, useActions } from 'm/store';
|
||||||
|
|
||||||
import { getConfigs, fetchConfigs, updateConfigs } from 'd/configs';
|
import { getConfigs, fetchConfigs, updateConfigs } from 'd/configs';
|
||||||
|
|
||||||
|
@ -57,7 +57,7 @@ const mapStateToProps = s => ({ configs: getConfigs(s) });
|
||||||
|
|
||||||
export default function ConfigContainer() {
|
export default function ConfigContainer() {
|
||||||
const { fetchConfigs } = useActions(actions);
|
const { fetchConfigs } = useActions(actions);
|
||||||
const { configs } = useComponentState(mapStateToProps);
|
const { configs } = useStoreState(mapStateToProps);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fetchConfigs();
|
fetchConfigs();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import React, { useState, useEffect } from 'react';
|
import React, { useState, useEffect } from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import cx from 'classnames';
|
import cx from 'classnames';
|
||||||
import { useComponentState } from 'm/store';
|
import { useStoreState } from 'm/store';
|
||||||
import { getClashAPIConfig } from 'd/app';
|
import { getClashAPIConfig } from 'd/app';
|
||||||
|
|
||||||
import Icon from 'c/Icon';
|
import Icon from 'c/Icon';
|
||||||
|
@ -45,7 +45,7 @@ LogLine.propTypes = {
|
||||||
|
|
||||||
export default function Logs() {
|
export default function Logs() {
|
||||||
const [logs, setLogs] = useState([]);
|
const [logs, setLogs] = useState([]);
|
||||||
const { hostname, port, secret } = useComponentState(getClashAPIConfig);
|
const { hostname, port, secret } = useStoreState(getClashAPIConfig);
|
||||||
|
|
||||||
useEffect(
|
useEffect(
|
||||||
() => {
|
() => {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import React, { useEffect } from 'react';
|
import React, { useEffect } from 'react';
|
||||||
import { useActions, useComponentState } from 'm/store';
|
import { useActions, useStoreState } from 'm/store';
|
||||||
|
|
||||||
import ContentHeader from 'c/ContentHeader';
|
import ContentHeader from 'c/ContentHeader';
|
||||||
import ProxyGroup from 'c/ProxyGroup';
|
import ProxyGroup from 'c/ProxyGroup';
|
||||||
|
@ -29,7 +29,7 @@ export default function Proxies() {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fetchProxies();
|
fetchProxies();
|
||||||
}, []);
|
}, []);
|
||||||
const { groupNames } = useComponentState(mapStateToProps);
|
const { groupNames } = useStoreState(mapStateToProps);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import { useComponentState } from 'm/store';
|
import { useStoreState } from 'm/store';
|
||||||
|
|
||||||
import Icon from 'c/Icon';
|
import Icon from 'c/Icon';
|
||||||
import ProxyLatency from 'c/ProxyLatency';
|
import ProxyLatency from 'c/ProxyLatency';
|
||||||
|
@ -41,7 +41,7 @@ const mapStateToProps = s => {
|
||||||
};
|
};
|
||||||
|
|
||||||
function Proxy({ now, name }) {
|
function Proxy({ now, name }) {
|
||||||
const { proxies, delay } = useComponentState(mapStateToProps);
|
const { proxies, delay } = useStoreState(mapStateToProps);
|
||||||
|
|
||||||
// const { name, proxies, delay, now } = this.props;
|
// const { name, proxies, delay, now } = this.props;
|
||||||
const latency = delay[name];
|
const latency = delay[name];
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import React, { useMemo } from 'react';
|
import React, { useMemo } from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import { useActions, useComponentState } from 'm/store';
|
import { useActions, useStoreState } from 'm/store';
|
||||||
|
|
||||||
import Proxy from 'c/Proxy';
|
import Proxy from 'c/Proxy';
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ const mapStateToProps = s => ({
|
||||||
// should move this to sth like constants.js
|
// should move this to sth like constants.js
|
||||||
// const userProxyTypes = ['Shadowsocks', 'Vmess', 'Socks5'];
|
// const userProxyTypes = ['Shadowsocks', 'Vmess', 'Socks5'];
|
||||||
export default function ProxyGroup2({ name }) {
|
export default function ProxyGroup2({ name }) {
|
||||||
const { proxies } = useComponentState(mapStateToProps);
|
const { proxies } = useStoreState(mapStateToProps);
|
||||||
const actions = useActions({ switchProxy });
|
const actions = useActions({ switchProxy });
|
||||||
const group = proxies[name];
|
const group = proxies[name];
|
||||||
const { all, now } = group;
|
const { all, now } = group;
|
||||||
|
|
|
@ -2,7 +2,7 @@ import React, { useEffect } from 'react';
|
||||||
import prettyBytes from 'm/pretty-bytes';
|
import prettyBytes from 'm/pretty-bytes';
|
||||||
import { fetchData } from '../api/traffic';
|
import { fetchData } from '../api/traffic';
|
||||||
import { unstable_createResource as createResource } from 'react-cache';
|
import { unstable_createResource as createResource } from 'react-cache';
|
||||||
import { useComponentState } from 'm/store';
|
import { useStoreState } from 'm/store';
|
||||||
import { getClashAPIConfig, getTheme } from 'd/app';
|
import { getClashAPIConfig, getTheme } from 'd/app';
|
||||||
|
|
||||||
// const delay = ms => new Promise(r => setTimeout(r, ms));
|
// const delay = ms => new Promise(r => setTimeout(r, ms));
|
||||||
|
@ -139,8 +139,8 @@ const chartWrapperStyle = {
|
||||||
|
|
||||||
export default function TrafficChart() {
|
export default function TrafficChart() {
|
||||||
const Chart = chartJSResource.read();
|
const Chart = chartJSResource.read();
|
||||||
const { hostname, port, secret } = useComponentState(getClashAPIConfig);
|
const { hostname, port, secret } = useStoreState(getClashAPIConfig);
|
||||||
const theme = useComponentState(getTheme);
|
const theme = useStoreState(getTheme);
|
||||||
|
|
||||||
useEffect(
|
useEffect(
|
||||||
() => {
|
() => {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import React, { useState, useEffect } from 'react';
|
import React, { useState, useEffect } from 'react';
|
||||||
import prettyBytes from 'm/pretty-bytes';
|
import prettyBytes from 'm/pretty-bytes';
|
||||||
|
|
||||||
import { useComponentState } from 'm/store';
|
import { useStoreState } from 'm/store';
|
||||||
import { getClashAPIConfig } from 'd/app';
|
import { getClashAPIConfig } from 'd/app';
|
||||||
import { fetchData } from '../api/traffic';
|
import { fetchData } from '../api/traffic';
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ export default function TrafficNow() {
|
||||||
|
|
||||||
function useSpeed() {
|
function useSpeed() {
|
||||||
const [speed, setSpeed] = useState({ upStr: '0 B/s', downStr: '0 B/s' });
|
const [speed, setSpeed] = useState({ upStr: '0 B/s', downStr: '0 B/s' });
|
||||||
const { hostname, port, secret } = useComponentState(getClashAPIConfig);
|
const { hostname, port, secret } = useStoreState(getClashAPIConfig);
|
||||||
useEffect(
|
useEffect(
|
||||||
() => {
|
() => {
|
||||||
return fetchData({
|
return fetchData({
|
||||||
|
|
|
@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
|
||||||
import { bindActionCreators } from 'redux';
|
import { bindActionCreators } from 'redux';
|
||||||
import shallowEqual from './shallowEqual';
|
import shallowEqual from './shallowEqual';
|
||||||
|
|
||||||
export const StoreContext = createContext(null);
|
const StoreContext = createContext(null);
|
||||||
|
|
||||||
export function Provider({ store, children }) {
|
export function Provider({ store, children }) {
|
||||||
return (
|
return (
|
||||||
|
@ -28,7 +28,7 @@ export function useActions(actions) {
|
||||||
return bindActionCreators(a, dispatch);
|
return bindActionCreators(a, dispatch);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useComponentState(selector) {
|
export function useStoreState(selector) {
|
||||||
const store = useStore();
|
const store = useStore();
|
||||||
const initialMappedState = selector(store.getState());
|
const initialMappedState = selector(store.getState());
|
||||||
const [compState, setCompState] = useState(initialMappedState);
|
const [compState, setCompState] = useState(initialMappedState);
|
||||||
|
|
Loading…
Reference in a new issue