Skip to content

Commit

Permalink
feat: settings header icon (#1343)
Browse files Browse the repository at this point in the history
  • Loading branch information
setchy authored Jul 8, 2024
1 parent 5736edd commit 32e22ec
Show file tree
Hide file tree
Showing 13 changed files with 212 additions and 93 deletions.
9 changes: 6 additions & 3 deletions src/components/Header.test.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { MarkGithubIcon } from '@primer/octicons-react';
import { fireEvent, render, screen } from '@testing-library/react';
import { AppContext } from '../context/App';
import { Header } from './Header';
Expand All @@ -16,13 +17,13 @@ describe('components/Header.tsx', () => {
});

it('should render itself & its children', () => {
const tree = render(<Header>Test Header</Header>);
const tree = render(<Header icon={MarkGithubIcon}>Test Header</Header>);

expect(tree).toMatchSnapshot();
});

it('should navigate back', () => {
render(<Header>Test Header</Header>);
render(<Header icon={MarkGithubIcon}>Test Header</Header>);

fireEvent.click(screen.getByLabelText('Go Back'));

Expand All @@ -36,7 +37,9 @@ describe('components/Header.tsx', () => {
fetchNotifications,
}}
>
<Header fetchOnBack={true}>Test Header</Header>
<Header fetchOnBack={true} icon={MarkGithubIcon}>
Test Header
</Header>
</AppContext.Provider>,
);

Expand Down
19 changes: 10 additions & 9 deletions src/components/Header.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import { ArrowLeftIcon } from '@primer/octicons-react';
import { type FC, type ReactNode, useContext } from 'react';
import { ArrowLeftIcon, type Icon } from '@primer/octicons-react';
import { type FC, useContext } from 'react';
import { useNavigate } from 'react-router-dom';
import { AppContext } from '../context/App';
import { Size } from '../types';
import { Legend } from './settings/Legend';

interface IHeader {
children: ReactNode;
icon: Icon;
children: string;
fetchOnBack?: boolean;
}

export const Header: FC<IHeader> = ({
children,
fetchOnBack = false,
}: IHeader) => {
export const Header: FC<IHeader> = (props: IHeader) => {
const navigate = useNavigate();

const { fetchNotifications } = useContext(AppContext);
Expand All @@ -25,7 +24,7 @@ export const Header: FC<IHeader> = ({
title="Go Back"
onClick={() => {
navigate(-1);
if (fetchOnBack) {
if (props.fetchOnBack) {
fetchNotifications();
}
}}
Expand All @@ -37,7 +36,9 @@ export const Header: FC<IHeader> = ({
/>
</button>

<h3 className="text-lg font-semibold">{children}</h3>
<h3 className="text-lg font-semibold flex items-center">
<Legend icon={props.icon}>{props.children}</Legend>
</h3>
</div>
);
};
46 changes: 42 additions & 4 deletions src/components/__snapshots__/Header.test.tsx.snap

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

2 changes: 1 addition & 1 deletion src/routes/Accounts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const AccountsRoute: FC = () => {

return (
<div className="flex h-screen flex-col" data-testid="accounts">
<Header>Accounts</Header>
<Header icon={PersonIcon}>Accounts</Header>
<div className="flex-grow overflow-x-auto px-8">
<div className="mt-4 flex flex-col text-sm">
{auth.accounts.map((account) => (
Expand Down
5 changes: 4 additions & 1 deletion src/routes/Filters.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
FeedPersonIcon,
FilterIcon,
FilterRemoveIcon,
NoteIcon,
} from '@primer/octicons-react';
Expand Down Expand Up @@ -34,7 +35,9 @@ export const FiltersRoute: FC = () => {

return (
<div className="flex h-screen flex-col" data-testid="filters">
<Header fetchOnBack={true}>Filters</Header>
<Header fetchOnBack={true} icon={FilterIcon}>
Filters
</Header>
<div className="flex-grow overflow-x-auto px-8">
<fieldset className="mb-3">
<Legend icon={FeedPersonIcon}>Users</Legend>
Expand Down
5 changes: 1 addition & 4 deletions src/routes/LoginWithOAuthApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,7 @@ export const LoginWithOAuthApp: FC = () => {

return (
<div>
<Header>
<PersonIcon size={Size.XLARGE} className="mr-2" />
Login with OAuth App
</Header>
<Header icon={PersonIcon}>Login with OAuth App</Header>
<div className="px-8">
<Form
initialValues={{
Expand Down
5 changes: 1 addition & 4 deletions src/routes/LoginWithPersonalAccessToken.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,7 @@ export const LoginWithPersonalAccessToken: FC = () => {

return (
<>
<Header>
<KeyIcon size={Size.LARGE} className="mr-2" />
Login with Personal Access Token
</Header>
<Header icon={KeyIcon}>Login with Personal Access Token</Header>

<div className="px-8">
<Form
Expand Down
5 changes: 4 additions & 1 deletion src/routes/Settings.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { GearIcon } from '@primer/octicons-react';
import { type FC, useContext } from 'react';
import { Header } from '../components/Header';
import { AppearanceSettings } from '../components/settings/AppearanceSettings';
Expand All @@ -10,7 +11,9 @@ export const SettingsRoute: FC = () => {
const { resetSettings } = useContext(AppContext);
return (
<div className="flex h-screen flex-col" data-testid="settings">
<Header fetchOnBack>Settings</Header>
<Header fetchOnBack icon={GearIcon}>
Settings
</Header>

<div className="flex flex-col flex-grow overflow-x-auto px-8 gap-3">
<AppearanceSettings />
Expand Down
23 changes: 21 additions & 2 deletions src/routes/__snapshots__/Accounts.test.tsx.snap

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

23 changes: 21 additions & 2 deletions src/routes/__snapshots__/Filters.test.tsx.snap

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

70 changes: 40 additions & 30 deletions src/routes/__snapshots__/LoginWithOAuthApp.test.tsx.snap

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

Loading

0 comments on commit 32e22ec

Please sign in to comment.