Skip to content
This repository was archived by the owner on Nov 19, 2025. It is now read-only.

Commit cd35831

Browse files
authored
feat: add welcome message for first visit (#40)
1 parent fa3424e commit cd35831

File tree

8 files changed

+96
-6
lines changed

8 files changed

+96
-6
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"dependencies": {
1919
"@fontsource/inter": "^4.5.11",
2020
"@headlessui/react": "^1.6.6",
21+
"@heroicons/react": "^1.0.6",
2122
"@icons-pack/react-simple-icons": "^5.2.0",
2223
"@next/bundle-analyzer": "^12.2.3",
2324
"autoprefixer": "^10.4.8",

src/components/SiteHeader.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import Link from 'next/link'
2+
import * as React from 'react'
23

34
import { HelpCircleIcon } from './HelpCircleIcon'
45
import { KominfodLogo } from './KominfodLogo'
@@ -15,7 +16,7 @@ export function SiteHeader() {
1516
</Link>
1617
<Link href='/about'>
1718
<a>
18-
<span className='sr-only'>Confused on what this is?</span>
19+
<span className='sr-only'>About</span>
1920
<HelpCircleIcon className='h-6 w-6 text-brand-text-grey' aria-hidden />
2021
</a>
2122
</Link>
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import type Fuse from 'fuse.js'
22
import Link from 'next/link'
33
import * as React from 'react'
44

5-
import { useDebounce } from '../hooks/useDebounce'
6-
import type { PSEData } from '../types/PSEData'
5+
import { useDebounce } from '../../hooks/useDebounce'
6+
import type { PSEData } from '../../types/PSEData'
77

88
export const ManualSearchSection = () => {
99
// TODO: This shit's ugly - Research a better way
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import { InformationCircleIcon, XIcon } from '@heroicons/react/solid'
2+
import Link from 'next/link'
3+
import { useRouter } from 'next/router'
4+
import * as React from 'react'
5+
6+
const LOCAL_STORAGE_KEY = 'kominfod-welcome'
7+
const canUseDOM = typeof window !== 'undefined'
8+
const getLocalStorage = (key: string) => canUseDOM && localStorage.getItem(key)
9+
const setLocalStorage = (key: string, value: string) => {
10+
return canUseDOM && localStorage.setItem(key, value)
11+
}
12+
13+
export function WelcomeMessageSection() {
14+
const router = useRouter()
15+
const existingStorage = getLocalStorage(LOCAL_STORAGE_KEY)
16+
const [isOpen, setIsOpen] = React.useState<boolean>(false)
17+
const [hasStorage, setHasStorage] = React.useState<boolean>(
18+
Boolean(existingStorage && existingStorage === '1')
19+
)
20+
21+
const setCloseStateToStorage = () => {
22+
setLocalStorage(LOCAL_STORAGE_KEY, '1')
23+
setHasStorage(true)
24+
}
25+
26+
const handleCloseMessage = React.useCallback(() => {
27+
setIsOpen(false)
28+
setCloseStateToStorage()
29+
}, [])
30+
31+
React.useEffect(() => {
32+
// Only open the dialog when intersecting
33+
// and have not been triggered before
34+
// and doesn't have a local storage "wbw-wm"
35+
if (!hasStorage) {
36+
setIsOpen(true)
37+
}
38+
}, [hasStorage])
39+
40+
React.useEffect(() => {
41+
// Also close dialog when route changes
42+
router.events.on('beforeHistoryChange', handleCloseMessage)
43+
44+
return () => {
45+
router.events.off('beforeHistoryChange', handleCloseMessage)
46+
}
47+
}, [router.events, handleCloseMessage])
48+
49+
if (isOpen) {
50+
return (
51+
<div className='rounded-md bg-brand-light-blue p-4'>
52+
<div className='flex'>
53+
<div className='flex-shrink-0'>
54+
<InformationCircleIcon className='h-5 w-5 text-brand-blue' aria-hidden='true' />
55+
</div>
56+
<div className='ml-3'>
57+
<p className='text-sm text-brand-blue'>
58+
Welcome to Kominfo&apos;d! Confused about what this is?{' '}
59+
<Link href='/about'>
60+
<a className='font-medium text-brand-blue underline'>Click here.</a>
61+
</Link>
62+
</p>
63+
</div>
64+
<div className='ml-auto pl-3'>
65+
<div className='-mx-1.5 -my-1.5'>
66+
<button
67+
type='button'
68+
className='inline-flex rounded-md p-1.5 text-brand-blue focus:outline-none focus:ring-2 focus:ring-brand-blue'
69+
onClick={handleCloseMessage}
70+
>
71+
<span className='sr-only'>Dismiss</span>
72+
<XIcon className='h-5 w-5' aria-hidden='true' />
73+
</button>
74+
</div>
75+
</div>
76+
</div>
77+
</div>
78+
)
79+
}
80+
81+
return null
82+
}

src/modules/home/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './ManualSearchSection'
2+
export * from './WelcomeMessageSection'

src/modules/index.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/pages/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ import { PageContent } from '../components/PageContent'
1010
import { SiteHeader } from '../components/SiteHeader'
1111
import { WebsiteEntry } from '../components/WebsiteEntry'
1212
import { fetchTrustPositif } from '../functions/fetchTrustPositif'
13-
import { ManualSearchSection } from '../modules'
14-
import { ExplanationSection, WhatIsThisSection } from '../modules/about'
13+
import { ManualSearchSection, WelcomeMessageSection } from '../modules/home'
1514
import type { PSEData } from '../types/PSEData'
1615
import { generateBlockList } from './api/fetchBlocked'
1716

@@ -75,6 +74,7 @@ const IndexPage = ({ PSEData: data, blockData, trustPositifData }: IndexPageProp
7574
<PageContent>
7675
<div className='mx-auto w-full max-w-screen-sm'>
7776
<div className='space-y-8'>
77+
<WelcomeMessageSection />
7878
{websiteSections.map((item) => (
7979
<section key={item.title}>
8080
<h2 className='text-2xl font-semibold'>{item.title}</h2>

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@
6868
resolved "https://registry.yarnpkg.com/@headlessui/react/-/react-1.6.6.tgz#3073c066b85535c9d28783da0a4d9288b5354d0c"
6969
integrity sha512-MFJtmj9Xh/hhBMhLccGbBoSk+sk61BlP6sJe4uQcVMtXZhCgGqd2GyIQzzmsdPdTEWGSF434CBi8mnhR6um46Q==
7070

71+
"@heroicons/react@^1.0.6":
72+
version "1.0.6"
73+
resolved "https://registry.yarnpkg.com/@heroicons/react/-/react-1.0.6.tgz#35dd26987228b39ef2316db3b1245c42eb19e324"
74+
integrity sha512-JJCXydOFWMDpCP4q13iEplA503MQO3xLoZiKum+955ZCtHINWnx26CUxVxxFQu/uLb4LW3ge15ZpzIkXKkJ8oQ==
75+
7176
"@humanwhocodes/config-array@^0.5.0":
7277
version "0.5.0"
7378
resolved "https://registry.yarnpkg.com/@humanwhocodes/config-array/-/config-array-0.5.0.tgz#1407967d4c6eecd7388f83acf1eaf4d0c6e58ef9"

0 commit comments

Comments
 (0)