-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ feat (App Frontend): View Changelog and Version info in the app (#167)
* ✨ feat (App Frontend): View Changelog and Version info in the app branch: main * 🧼 format & lint (App Frontend): branch: view-version
- Loading branch information
Showing
13 changed files
with
367 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
NEXT_PUBLIC_BACKEND_URL=http://localhost:3001 | ||
NEXT_PUBLIC_BACKEND_URL=http://localhost:3001 | ||
NEXT_PUBLIC_VERSION=1.1.10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
import React, { useState, useEffect, use } from "react"; | ||
import { useI18nContext } from "@/i18n/i18n-react"; | ||
import { useBackend } from "@/contexts/backend"; | ||
import { Dialog } from "primereact/dialog"; | ||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; | ||
import { | ||
faCheck, | ||
faCircle, | ||
faCircleNotch, | ||
faConstruction, | ||
faExternalLink, | ||
faPersonDigging, | ||
faStars, | ||
faTag, | ||
} from "@fortawesome/pro-solid-svg-icons"; | ||
import Markdown from "react-markdown"; | ||
import Button from "./button"; | ||
import Link from "next/link"; | ||
import SmallInfoCard from "./small_info_card"; | ||
import { env } from "next-runtime-env"; | ||
|
||
export default function VersionModal({ | ||
visible, | ||
setVisible, | ||
autoOpen, | ||
}: { | ||
visible: boolean; | ||
setVisible: (boolean) => void; | ||
autoOpen?: boolean; | ||
}) { | ||
const { LL, locale } = useI18nContext(); | ||
|
||
// biome-ignore lint/suspicious/noExplicitAny: Type not known, github API response | ||
const [releases, setReleases] = useState<any[]>([]); | ||
const [version, setVersion] = useState<string>("DEV"); | ||
|
||
useEffect(() => { | ||
const v = env("NEXT_PUBLIC_VERSION") || "DEV"; | ||
setVersion(v); | ||
|
||
if ( | ||
localStorage.getItem("munify_version_modal_seen_with_version") !== v && | ||
autoOpen | ||
) { | ||
setVisible(true); | ||
localStorage.setItem("munify_version_modal_seen_with_version", v); | ||
} | ||
|
||
fetch( | ||
"https://api.github.com/repos/deutschemodelunitednations/munify/releases", | ||
) | ||
.then((res) => res.json()) | ||
.then((data) => { | ||
setReleases(data); | ||
}) | ||
.catch((err) => { | ||
console.error(err); | ||
}); | ||
}, []); | ||
|
||
return ( | ||
<> | ||
<Dialog | ||
header={ | ||
<> | ||
<FontAwesomeIcon icon={faStars} className="mr-3 text-orange-400" /> | ||
{LL.version.VERSION_MODAL_TITLE()} | ||
</> | ||
} | ||
visible={visible} | ||
style={{ width: "70vw" }} | ||
onHide={() => setVisible(false)} | ||
dismissableMask | ||
> | ||
<h1 className="text-3xl font-bold text-slate-900 mb-4"> | ||
{LL.version.VERSION()} | ||
</h1> | ||
<div className="text-2xl font-mono font-bold text-white py-4 px-4 rounded-lg bg-primary-500 flex justify-center items-center mb-2"> | ||
<FontAwesomeIcon icon={faTag} className="mr-3" /> | ||
{version} | ||
</div> | ||
{version !== releases[0]?.name ? ( | ||
version === "DEV" ? ( | ||
<SmallInfoCard icon={faConstruction}> | ||
<div className="flex flex-col"> | ||
<h3 className="font-bold"> | ||
{LL.version.DEVELOPMENT_VERSION()} | ||
</h3> | ||
<p>{LL.version.DEVELOPMENT_VERSION_TEXT()}</p> | ||
</div> | ||
</SmallInfoCard> | ||
) : ( | ||
<SmallInfoCard icon={faStars}> | ||
<div className="flex flex-col"> | ||
<h3 className="font-bold"> | ||
{LL.version.NEW_VERSION_AVAILABLE()} | ||
</h3> | ||
<p>{LL.version.NEW_VERSION_AVAILABLE_TEXT()}</p> | ||
</div> | ||
</SmallInfoCard> | ||
) | ||
) : ( | ||
<SmallInfoCard | ||
icon={faCheck} | ||
classNameForContentBox="bg-green-500" | ||
classNameForIconBox="bg-green-500 text-green-500 border-green-500" | ||
> | ||
<div className="flex flex-col"> | ||
<h3 className="font-bold">{LL.version.LATEST_VERSION()}</h3> | ||
<p>{LL.version.LATEST_VERSION_TEXT()}</p> | ||
</div> | ||
</SmallInfoCard> | ||
)} | ||
|
||
<h1 className="text-3xl font-bold text-slate-900 mb-2 mt-10"> | ||
{LL.version.CHANGELOG()} | ||
</h1> | ||
<p className="text-slate-900 mb-4 text-sm"> | ||
{LL.version.CHANGELOG_TEXT()} | ||
</p> | ||
<div className="flex flex-col gap-2"> | ||
{releases.length > 0 ? ( | ||
releases.map((release, i) => { | ||
if (i > 5) return null; | ||
return ( | ||
<div | ||
key={release.id} | ||
className="p-4 bg-primary-950 rounded-lg flex flex-col gap-2 justify-start items-start" | ||
> | ||
<div className="flex gap-2 items-start justify-between w-full mb-2"> | ||
<Link | ||
className="text-2xl font-mono font-bold text-white py-2 px-4 rounded-lg bg-primary-500 flex justify-center items-center" | ||
href={release.html_url} | ||
> | ||
<FontAwesomeIcon icon={faTag} className="mr-3" /> | ||
{release.name} | ||
</Link> | ||
<div className="text-slate-900"> | ||
{new Date(release.published_at).toLocaleString(locale, { | ||
dateStyle: "medium", | ||
timeStyle: "short", | ||
})} | ||
</div> | ||
</div> | ||
<Markdown className="prose prose-sm w-full overflow-x-scroll"> | ||
{release.body} | ||
</Markdown> | ||
</div> | ||
); | ||
}) | ||
) : ( | ||
<FontAwesomeIcon icon={faCircleNotch} spin /> | ||
)} | ||
<Button | ||
label={LL.version.ALL_RELEASES()} | ||
onClick={() => | ||
window.open( | ||
"https://github.com/deutschemodelunitednations/munify/releases", | ||
) | ||
} | ||
faIcon={faExternalLink} | ||
className="mt-4" | ||
/> | ||
</div> | ||
</Dialog> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.