Skip to content
This repository has been archived by the owner on Mar 23, 2022. It is now read-only.

Commit

Permalink
Added admin announcement nav item #343
Browse files Browse the repository at this point in the history
Signed-off-by: RaenonX <[email protected]>
  • Loading branch information
RaenonX committed Jan 23, 2022
1 parent 1ab0009 commit e5466ef
Show file tree
Hide file tree
Showing 13 changed files with 112 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/api-def
6 changes: 6 additions & 0 deletions src/components/nav/const.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ export const navItems: NavItems = [
{type: 'header', text: (t) => t.nav.header.others},
{type: 'path', path: GeneralPath.SPECIAL_THANKS, text: (t) => t.meta.inUse.thanks.title},
{type: 'path', path: GeneralPath.ABOUT, text: (t) => t.meta.inUse.about.title},
{
type: 'path',
path: GeneralPath.ADMIN_ANNOUNCEMENT,
text: (t) => t.meta.inUse.admin.announcement.title,
adminOnly: true,
},
{type: 'divider'},
{type: 'path', path: GeneralPath.USER_SETTINGS, text: (t) => t.meta.inUse.user.settings.title},
{type: 'component', renderComponent: () => <NavLanguageSwitch/>},
Expand Down
12 changes: 10 additions & 2 deletions src/components/nav/elements/path.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,15 @@ import {NavItemPath} from '../type';
type Props = NavItemPath;

export const NavPath = ({
path, pathActiveBasis, href: hrefProps, text, disabled, onClick, pathnameNoLang, activeOverride,
path,
pathActiveBasis,
href: hrefProps,
text,
disabled,
onClick,
pathnameNoLang,
activeOverride,
adminOnly = false,
}: Props) => {
const {t, lang} = useI18n();
const href = !!path ? makeGeneralUrl(path, {lang}) : hrefProps;
Expand All @@ -26,7 +34,7 @@ export const NavPath = ({
);

const props = {
className: `${isActive ? styles.active : ''} ${styles['nav-item']}`,
className: `${isActive ? styles.active : ''} ${adminOnly ? styles['nav-item-admin'] : styles['nav-item']}`,
href,
disabled,
onClick,
Expand Down
22 changes: 21 additions & 1 deletion src/components/nav/main.module.css

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

2 changes: 1 addition & 1 deletion src/components/nav/main.module.css.map

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

29 changes: 27 additions & 2 deletions src/components/nav/main.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ div {
@mixin nav-item() {
border: 1px solid colors.$color-bw-101;
border-radius: 0.3rem;
background-image: var(--bs-gradient);

// !important to override the default style from BS `.navbar-nav .nav-link`
padding: 0.5rem 1rem !important;
Expand All @@ -86,8 +87,6 @@ div {
a.nav-item {
@include nav-item;

background-image: var(--bs-gradient);

&:not([class*="disabled"]) {
color: colors.$color-bw-240;
}
Expand All @@ -111,6 +110,32 @@ div {
}
}

a.nav-item-admin {
@include nav-item;

&:not([class*="disabled"]) {
color: colors.$color-danger;
}

&.active {
$bg-active: colors.$color-danger;

color: colors.$color-bw-255;
border: 1px solid $bg-active;
background-color: $bg-active;
}

&:hover,
&:focus,
&.nav-dropdown-hover {
$bg-hovered: color.change(colors.$color-danger, $lightness: 35%);

color: colors.$color-bw-240;
border: 1px solid $bg-hovered;
background-color: $bg-hovered;
}
}

button {
// For all button component to fill the vertical space
width: 100%;
Expand Down
18 changes: 18 additions & 0 deletions src/components/nav/main.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,24 @@ describe('Navigation bar', () => {
expect(aboutButton).toHaveAttribute('data-test-is-active', 'true');
});

it('does not show admin only path for non-admin', async () => {
renderReact(
() => <NavigationBody/>,
{hasSession: true, user: {isAdmin: false}},
);

expect(screen.queryByText(translationEN.meta.inUse.admin.announcement.title)).not.toBeInTheDocument();
});

it('shows admin only path', async () => {
renderReact(
() => <NavigationBody/>,
{hasSession: true, user: {isAdmin: true}},
);

expect(screen.getByText(translationEN.meta.inUse.admin.announcement.title)).toBeInTheDocument();
});

it('hides the navbar', async () => {
const fnSetCollapse = jest.spyOn(layoutDispatchers, LayoutDispatcherName.CHANGE_COLLAPSE);

Expand Down
7 changes: 6 additions & 1 deletion src/components/nav/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export type NavItemPath = NavItemCommon & {
disabled?: boolean,
onClick?: () => void,
activeOverride?: boolean,
adminOnly?: boolean,
} & ({
path?: GeneralPath,
pathActiveBasis?: PagePath[],
Expand All @@ -38,7 +39,11 @@ export type NavItemDivider = NavItemCommon & {
type: 'divider',
};

export type NavItemDropdownContainable = NavItemHeader | NavItemPath | NavItemText | NavItemDivider;
export type NavItemDropdownContainable =
NavItemHeader |
NavItemPath |
NavItemText |
NavItemDivider;

export type NavItemDropdownTitleProps = {
open: boolean,
Expand Down
6 changes: 6 additions & 0 deletions src/i18n/translations/cht/translation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,12 @@ export const translation: TranslationStruct = {
description: '{{unitName}} 的角色故事全集。',
},
},
admin: {
announcement: {
title: '發送網站公告',
description: '發送網站公告的頁面。',
},
},
user: {
settings: {
title: '使用者設定',
Expand Down
3 changes: 3 additions & 0 deletions src/i18n/translations/definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,9 @@ export type TranslationStruct = {
user: {
settings: PageMetaTranslations,
},
admin: {
announcement: PageMetaTranslations,
},
},
error: {
401: PageMetaTranslations,
Expand Down
6 changes: 6 additions & 0 deletions src/i18n/translations/en/translation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -816,6 +816,12 @@ export const translation: TranslationStruct = {
description: 'All unit stories of {{unitName}}.',
},
},
admin: {
announcement: {
title: 'Website announcement',
description: 'Page to send the website announcement',
},
},
user: {
settings: {
title: 'User settings',
Expand Down
6 changes: 6 additions & 0 deletions src/i18n/translations/jp/translation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,12 @@ export const translation: TranslationStruct = {
description: '全部の{{unitName}}のストーリー。',
},
},
admin: {
announcement: {
title: 'TBA',
description: 'TBA',
},
},
user: {
settings: {
title: 'TBA',
Expand Down
1 change: 1 addition & 0 deletions src/utils/meta/translations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export const metaTransFunctions: {[path in PagePath]: GetTranslationFunction<Pag
[GeneralPath.ENMITY_CALC]: (t) => t.meta.inUse.calc.enmity,
[GeneralPath.GAME_DATAMINE_INDEX]: (t) => t.meta.inUse.gameData.datamine.index,
[GeneralPath.USER_SETTINGS]: (t) => t.meta.inUse.user.settings,
[GeneralPath.ADMIN_ANNOUNCEMENT]: (t) => t.meta.inUse.admin.announcement,
[AuthPath.SIGN_IN]: (t) => t.meta.inUse.auth.signIn,
// Constructing paths
[GeneralPath.SKILL_SUP]: (t) => t.meta.temp.constructing,
Expand Down

0 comments on commit e5466ef

Please sign in to comment.