mirror of
https://github.com/urbit/shrub.git
synced 2024-12-22 10:21:31 +03:00
webterm: improve slogstream management
Don't re-open the slog eventsource every time we navigate to webterm.
This commit is contained in:
parent
a13f19d6f9
commit
aa244a10ea
@ -9,11 +9,13 @@ type Sessions = { [id: string]: Session; }
|
||||
export interface TermState extends BaseState<TermState> {
|
||||
sessions: Sessions,
|
||||
selected: string,
|
||||
slogstream: null | EventSource,
|
||||
};
|
||||
|
||||
const useTermState = createState<TermState>('Term', {
|
||||
sessions: {},
|
||||
selected: '', // empty string is default session
|
||||
}, ['sessions']); //TODO consider persisting
|
||||
slogstream: null,
|
||||
}, ['sessions', 'slogstream']); //TODO consider persisting
|
||||
|
||||
export default useTermState;
|
@ -128,7 +128,7 @@ export default function TermApp(props: TermAppProps) {
|
||||
|
||||
const container = useRef<HTMLElement>(null);
|
||||
//TODO allow switching of selected
|
||||
const { sessions, selected, set } = useTermState();
|
||||
const { sessions, selected, slogstream, set } = useTermState();
|
||||
|
||||
const osDark = useLocalState((state) => state.dark);
|
||||
const theme = useSettingsState(s => s.display.theme);
|
||||
@ -246,6 +246,8 @@ export default function TermApp(props: TermAppProps) {
|
||||
}, 10000);
|
||||
}
|
||||
}
|
||||
|
||||
set(state => { state.slogstream = slog });
|
||||
}, [onSlog]);
|
||||
|
||||
const onInput = useCallback((ses: string, e: string) => {
|
||||
@ -341,13 +343,13 @@ export default function TermApp(props: TermAppProps) {
|
||||
// on-init, open slogstream
|
||||
//
|
||||
useEffect(() => {
|
||||
setupSlog();
|
||||
if (!slogstream) setupSlog();
|
||||
window.addEventListener('resize', onResize);
|
||||
return () => {
|
||||
//TODO clean up subs?
|
||||
window.removeEventListener('resize', onResize);
|
||||
};
|
||||
}, [onResize]);
|
||||
}, [onResize, setupSlog]);
|
||||
|
||||
// on dark mode change, change terminals' theme
|
||||
//
|
||||
|
Loading…
Reference in New Issue
Block a user