diff --git a/src/global/AppServices.tsx b/src/global/AppServices.tsx index b7518af..d035ed8 100644 --- a/src/global/AppServices.tsx +++ b/src/global/AppServices.tsx @@ -6,7 +6,6 @@ import { SyncWallets } from "@comp/wallets/SyncWallets"; import { ForcedAuth } from "./ForcedAuth"; import { WebsocketService } from "./ws/WebsocketService"; -import { SyncWork } from "./ws/SyncWork"; import { SyncMOTD } from "./ws/SyncMOTD"; import { AppHotkeys } from "./AppHotkeys"; import { StorageBroadcast } from "./StorageBroadcast"; @@ -14,7 +13,6 @@ export function AppServices(): JSX.Element { return <> - diff --git a/src/global/ws/SyncDetailedWork.tsx b/src/global/ws/SyncDetailedWork.tsx new file mode 100644 index 0000000..0fb966a --- /dev/null +++ b/src/global/ws/SyncDetailedWork.tsx @@ -0,0 +1,36 @@ +// Copyright (c) 2020-2021 Drew Lemmy +// This file is part of KristWeb 2 under GPL-3.0. +// Full details: https://github.com/tmpim/KristWeb2/blob/master/LICENSE.txt +import { useEffect } from "react"; + +import { useSelector } from "react-redux"; +import { RootState } from "@store"; +import * as nodeActions from "@actions/NodeActions"; + +import { store } from "@app"; + +import * as api from "@api"; +import { KristWorkDetailed } from "@api/types"; + +import Debug from "debug"; +const debug = Debug("kristweb:sync-work"); + +export async function updateDetailedWork(): Promise { + debug("updating detailed work"); + const data = await api.get("work/detailed"); + + debug("work: %d", data.work); + store.dispatch(nodeActions.setDetailedWork(data)); +} + +/** Sync the detailed work with the Krist node on startup. */ +export function SyncDetailedWork(): JSX.Element | null { + const { lastBlockID } = useSelector((s: RootState) => s.node); + + useEffect(() => { + // TODO: show errors to the user? + updateDetailedWork().catch(console.error); + }, [lastBlockID]); + + return null; +} diff --git a/src/global/ws/SyncWork.tsx b/src/global/ws/SyncWork.tsx deleted file mode 100644 index d56649f..0000000 --- a/src/global/ws/SyncWork.tsx +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright (c) 2020-2021 Drew Lemmy -// This file is part of KristWeb 2 under GPL-3.0. -// Full details: https://github.com/tmpim/KristWeb2/blob/master/LICENSE.txt -import { useEffect } from "react"; - -import { useSelector } from "react-redux"; -import { RootState } from "@store"; -import * as nodeActions from "@actions/NodeActions"; - -import { store } from "@app"; - -import * as api from "@api"; -import { KristWorkDetailed } from "@api/types"; - -import Debug from "debug"; -const debug = Debug("kristweb:sync-work"); - -export async function updateDetailedWork(): Promise { - debug("updating detailed work"); - const data = await api.get("work/detailed"); - - debug("work: %d", data.work); - store.dispatch(nodeActions.setDetailedWork(data)); -} - -/** Sync the work with the Krist node on startup. */ -export function SyncWork(): JSX.Element | null { - const { lastBlockID } = useSelector((s: RootState) => s.node); - - useEffect(() => { - // TODO: show errors to the user? - updateDetailedWork().catch(console.error); - }, [lastBlockID]); - - return null; -} diff --git a/src/pages/dashboard/DashboardPage.tsx b/src/pages/dashboard/DashboardPage.tsx index 3ea2f14..4dbcde2 100644 --- a/src/pages/dashboard/DashboardPage.tsx +++ b/src/pages/dashboard/DashboardPage.tsx @@ -15,10 +15,18 @@ import { MOTDCard } from "./MOTDCard"; import { WhatsNewCard } from "./WhatsNewCard"; +import { SyncDetailedWork } from "@global/ws/SyncDetailedWork"; + import "./DashboardPage.less"; export function DashboardPage(): JSX.Element { return + {/* This was moved away from AppServices to here, as the detailed work + * data was only used for this page (at least right now). This was, the + * work will only be fetched when a block is mined while the Dashboard + * page is actually open and active. */} + +