diff --git a/ui/package-lock.json b/ui/package-lock.json index 98bfc9969..7dbac7c07 100644 --- a/ui/package-lock.json +++ b/ui/package-lock.json @@ -7856,6 +7856,11 @@ "pify": "^4.0.1" } }, + "hamt_plus": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/hamt_plus/-/hamt_plus-1.0.2.tgz", + "integrity": "sha1-4hwlKWjH4zsg9qGwlM2FeHomVgE=" + }, "handle-thing": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/handle-thing/-/handle-thing-2.0.1.tgz", @@ -14229,6 +14234,14 @@ "picomatch": "^2.2.1" } }, + "recoil": { + "version": "0.5.2", + "resolved": "https://registry.npmjs.org/recoil/-/recoil-0.5.2.tgz", + "integrity": "sha512-Edibzpu3dbUMLy6QRg73WL8dvMl9Xqhp+kU+f2sJtXxsaXvAlxU/GcnDE8HXPkprXrhHF2e6SZozptNvjNF5fw==", + "requires": { + "hamt_plus": "1.0.2" + } + }, "recursive-readdir": { "version": "2.2.2", "resolved": "https://registry.npmjs.org/recursive-readdir/-/recursive-readdir-2.2.2.tgz", diff --git a/ui/package.json b/ui/package.json index 64763c557..a3de9574b 100644 --- a/ui/package.json +++ b/ui/package.json @@ -31,6 +31,7 @@ "react-scrollable-feed-virtualized": "^1.4.9", "react-syntax-highlighter": "^15.4.3", "react-toastify": "^8.0.3", + "recoil": "^0.5.2", "typescript": "^4.2.4", "web-vitals": "^1.1.1", "xml-formatter": "^2.6.0" diff --git a/ui/src/EntApp.tsx b/ui/src/EntApp.tsx index 452b8013d..34bebdf32 100644 --- a/ui/src/EntApp.tsx +++ b/ui/src/EntApp.tsx @@ -1,4 +1,4 @@ -import React, {useEffect, useState} from 'react'; +import React, {useCallback, useEffect, useState} from 'react'; import './App.sass'; import {TrafficPage} from "./components/TrafficPage"; import {TLSWarning} from "./components/TLSWarning/TLSWarning"; @@ -9,43 +9,29 @@ import InstallPage from "./components/InstallPage"; import LoginPage from "./components/LoginPage"; import LoadingOverlay from "./components/LoadingOverlay"; import AuthPageBase from './components/AuthPageBase'; +import entPageAtom, {Page} from "./recoil/entPage"; +import {useRecoilState} from "recoil"; const api = Api.getInstance(); -// TODO: move to state management -export enum Page { - Traffic, - Setup, - Login -} - -// TODO: move to state management -export interface MizuContextModel { - page: Page; - setPage: (page: Page) => void; -} - -// TODO: move to state management -export const MizuContext = React.createContext(null); - const EntApp = () => { const [isLoading, setIsLoading] = useState(true); const [showTLSWarning, setShowTLSWarning] = useState(false); const [userDismissedTLSWarning, setUserDismissedTLSWarning] = useState(false); const [addressesWithTLS, setAddressesWithTLS] = useState(new Set()); - const [page, setPage] = useState(Page.Traffic); // TODO: move to state management + const [entPage, setEntPage] = useRecoilState(entPageAtom); const [isFirstLogin, setIsFirstLogin] = useState(false); - const determinePage = async () => { // TODO: move to state management + const determinePage = useCallback(async () => { // TODO: move to state management try { const isInstallNeeded = await api.isInstallNeeded(); if (isInstallNeeded) { - setPage(Page.Setup); + setEntPage(Page.Setup); } else { const isAuthNeeded = await api.isAuthenticationNeeded(); if(isAuthNeeded) { - setPage(Page.Login); + setEntPage(Page.Login); } } } catch (e) { @@ -54,11 +40,11 @@ const EntApp = () => { } finally { setIsLoading(false); } - } + },[setEntPage]); useEffect(() => { determinePage(); - }, []); + }, [determinePage]); const onTLSDetected = (destAddress: string) => { addressesWithTLS.add(destAddress); @@ -71,7 +57,7 @@ const EntApp = () => { let pageComponent: any; - switch (page) { // TODO: move to state management / proper routing + switch (entPage) { // TODO: move to state management / proper routing case Page.Traffic: pageComponent = ; break; @@ -91,16 +77,14 @@ const EntApp = () => { return (
- - {page === Page.Traffic && } - {pageComponent} - {page === Page.Traffic && } - + {entPage === Page.Traffic && } + {pageComponent} + {entPage === Page.Traffic && }
); } diff --git a/ui/src/components/EntriesList.tsx b/ui/src/components/EntriesList.tsx index 4fb88cbf2..532af5ee0 100644 --- a/ui/src/components/EntriesList.tsx +++ b/ui/src/components/EntriesList.tsx @@ -6,11 +6,12 @@ import {EntryItem} from "./EntryListItem/EntryListItem"; import down from "./assets/downImg.svg"; import spinner from './assets/spinner.svg'; import Api from "../helpers/api"; +import {useRecoilState, useRecoilValue} from "recoil"; +import entriesAtom from "../recoil/entries"; +import wsConnectionAtom, {WsConnectionStatus} from "../recoil/wsConnection"; +import queryAtom from "../recoil/query"; interface EntriesListProps { - entries: any[]; - setEntries: any; - query: string; listEntryREF: any; onSnapBrokenEvent: () => void; isSnappedToBottom: boolean; @@ -22,12 +23,8 @@ interface EntriesListProps { startTime: number; noMoreDataTop: boolean; setNoMoreDataTop: (flag: boolean) => void; - focusedEntryId: string; - setFocusedEntryId: (id: string) => void; - updateQuery: any; leftOffTop: number; setLeftOffTop: (leftOffTop: number) => void; - isWebSocketConnectionClosed: boolean; ws: any; openWebSocket: (query: string, resetEntries: boolean) => void; leftOffBottom: number; @@ -38,7 +35,13 @@ interface EntriesListProps { const api = Api.getInstance(); -export const EntriesList: React.FC = ({entries, setEntries, query, listEntryREF, onSnapBrokenEvent, isSnappedToBottom, setIsSnappedToBottom, queriedCurrent, setQueriedCurrent, queriedTotal, setQueriedTotal, startTime, noMoreDataTop, setNoMoreDataTop, focusedEntryId, setFocusedEntryId, updateQuery, leftOffTop, setLeftOffTop, isWebSocketConnectionClosed, ws, openWebSocket, leftOffBottom, truncatedTimestamp, setTruncatedTimestamp, scrollableRef}) => { +export const EntriesList: React.FC = ({listEntryREF, onSnapBrokenEvent, isSnappedToBottom, setIsSnappedToBottom, queriedCurrent, setQueriedCurrent, queriedTotal, setQueriedTotal, startTime, noMoreDataTop, setNoMoreDataTop, leftOffTop, setLeftOffTop, ws, openWebSocket, leftOffBottom, truncatedTimestamp, setTruncatedTimestamp, scrollableRef}) => { + + const [entries, setEntries] = useRecoilState(entriesAtom); + const wsConnection = useRecoilValue(wsConnectionAtom); + const query = useRecoilValue(queryAtom); + const isWsConnectionClosed = wsConnection === WsConnectionStatus.Closed; + const [loadMoreTop, setLoadMoreTop] = useState(false); const [isLoadingTop, setIsLoadingTop] = useState(false); @@ -95,9 +98,9 @@ export const EntriesList: React.FC = ({entries, setEntries, qu },[setLoadMoreTop, setIsLoadingTop, entries, setEntries, query, setNoMoreDataTop, leftOffTop, setLeftOffTop, queriedCurrent, setQueriedCurrent, setQueriedTotal, setTruncatedTimestamp, scrollableRef]); useEffect(() => { - if(!isWebSocketConnectionClosed || !loadMoreTop || noMoreDataTop) return; + if(!isWsConnectionClosed || !loadMoreTop || noMoreDataTop) return; getOldEntries(); - }, [loadMoreTop, noMoreDataTop, getOldEntries, isWebSocketConnectionClosed]); + }, [loadMoreTop, noMoreDataTop, getOldEntries, isWsConnectionClosed]); const scrollbarVisible = scrollableRef.current?.childWrapperRef.current.clientHeight > scrollableRef.current?.wrapperRef.current.clientHeight; @@ -113,10 +116,7 @@ export const EntriesList: React.FC = ({entries, setEntries, qu {memoizedEntries.map(entry => )} @@ -131,9 +131,9 @@ export const EntriesList: React.FC = ({entries, setEntries, qu