From 5791626cc5dfb5755f4e568815e4375b0432dca4 Mon Sep 17 00:00:00 2001 From: Vitaly Turovsky Date: Thu, 31 Oct 2024 00:28:54 +0300 Subject: [PATCH] fix: (latest) or (offline) status text was not displayed sometimes after the page load --- src/react/MainMenu.tsx | 25 ++++++++++++++++--------- src/react/MainMenuRenderApp.tsx | 10 ++++++++-- src/utils.ts | 4 ++-- 3 files changed, 26 insertions(+), 13 deletions(-) diff --git a/src/react/MainMenu.tsx b/src/react/MainMenu.tsx index 45bc4296..45196f4c 100644 --- a/src/react/MainMenu.tsx +++ b/src/react/MainMenu.tsx @@ -19,8 +19,10 @@ interface Props { mapsProvider?: string versionStatus?: string versionTitle?: string - onVersionClick?: () => void + onVersionStatusClick?: () => void bottomRightLinks?: string + versionText?: string + onVersionTextClick?: () => void } const httpsRegex = /^https?:\/\// @@ -33,9 +35,11 @@ export default ({ githubAction, linksButton, openFileAction, + versionText, + onVersionTextClick, versionStatus, versionTitle, - onVersionClick, + onVersionStatusClick, bottomRightLinks }: Props) => { if (!bottomRightLinks?.trim()) bottomRightLinks = undefined @@ -109,13 +113,16 @@ export default ({
- - Prismarine Web Client {versionStatus} - +
+ {versionText} + + Prismarine Web Client {versionStatus} + +
{linksParsed?.map(([name, link], i, arr) => { diff --git a/src/react/MainMenuRenderApp.tsx b/src/react/MainMenuRenderApp.tsx index 37c7966b..4fed18d6 100644 --- a/src/react/MainMenuRenderApp.tsx +++ b/src/react/MainMenuRenderApp.tsx @@ -65,8 +65,11 @@ export default () => { setVersionStatus(`(${isLatest ? 'latest' : 'new version available'}${mainMenuState.serviceWorkerLoaded ? ' - Available Offline' : ''})`) } subscribe(mainMenuState, upStatus) + upStatus() setVersionTitle(`Loaded: ${process.env.BUILD_VERSION}. Remote: ${contents}`) - }, () => { }) + }, () => { + setVersionStatus('(offline)') + }) } }, []) @@ -113,10 +116,13 @@ export default () => { mapsProvider={mapsProviderUrl} versionStatus={versionStatus} versionTitle={versionTitle} - onVersionClick={async () => { + onVersionStatusClick={async () => { setVersionStatus('(reloading)') await refreshApp() }} + onVersionTextClick={async () => { + openGithub('/releases') + }} />
} diff --git a/src/utils.ts b/src/utils.ts index f6a6176f..0d0875e9 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -185,8 +185,8 @@ export const reloadChunks = async () => { await worldView.updatePosition(bot.entity.position, true) } -export const openGithub = () => { - window.open(process.env.GITHUB_URL, '_blank') +export const openGithub = (addUrl = '') => { + window.open(`${process.env.GITHUB_URL}${addUrl}`, '_blank') } export const resolveTimeout = async (promise, timeout = 10_000) => {