Skip to content

Commit 656c340

Browse files
committed
Toggle jump links separately on mobile
Also update styles
1 parent a088948 commit 656c340

File tree

13 files changed

+100
-51
lines changed

13 files changed

+100
-51
lines changed

src/components/App/App.tsx

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@ import {
33
mdiArrowLeft,
44
mdiCheck,
55
mdiCogOutline,
6-
mdiDockLeft,
76
mdiImage,
87
mdiListStatus,
9-
mdiNoteTextOutline,
8+
mdiNoteTextOutline
109
} from '@mdi/js'
1110
import { FC } from 'react'
1211
import { useIsCurrentAppMode } from '../../stores/appMode/appModeHooks'
@@ -52,7 +51,7 @@ export const WebdevHome: FC = () => {
5251
<AppLayout
5352
sidebar={
5453
isCurrentAppMode(AppMode.default, AppMode.customize) &&
55-
toggleJumpLinks.showJumpLinks ? (
54+
toggleJumpLinks.showJumpLinks || toggleJumpLinks.showJumpLinksMobile ? (
5655
<JumpLinks />
5756
) : null
5857
}
@@ -101,12 +100,6 @@ export const WebdevHome: FC = () => {
101100
visible={isCurrentAppMode(AppMode.default)}
102101
/>
103102
<AppMenuDivider />
104-
<AppMenuItem
105-
label="Show group list"
106-
icon={<MdiIcon path={mdiDockLeft} />}
107-
selected={toggleJumpLinks.showJumpLinks}
108-
action={toggleJumpLinks.toggle}
109-
/>
110103
<AppMenuItem
111104
label="Show link info"
112105
icon={<MdiIcon path={mdiNoteTextOutline} />}
Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
import { useCallback } from 'react'
22
import { useAppDispatch, useAppSelector } from '../../stores'
3-
import { setDisplayJumpLinks } from '../../stores/appSettings/appSettingsActions'
3+
import {
4+
setDisplayJumpLinks,
5+
setDisplayJumpLinksMobile,
6+
} from '../../stores/appSettings/appSettingsActions'
47

58
type UseToggleJumpLinksResult = {
69
showJumpLinks: boolean
10+
showJumpLinksMobile: boolean
711
toggle: () => void
12+
toggleMobile: () => void
813
}
914

1015
export function useToggleJumpLinks(): UseToggleJumpLinksResult {
@@ -14,9 +19,17 @@ export function useToggleJumpLinks(): UseToggleJumpLinksResult {
1419
(state) => state.appSettings.showJumpLinks,
1520
)
1621

22+
const showJumpLinksMobile = useAppSelector(
23+
(state) => state.appSettings.showJumpLinksMobile,
24+
)
25+
1726
const toggle = useCallback(() => {
1827
dispatch(setDisplayJumpLinks(!showJumpLinks))
1928
}, [dispatch, showJumpLinks])
2029

21-
return { showJumpLinks, toggle }
30+
const toggleMobile = useCallback(() => {
31+
dispatch(setDisplayJumpLinksMobile(!showJumpLinksMobile))
32+
}, [dispatch, showJumpLinksMobile])
33+
34+
return { showJumpLinks, showJumpLinksMobile, toggle, toggleMobile }
2235
}

src/components/Header/AppAction.tsx

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ export const AppAction: FC<Props> = ({
2121
<div
2222
className={classNames(
2323
'flex items-center',
24-
'px-3 py-1.5',
24+
'p-1.5',
25+
{ 'sm:px-3': label !== undefined },
2526
'rounded-md',
2627
'select-none',
2728
{
@@ -45,13 +46,16 @@ export const AppAction: FC<Props> = ({
4546
onClick={action}
4647
>
4748
<MdiIcon path={icon} />
48-
<div
49-
className={classNames('ml-2 text-sm font-semibold', {
50-
'hidden lg:block': !highlight,
51-
})}
52-
>
53-
{label}
54-
</div>
49+
50+
{label !== undefined ? (
51+
<div
52+
className={classNames('ml-2 text-sm font-semibold', {
53+
'hidden lg:block': !highlight,
54+
})}
55+
>
56+
{label}
57+
</div>
58+
) : null}
5559
</div>
5660
)
5761
}

src/components/Header/AppHeader.tsx

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
import { mdiClose, mdiMenu } from '@mdi/js'
12
import classNames from 'classnames'
23
import { FC, ReactElement } from 'react'
4+
import { useToggleJumpLinks } from '../App/useToggleJumpLinks'
5+
import { AppAction } from './AppAction'
36
import { Logo } from './Logo'
47

58
interface Props {
@@ -8,16 +11,28 @@ interface Props {
811
}
912

1013
export const AppHeader: FC<Props> = ({ centerItems, actions }) => {
14+
const toggleJumpLinks = useToggleJumpLinks()
15+
16+
function handleMenuClick() {
17+
// TODO: if (mobile) { toggleJumpLinks.toggleMobile() } else { toggleJumpLinks.toggle() }
18+
}
19+
1120
return (
1221
<div
1322
className={classNames(
1423
'grid items-center',
1524
'grid-cols-[1fr,auto] grid-rows-[auto,auto] md:grid-cols-[1fr,auto,1fr] md:grid-rows-1',
1625
'px-page',
17-
'bg-white/20 dark:bg-black/20',
26+
'bg-white/30 dark:bg-black/30',
1827
)}
1928
>
20-
<Logo />
29+
<div className="flex items-center gap-x-2">
30+
<AppAction
31+
icon={toggleJumpLinks.showJumpLinksMobile ? mdiClose : mdiMenu}
32+
action={handleMenuClick}
33+
/>
34+
<Logo />
35+
</div>
2136

2237
{centerItems !== null ? (
2338
<div className="col-span-2 row-start-2 flex items-center gap-x-1 justify-self-center py-2 md:col-span-1 md:col-start-2 md:row-start-1">

src/components/Header/Logo.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,13 @@ export const Logo: FC = () => {
55
return (
66
<div
77
className={classNames(
8-
'font-mono text-2xl',
8+
'font-mono text-xl',
99
'text-gray-400 dark:text-gray-200',
1010
'select-none text-nowrap',
1111
)}
1212
>
13-
<span>&lt;</span>
1413
<span className="text-brand-500 dark:text-brand-300">Webdev</span>
1514
<span className="text-brand-800 dark:text-brand-100">Home</span>
16-
<span> /&gt;</span>
1715
</div>
1816
)
1917
}

src/components/JumpLinks/JumpLinks.tsx

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,27 @@
1-
import { mdiChevronDown, mdiChevronUp } from '@mdi/js'
21
import classNames from 'classnames'
3-
import { FC, useState } from 'react'
4-
import { MdiIcon } from '../Icon/MdiIcon'
5-
import { JumpLink } from './JumpLink'
2+
import { FC } from 'react'
63
import { links } from '../../links'
74
import { useAllLinksInGroupAreHidden } from '../../stores/hiddenLinks/hiddenLinksHooks'
5+
import { useToggleJumpLinks } from '../App/useToggleJumpLinks'
6+
import { JumpLink } from './JumpLink'
87

98
export const JumpLinks: FC = () => {
109
const allLinksInGroupAreHidden = useAllLinksInGroupAreHidden()
11-
12-
const [isOpen, setIsOpen] = useState(false)
13-
14-
function handleToggleClick() {
15-
setIsOpen(!isOpen)
16-
}
10+
const toggleJumpLinks = useToggleJumpLinks()
1711

1812
return (
19-
<div className="jump-links px-page w-[300px] py-4">
20-
<div
21-
className="flex cursor-default select-none items-center gap-x-2 dark:text-white md:hidden"
22-
onClick={handleToggleClick}
23-
>
24-
<MdiIcon path={isOpen ? mdiChevronUp : mdiChevronDown}></MdiIcon>
25-
<div>Jump to</div>
26-
</div>
27-
<div
28-
className={classNames('flex flex-col gap-1 md:flex', {
29-
hidden: !isOpen,
30-
block: isOpen,
31-
})}
32-
>
13+
<div
14+
className={classNames(
15+
'fixed top-10 lg:static',
16+
'bg-white dark:bg-black lg:bg-white/20 dark:lg:bg-black/20',
17+
'jump-links px-page w-[300px] py-4',
18+
{
19+
'left-0': toggleJumpLinks.showJumpLinksMobile,
20+
'-left-full': !toggleJumpLinks.showJumpLinksMobile,
21+
},
22+
)}
23+
>
24+
<div className={classNames('flex flex-col gap-1 md:flex')}>
3325
{links.items
3426
.filter((group) => !allLinksInGroupAreHidden(group))
3527
.map((linkGroup, index) => (

src/components/Links/LinkGroup.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export const LinkGroup: FC<Props> = ({ group }) => {
7070
}
7171

7272
return (
73-
<div id={slugify(group.name)} className="scroll-mt-20">
73+
<div id={slugify(group.name)} className="scroll-mt-4">
7474
<div className="mb-2 flex gap-x-1">
7575
<div
7676
className={classNames(

src/stores/appSettings/appSettingsActions.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export const enum SettingsActions {
44
setTheme,
55
setDisplayDescription,
66
setDisplayJumpLinks,
7+
setDisplayJumpLinksMobile,
78
setDisplayBackground,
89
}
910

@@ -22,6 +23,11 @@ type SetDisplayJumpLinksAction = {
2223
payload: boolean
2324
}
2425

26+
type SetDisplayJumpLinksMobileAction = {
27+
type: SettingsActions.setDisplayJumpLinksMobile
28+
payload: boolean
29+
}
30+
2531
type SetDisplayBackgroundAction = {
2632
type: SettingsActions.setDisplayBackground
2733
payload: boolean
@@ -31,6 +37,7 @@ export type AppSettingsActions =
3137
| SetThemeAction
3238
| SetDisplayDescriptionAction
3339
| SetDisplayJumpLinksAction
40+
| SetDisplayJumpLinksMobileAction
3441
| SetDisplayBackgroundAction
3542

3643
export function setTheme(payload: AppTheme): SetThemeAction {
@@ -49,6 +56,12 @@ export function setDisplayJumpLinks(
4956
return { type: SettingsActions.setDisplayJumpLinks, payload }
5057
}
5158

59+
export function setDisplayJumpLinksMobile(
60+
payload: boolean,
61+
): SetDisplayJumpLinksMobileAction {
62+
return { type: SettingsActions.setDisplayJumpLinksMobile, payload }
63+
}
64+
5265
export function setDisplayBackground(
5366
payload: boolean,
5467
): SetDisplayBackgroundAction {

src/stores/appSettings/appSettingsReducer.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@ type AppSettingsState = {
1010
theme: AppTheme
1111
showDescriptions: boolean
1212
showJumpLinks: boolean
13+
showJumpLinksMobile: boolean
1314
showBackground: boolean
1415
}
1516

1617
const initialState: AppSettingsState = {
1718
theme: AppTheme.auto,
1819
showDescriptions: false,
1920
showJumpLinks: true,
21+
showJumpLinksMobile: false,
2022
showBackground: false,
2123
}
2224

@@ -37,6 +39,10 @@ export function appSettings(
3739
return { ...state, showJumpLinks: action.payload }
3840
}
3941

42+
case SettingsActions.setDisplayJumpLinksMobile: {
43+
return { ...state, showJumpLinksMobile: action.payload }
44+
}
45+
4046
case SettingsActions.setDisplayBackground: {
4147
return { ...state, showBackground: action.payload }
4248
}

src/stores/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,10 @@ export const store = createStore(rootReducer, {
2424
theme: loadThemeSetting(),
2525
showDescriptions: loadShowDescriptionsSetting(),
2626
showJumpLinks: loadShowJumpLinksSetting(),
27+
showJumpLinksMobile: false,
2728
showBackground: loadShowBackgroundSetting(),
2829
},
29-
})
30+
}, window.__REDUX_DEVTOOLS_EXTENSION__?.())
3031

3132
persistToLocalStorage(store)
3233

0 commit comments

Comments
 (0)