Skip to content

Commit

Permalink
refactor: app info reuse (#1734)
Browse files Browse the repository at this point in the history
  • Loading branch information
aeharding authored Nov 18, 2024
1 parent 5993a0d commit 813c901
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 17 deletions.
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>
);
}

0 comments on commit 813c901

Please sign in to comment.