webterm: clean up component state derivation

This commit is contained in:
Fang 2021-06-29 16:03:21 +02:00
parent 329ec8ef3f
commit d138ab254b
No known key found for this signature in database
GPG Key ID: EB035760C1BBA972

View File

@ -6,8 +6,7 @@ import React, {
import Helmet from 'react-helmet'; import Helmet from 'react-helmet';
import useTermState from '~/logic/state/term'; import useTermState from '~/logic/state/term';
import useSettingsState from '~/logic/state/settings'; import { useDark } from '~/logic/state/join';
import useLocalState from '~/logic/state/local';
import { Terminal, ITerminalOptions, ITheme } from 'xterm'; import { Terminal, ITerminalOptions, ITheme } from 'xterm';
import { FitAddon } from 'xterm-addon-fit'; import { FitAddon } from 'xterm-addon-fit';
@ -278,15 +277,8 @@ export default function TermApp(props: TermAppProps) {
const container = useRef<HTMLDivElement>(null); const container = useRef<HTMLDivElement>(null);
// TODO allow switching of selected // TODO allow switching of selected
const { sessions, selected, slogstream, set } = useTermState(); const { sessions, selected, slogstream, set } = useTermState();
const session = sessions[selected];
const session = useTermState(useCallback( const dark = useDark();
state => state.sessions[state.selected],
[selected, sessions]
));
const osDark = useLocalState(state => state.dark);
const theme = useSettingsState(s => s.display.theme);
const dark = theme === 'dark' || (theme === 'auto' && osDark);
const setupSlog = useCallback(() => { const setupSlog = useCallback(() => {
console.log('slog: setting up...'); console.log('slog: setting up...');