Skip to content

Commit

Permalink
Add logout button
Browse files Browse the repository at this point in the history
  • Loading branch information
duehoa1211 committed Jan 6, 2024
1 parent c7857a3 commit 1e857f5
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
20 changes: 9 additions & 11 deletions src/components/Input/ButtonDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ type Props = {
buttonTypes?: 'primary' | 'secondary' | 'danger';
className?: string;
children: React.ReactNode;
content: React.ReactNode | string;
disabled?: boolean;
loading?: boolean;
loadingSize?: number;
tooltip?: string;
text: string;
};

const buttonTypeClasses = {
Expand All @@ -30,10 +30,10 @@ const ButtonDropdown = (props: Props) => {
buttonTypes,
children,
className,
content,
disabled,
loading,
loadingSize,
text,
tooltip,
} = props;

Expand All @@ -50,37 +50,35 @@ const ButtonDropdown = (props: Props) => {
title={tooltip}
className={cx([
`${className} button rounded font-semibold transition ease-in-out focus:shadow-none focus:outline-none min-w-full`,
`${buttonTypeClasses[buttonTypes ?? 'secondary']} border border-panel-border`,
buttonTypes !== undefined && `${buttonTypeClasses[buttonTypes ?? 'secondary']} border border-panel-border`,
loading && 'cursor-default',
disabled && 'cursor-default opacity-50',
])}
onClick={onClick}
disabled={disabled}
>
{loading && (
<div className="flex justify-center">
<div className="flex items-center justify-center">
<Icon path={mdiLoading} spin size={loadingSize ?? 1} />
</div>
)}

{!loading && (
<div className="flex flex-row justify-between">
<span>{text}</span>
<div className="flex flex-row items-center justify-between">
<span>{content}</span>
<Icon path={mdiChevronDown} size={1} />
</div>
)}
</button>
<div
className={cx([
'flex-col fixed z-10 origin-top-right text-right overflow-hidden',
'flex-col fixed z-10 origin-top-right text-right overflow-hidden justify-center w-full',
open ? 'flex' : 'hidden',
buttonTypes !== undefined && `${buttonTypeClasses[buttonTypes ?? 'secondary']} border border-panel-border`,
buttonTypes !== undefined && `${buttonTypeClasses[buttonTypes]} border border-panel-border`,
])}
style={{ maxWidth: `${bounds.width}px` }}
>
<div className="py-1" role="none">
{children}
</div>
{children}
</div>
</div>
);
Expand Down
10 changes: 10 additions & 0 deletions src/components/Layout/TopNav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
mdiInformationOutline,
mdiLayersTripleOutline,
mdiLoading,
mdiLogout,
mdiServer,
mdiTabletDashboard,
mdiTextBoxOutline,
Expand All @@ -36,6 +37,7 @@ import { useSettingsQuery } from '@/core/react-query/settings/queries';
import { useCurrentUserQuery } from '@/core/react-query/user/queries';
import { useUpdateWebuiMutation } from '@/core/react-query/webui/mutations';
import { useWebuiUpdateCheckQuery } from '@/core/react-query/webui/queries';
import { unsetDetails } from '@/core/slices/apiSession';
import { setQueueModalOpen } from '@/core/slices/mainpage';
import { NetworkAvailability } from '@/core/types/signalr';

Expand Down Expand Up @@ -144,6 +146,11 @@ function TopNav() {
dispatch(setQueueModalOpen(false));
};

const handleLogout = useEventCallback(() => {

Check failure on line 149 in src/components/Layout/TopNav.tsx

View workflow job for this annotation

GitHub Actions / Lint check and build test PR

Cannot find name 'useEventCallback'.
dispatch(unsetDetails());
navigate('/webui/login');
});

const handleWebUiUpdate = () => {
const renderToast = () => (
<div className="flex flex-col gap-y-3">
Expand Down Expand Up @@ -220,6 +227,9 @@ function TopNav() {
>
<Icon path={mdiCogOutline} size={0.8333} />
</NavLink>
<Button onClick={handleLogout} tooltip="Log out">
<Icon path={mdiLogout} size={0.8333} />
</Button>
</div>
</div>
<div className="bg-topnav-background text-topnav-text">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,8 @@ function UnrecognizedTab() {
/>
<TransitionDiv show={selectedRows.length !== 0} className="flex h-[50px] gap-x-3">
<ButtonDropdown
text="Options"
className="px-4 py-2.5"
content="Options"
>
<Button
buttonType="primary"
Expand Down

0 comments on commit 1e857f5

Please sign in to comment.