Skip to content

Commit

Permalink
feat: 'new version' popup at workspace selection page after new relea…
Browse files Browse the repository at this point in the history
…se (#372)

Signed-off-by: Johannes Groß <mail@gross-johannes.de>
  • Loading branch information
jo-gross authored Aug 24, 2024
1 parent ebba732 commit 6c47b29
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 1 deletion.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"http-method-enum": "1.0.0",
"jssoup": "0.0.15",
"lodash": "4.17.21",
"marked": "^14.0.0",
"next": "14.2.5",
"next-auth": "4.24.7",
"node-html-parser": "6.1.13",
Expand Down
48 changes: 47 additions & 1 deletion pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { signIn, signOut } from 'next-auth/react';
import { useCallback, useContext, useEffect, useState } from 'react';
import { Workspace } from '@prisma/client';
import { Setting, Workspace } from '@prisma/client';
import { Loading } from '../components/Loading';
import Image from 'next/image';
import { FaArrowRight } from 'react-icons/fa';
Expand All @@ -10,9 +10,13 @@ import { alertService } from '../lib/alertService';
import Head from 'next/head';
import packageInfo from '../package.json';
import { ThemeContext } from '../lib/context/ThemeContextProvider';
import { ModalContext } from '../lib/context/ModalContextProvider';
import { marked } from 'marked';

export default function WorkspacesPage() {
const themeContext = useContext(ThemeContext);
const modalContext = useContext(ModalContext);

const [workspaces, setWorkspaces] = useState<Workspace[]>([]);
const [workspacesLoading, setWorkspacesLoading] = useState(false);

Expand Down Expand Up @@ -87,6 +91,48 @@ export default function WorkspacesPage() {
.finally(() => setJoiningWorkspace(false));
}, [fetchWorkspaces, joinWorkspaceId, userContext.user]);

useEffect(() => {
if (userContext.user && (document.getElementById('changelog-modal')?.innerHTML == '' || !document.getElementById('changelog-modal'))) {
if (userContext.user.settings?.find((userSetting) => userSetting.setting == Setting.lastSeenVersion)?.value != packageInfo.version) {
fetch('https://raw.githubusercontent.com/jo-gross/Cocktail-Manager/main/docs/CHANGELOG.md')
.then((response) => {
if (response.ok) {
return response.text();
}
})
.then((text) => {
if (text) {
return marked(text);
}
})
.then((innerHtml) => {
if (innerHtml) {
innerHtml = innerHtml.replaceAll('<h1', '<div class="text-2xl font-bold" ');
innerHtml = innerHtml.replaceAll('/h1>', '/div>');
innerHtml = innerHtml.replaceAll('<h2', '<div class="text-xl font-bold" ');
innerHtml = innerHtml.replaceAll('/h2>', '/div>');
innerHtml = innerHtml.replaceAll('<h3', '<div class="text-lg font-bold" ');
innerHtml = innerHtml.replaceAll('/h3>', '/div>');
innerHtml = innerHtml.replaceAll('<ul>', '<ul class="list-disc pl-4">');
innerHtml = innerHtml.replaceAll('<a', '<a class="link"');

modalContext.openModal(
<div className={'flex flex-col'}>
<div className={'w-full text-center text-2xl font-bold'}>Neue Version ({packageInfo.version})</div>
<div id={'changelog-modal'}></div>
</div>,
);
if (document.getElementById('changelog-modal')) {
document.getElementById('changelog-modal')!.innerHTML = innerHtml;
}

userContext.updateUserSetting(Setting.lastSeenVersion, packageInfo.version);
}
});
}
}
}, [modalContext, userContext, userContext.user]);

useEffect(() => {
fetchWorkspaces();
}, [fetchWorkspaces]);
Expand Down
10 changes: 10 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterEnum
ALTER TYPE "Setting" ADD VALUE 'lastSeenVersion';
1 change: 1 addition & 0 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ enum Setting {
theme
showStatisticActions
showQueueAsOverlay
lastSeenVersion
}

enum WorkspaceSettingKey {
Expand Down

0 comments on commit 6c47b29

Please sign in to comment.