mirror of
https://github.com/cheeaun/phanpy.git
synced 2025-03-21 21:29:20 +01:00
Fix document.title not working properly
This commit is contained in:
parent
80cc387c1c
commit
ae37d58826
4 changed files with 15 additions and 5 deletions
|
@ -17,11 +17,12 @@ const Link = (props) => {
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
let hash = (location.hash || '').replace(/^#/, '').trim();
|
let hash = (location.hash || '').replace(/^#/, '').trim();
|
||||||
if (hash === '') hash = '/';
|
if (hash === '') hash = '/';
|
||||||
const isActive = hash === props.to;
|
const { to, ...restProps } = props;
|
||||||
|
const isActive = hash === to;
|
||||||
return (
|
return (
|
||||||
<a
|
<a
|
||||||
href={`#${props.to}`}
|
href={`#${to}`}
|
||||||
{...props}
|
{...restProps}
|
||||||
class={`${props.class || ''} ${isActive ? 'is-active' : ''}`}
|
class={`${props.class || ''} ${isActive ? 'is-active' : ''}`}
|
||||||
onClick={(e) => {
|
onClick={(e) => {
|
||||||
if (routerLocation) states.prevLocation = routerLocation;
|
if (routerLocation) states.prevLocation = routerLocation;
|
||||||
|
|
|
@ -12,10 +12,12 @@ import states, { saveStatus } from '../utils/states';
|
||||||
import { getCurrentAccountNS } from '../utils/store-utils';
|
import { getCurrentAccountNS } from '../utils/store-utils';
|
||||||
import useDebouncedCallback from '../utils/useDebouncedCallback';
|
import useDebouncedCallback from '../utils/useDebouncedCallback';
|
||||||
import useScroll from '../utils/useScroll';
|
import useScroll from '../utils/useScroll';
|
||||||
|
import useTitle from '../utils/useTitle';
|
||||||
|
|
||||||
const LIMIT = 20;
|
const LIMIT = 20;
|
||||||
|
|
||||||
function Home({ hidden }) {
|
function Home({ hidden }) {
|
||||||
|
useTitle('Home', '/');
|
||||||
const snapStates = useSnapshot(states);
|
const snapStates = useSnapshot(states);
|
||||||
const isHomeLocation = snapStates.currentLocation === '/';
|
const isHomeLocation = snapStates.currentLocation === '/';
|
||||||
const [uiState, setUIState] = useState('default');
|
const [uiState, setUIState] = useState('default');
|
||||||
|
|
|
@ -308,6 +308,7 @@ function StatusPage() {
|
||||||
heroDisplayName && heroContentText
|
heroDisplayName && heroContentText
|
||||||
? `${heroDisplayName}: "${heroContentText}"`
|
? `${heroDisplayName}: "${heroContentText}"`
|
||||||
: 'Status',
|
: 'Status',
|
||||||
|
'/s/:id',
|
||||||
);
|
);
|
||||||
|
|
||||||
const closeLink = useMemo(() => {
|
const closeLink = useMemo(() => {
|
||||||
|
|
|
@ -1,9 +1,15 @@
|
||||||
import { useEffect } from 'preact/hooks';
|
import { useEffect } from 'preact/hooks';
|
||||||
|
import { matchPath } from 'react-router-dom';
|
||||||
|
import { useSnapshot } from 'valtio';
|
||||||
|
|
||||||
|
import states from './states';
|
||||||
|
|
||||||
const { VITE_CLIENT_NAME: CLIENT_NAME } = import.meta.env;
|
const { VITE_CLIENT_NAME: CLIENT_NAME } = import.meta.env;
|
||||||
|
|
||||||
export default function useTitle(title) {
|
export default function useTitle(title, path) {
|
||||||
|
const snapStates = useSnapshot(states);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
if (path && !matchPath(path, snapStates.currentLocation)) return;
|
||||||
document.title = title ? `${title} / ${CLIENT_NAME}` : CLIENT_NAME;
|
document.title = title ? `${title} / ${CLIENT_NAME}` : CLIENT_NAME;
|
||||||
}, [title]);
|
}, [title, snapStates.currentLocation]);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue