feat(header): add settings header, add settings view util

This commit is contained in:
plebeius.eth
2023-11-27 12:48:01 +01:00
parent 8b1d9f96ab
commit a3bd954f7f
2 changed files with 12 additions and 2 deletions

View File

@@ -2,7 +2,7 @@ import { useEffect, useState } from 'react';
import { Link, useLocation, useParams } from 'react-router-dom';
import { useTranslation } from 'react-i18next';
import { useSubplebbit } from '@plebbit/plebbit-react-hooks';
import { isAboutView, isHomeView, isPostView, isSubplebbitView, isSubmitView, isSubplebbitSubmitView } from '../../lib/utils/view-utils';
import { isAboutView, isHomeView, isPostView, isSettingsView, isSubplebbitView, isSubmitView, isSubplebbitSubmitView } from '../../lib/utils/view-utils';
import useTheme from '../../hooks/use-theme';
import styles from './header.module.css';
import AccountBar from './account-bar';
@@ -19,13 +19,16 @@ const Header = () => {
const sortLabels = [t('header_hot'), t('header_new'), t('header_active'), t('header_controversial'), t('header_top')];
const subplebbit = useSubplebbit({ subplebbitAddress: params.subplebbitAddress });
const { suggested, title, shortAddress } = subplebbit || {};
const isAbout = isAboutView(location.pathname);
const isHome = isHomeView(location.pathname);
const isPost = isPostView(location.pathname, params);
const isSettings = isSettingsView(location.pathname);
const isSubplebbit = isSubplebbitView(location.pathname, params);
const isSubmit = isSubmitView(location.pathname);
const isSubplebbitSubmit = isSubplebbitSubmitView(location.pathname, params);
const fewTabs = isPost || isSubmit || isSubplebbitSubmit;
const fewTabs = isPost || isSubmit || isSubplebbitSubmit || isSettings;
const logoSrc = isSubplebbit ? suggested?.avatarUrl : '/assets/logo/seedit.png';
const logoIsAvatar = isSubplebbit && suggested?.avatarUrl;
@@ -62,6 +65,7 @@ const Header = () => {
</Link>
</li>
);
let headerTabs;
if (isPost) {
@@ -84,6 +88,8 @@ const Header = () => {
headerTitle = subplebbitTitle;
} else if (isSubmit) {
headerTitle = submitTitle;
} else if (isSettings) {
headerTitle = t('preferences');
}
let aboutLink;

View File

@@ -24,6 +24,10 @@ export const isPostView = (pathname: string, params: ParamsType): boolean => {
return params.subplebbitAddress && params.commentCid ? pathname.startsWith(`/p/${params.subplebbitAddress}/c/${params.commentCid}`) : false;
};
export const isSettingsView = (pathname: string): boolean => {
return pathname === '/settings';
}
export const isSubmitView = (pathname: string): boolean => {
return pathname === '/submit';
};