mirror of
https://github.com/kremalicious/umami.git
synced 2024-06-28 08:47:50 +02:00
Refactored update notice. Fixes #2124.
This commit is contained in:
parent
ba9ddcac38
commit
f35d0f65dc
|
@ -1,15 +1,19 @@
|
|||
import { useState, useEffect, useCallback } from 'react';
|
||||
import { useEffect, useCallback, useState } from 'react';
|
||||
import { Button, Row, Column } from 'react-basics';
|
||||
import { setItem } from 'next-basics';
|
||||
import useStore, { checkVersion } from 'store/version';
|
||||
import { REPO_URL, VERSION_CHECK } from 'lib/constants';
|
||||
import styles from './UpdateNotice.module.css';
|
||||
import useMessages from 'hooks/useMessages';
|
||||
import { useRouter } from 'next/router';
|
||||
|
||||
export function UpdateNotice() {
|
||||
export function UpdateNotice({ user, config }) {
|
||||
const { formatMessage, labels, messages } = useMessages();
|
||||
const { latest, checked, hasUpdate, releaseUrl } = useStore();
|
||||
const [dismissed, setDismissed] = useState(false);
|
||||
const { pathname } = useRouter();
|
||||
const [dismissed, setDismissed] = useState(checked);
|
||||
const allowUpdate =
|
||||
user?.isAdmin && !config?.updatesDisabled && !pathname.includes('/share/') && !dismissed;
|
||||
|
||||
const updateCheck = useCallback(() => {
|
||||
setItem(VERSION_CHECK, { version: latest, time: Date.now() });
|
||||
|
@ -27,12 +31,12 @@ export function UpdateNotice() {
|
|||
}
|
||||
|
||||
useEffect(() => {
|
||||
if (!checked) {
|
||||
if (allowUpdate) {
|
||||
checkVersion();
|
||||
}
|
||||
}, [checked]);
|
||||
}, [allowUpdate]);
|
||||
|
||||
if (!hasUpdate || dismissed) {
|
||||
if (!allowUpdate || !hasUpdate) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
gap: 20px;
|
||||
margin: 20px auto;
|
||||
justify-self: center;
|
||||
background: #fff;
|
||||
background: var(--base50);
|
||||
padding: 20px;
|
||||
border: 1px solid var(--base300);
|
||||
border-radius: var(--border-radius);
|
||||
|
@ -15,7 +15,8 @@
|
|||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
font-weight: 600;
|
||||
color: var(--font-color100);
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.buttons {
|
||||
|
|
|
@ -11,17 +11,14 @@ import styles from './AppLayout.module.css';
|
|||
export function AppLayout({ title, children }) {
|
||||
const { user } = useRequireLogin();
|
||||
const config = useConfig();
|
||||
const { pathname } = useRouter();
|
||||
|
||||
if (!user || !config) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const allowUpdate = user?.isAdmin && !config?.updatesDisabled && !pathname.includes('/share/');
|
||||
|
||||
return (
|
||||
<div className={styles.layout} data-app-version={CURRENT_VERSION}>
|
||||
{allowUpdate && <UpdateNotice />}
|
||||
<UpdateNotice user={user} config={config} />
|
||||
<Head>
|
||||
<title>{title ? `${title} | umami` : 'umami'}</title>
|
||||
</Head>
|
||||
|
|
|
@ -21,7 +21,7 @@ export function useConfig() {
|
|||
}
|
||||
}, []);
|
||||
|
||||
return config || {};
|
||||
return config;
|
||||
}
|
||||
|
||||
export default useConfig;
|
||||
|
|
Loading…
Reference in New Issue
Block a user