diff --git a/src/components/Updater.tsx b/src/components/Updater.tsx index 7e4b2a772..1ed56d61d 100644 --- a/src/components/Updater.tsx +++ b/src/components/Updater.tsx @@ -1,13 +1,12 @@ import gitHash from "git-hash"; -import { changes, checkForUpdates, getRepo, rebuild, update, UpdateLogger, updateError } from '../utils/updater'; +import { changes, checkForUpdates, getRepo, rebuild, update, UpdateLogger, updateError, isOutdated, isNewer } from '../utils/updater'; import { React, Forms, Button, Margins, Alerts, Card, Parser, Toasts } from '../webpack/common'; import { Flex } from "./Flex"; -import { useAwaiter } from '../utils/misc'; +import { classes, useAwaiter } from '../utils/misc'; import { Link } from "./Link"; import ErrorBoundary from "./ErrorBoundary"; import { ErrorCard } from "./ErrorCard"; - function withDispatcher(dispatcher: React.Dispatch>, action: () => any) { return async () => { dispatcher(true); @@ -45,33 +44,38 @@ function withDispatcher(dispatcher: React.Dispatch }; }; -export default ErrorBoundary.wrap(function Updater() { - const [repo, err, repoPending] = useAwaiter(getRepo, "Loading..."); +interface CommonProps { + repo: string; + repoPending: boolean; +} + +function Changes({ updates, repo, repoPending }: CommonProps & { updates: typeof changes; }) { + return ( + + {updates.map(({ hash, author, message }) => ( +
+ + {hash} + + {message} - {author} +
+ ))} +
+ ); +} + +function Updatable(props: CommonProps) { + const [updates, setUpdates] = React.useState(changes); const [isChecking, setIsChecking] = React.useState(false); const [isUpdating, setIsUpdating] = React.useState(false); - const [updates, setUpdates] = React.useState(changes); - React.useEffect(() => { - if (err) - UpdateLogger.error("Failed to retrieve repo", err); - }, [err]); - - const isOutdated = updates?.length > 0; + const isOutdated = updates.length > 0; return ( - - Repo - - {repoPending ? repo : err ? "Failed to retrieve - check console" : ( - - {repo.split("/").slice(-2).join("/")} - - )} ({gitHash}) - - - - Updates - + <> {!updates && updateError ? ( <> Failed to check updates. Check the console for more info @@ -79,31 +83,15 @@ export default ErrorBoundary.wrap(function Updater() {

{updateError.stderr || updateError.stdout || "An unknown error occurred"}

- ) : - ( - - {isOutdated ? `There are ${updates.length} Updates` : "Up to Date!"} - - ) - } - - {isOutdated && ( - - {updates.map(({ hash, author, message }) => ( -
- - {hash} - - {message} - {author} -
- ))} -
+ ) : ( + + {isOutdated ? `There are ${updates.length} Updates` : "Up to Date!"} + )} - + {isOutdated && } + + {isOutdated &&