Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: app info reuse #1734

Merged
merged 1 commit into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/routes/pages/settings/UpdateAppPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { PageContentIonSpinner } from "#/features/user/AsyncProfile";
import { ua } from "#/helpers/device";
import { unloadServiceWorkerAndRefresh } from "#/helpers/serviceWorker";

import AppVersionInfo from "./about/AppVersionInfo";
import { UpdateContext } from "./update/UpdateContext";

const UpToDateText = styled.div`
Expand Down Expand Up @@ -108,7 +109,7 @@ export default function UpdateAppPage() {
<IonItem>
<IonLabel>Current version</IonLabel>
<IonLabel slot="end" color="medium">
{import.meta.env.APP_VERSION}
<AppVersionInfo />
</IonLabel>
</IonItem>
<IonItem
Expand Down
19 changes: 3 additions & 16 deletions src/routes/pages/settings/about/AppDetails.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { IonText } from "@ionic/react";
import { styled } from "@linaria/react";

import AppVersionInfo from "./AppVersionInfo";

const AppContainer = styled.div`
display: flex;
align-items: center;
Expand All @@ -22,26 +23,12 @@ const AppContainer = styled.div`
}
`;

const buildInfo = (() => {
if (import.meta.env.DEV) return <IonText color="danger">Development</IonText>;

// If the app version is different from the git ref (tag), it's a pre-release
if (import.meta.env.APP_GIT_REF !== import.meta.env.APP_VERSION)
return (
<IonText color="warning">
Beta Track — [{import.meta.env.APP_BUILD}]{" "}
{import.meta.env.APP_GIT_REF.slice(0, 7)}
</IonText>
);
})();

export default function AppDetails() {
return (
<AppContainer>
<img src="/logo.png" alt="" />
<div>
Voyager {import.meta.env.APP_VERSION}
{buildInfo && <aside>{buildInfo}</aside>}
Voyager <AppVersionInfo betaPrefix="Beta Track" betaAs="aside" />
<aside>by Alexander Harding</aside>
</div>
</AppContainer>
Expand Down
34 changes: 34 additions & 0 deletions src/routes/pages/settings/about/AppVersionInfo.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { IonText } from "@ionic/react";
import React from "react";

interface AppVersionInfoProps {
betaAs?: React.ElementType;
betaPrefix?: string;
}

export default function AppVersionInfo({
betaAs: BetaEl = React.Fragment,
...props
}: AppVersionInfoProps) {
return (
<>
{import.meta.env.APP_VERSION}{" "}
<BetaEl>
<BetaInfo {...props} />
</BetaEl>
</>
);
}

function BetaInfo({ betaPrefix }: AppVersionInfoProps) {
if (import.meta.env.DEV) return <IonText color="danger">Development</IonText>;

// If the app version is different from the git ref (tag), it's a pre-release
if (import.meta.env.APP_GIT_REF !== import.meta.env.APP_VERSION)
return (
<IonText color="warning">
{betaPrefix && `${betaPrefix} – `}[{import.meta.env.APP_BUILD}]{" "}
{import.meta.env.APP_GIT_REF.slice(0, 7)}
</IonText>
);
}