From 25fcc528eaf154bef3aa6eff3bb842f17fe28163 Mon Sep 17 00:00:00 2001 From: Vendicated Date: Wed, 5 Oct 2022 17:09:37 +0200 Subject: [PATCH] Updater: Inform about more recent commits --- src/components/Updater.tsx | 127 +++++++++++++++++++++++-------------- src/utils/updater.ts | 5 +- 2 files changed, 82 insertions(+), 50 deletions(-) diff --git a/src/components/Updater.tsx b/src/components/Updater.tsx index 7e4b2a77..1ed56d61 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 &&