Skip to content

Commit 008929f

Browse files
committed
feat: add Changelog component and integrate with SupportPage
1 parent 2b22c49 commit 008929f

File tree

7 files changed

+99
-1
lines changed

7 files changed

+99
-1
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import config from '@config/config'
2+
import { useQuery } from '@tanstack/react-query'
3+
4+
const importReadmeFile = async () => {
5+
const response = await fetch(`${config.ROOT_URL}/readme.txt`)
6+
if (!response.ok) {
7+
throw new Error('Failed to fetch the README.txt file')
8+
}
9+
return response.text()
10+
}
11+
12+
export default function useChangelog() {
13+
const { data } = useQuery({
14+
queryFn: importReadmeFile,
15+
queryKey: ['changelog'],
16+
select: res =>
17+
res
18+
.match(/==\s*Changelog\s*==\s*([\S\s]*?)(?=\s*==|$)/g)?.[0]
19+
?.replaceAll('== Changelog ==', '') // Convert changelog heading
20+
?.replaceAll(/^= (.+?) =/gm, '## $1') // Convert version headings
21+
})
22+
23+
return {
24+
changelog: data
25+
}
26+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default } from './ui/Changelog'
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { __ } from '@common/helpers/i18nwrap'
2+
import LucideIcn from '@icons/LucideIcn'
3+
import { Button, Drawer } from 'antd'
4+
import { useToggle } from 'react-use'
5+
import { twMerge } from 'tailwind-merge'
6+
7+
import ChangelogContent from './ChangelogContent'
8+
9+
const drawerClassNames =
10+
'mt-[33px] h-[calc(100vh-40px)] rounded-md border-2 border-[var(--wp-bg-color)] ring-4 ring-[var(--wp-bg-color)] dark:border-[#1f1f1f] dark:bg-slate-950'
11+
const wrapperClassName = 'drawer-decoration mr-1 shadow-none'
12+
13+
export default function Changelog() {
14+
const [isOpen, toggle] = useToggle(false)
15+
16+
const handleClose = () => toggle(false)
17+
18+
return (
19+
<div>
20+
<Button className="mb-12" icon={<LucideIcn name="file-clock" />} onClick={toggle}>
21+
{`Changelog`}
22+
</Button>
23+
24+
<Drawer
25+
className={twMerge([drawerClassNames, 'bg-slate-50'])}
26+
classNames={{ wrapper: wrapperClassName }}
27+
mask={false}
28+
onClose={handleClose}
29+
open={isOpen}
30+
title={__('Changelog')}
31+
width={500}
32+
>
33+
<ChangelogContent />
34+
</Drawer>
35+
</div>
36+
)
37+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import Markdown from 'react-markdown'
2+
3+
import useChangelog from '../data/useChangelog'
4+
import cls from './changelog.module.css'
5+
6+
export default function ChangelogContent() {
7+
const { changelog } = useChangelog()
8+
9+
if (!changelog) return
10+
11+
return (
12+
<div className={cls.changelog}>
13+
<Markdown>{changelog}</Markdown>
14+
</div>
15+
)
16+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
.changelog ul {
2+
list-style-type: disc;
3+
margin-left: 20px;
4+
}
5+
6+
.changelog h2 {
7+
margin-bottom: 15px;
8+
}
9+
10+
.changelog h2:first-child {
11+
margin-bottom: 20px;
12+
font-size: 1.25rem;
13+
}

frontend/components/SupportPage/SupportPage.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { __ } from '@common/helpers/i18nwrap'
22
import { Col, Row, theme, Typography } from 'antd'
33
import { type ReactNode } from 'react'
44

5+
import Changelog from '../Changelog'
56
import FacebookCommunityCard from '../FacebookCommunityCard'
67
import License from '../License.pro'
78
import pluginInfoData from './data/pluginInfoData'
@@ -46,6 +47,8 @@ export default function SupportPage({
4647

4748
{isTelemetryVisible && <Improvement />}
4849

50+
<Changelog />
51+
4952
<SupportLinks pluginSlug={pluginSlug} />
5053
</Col>
5154

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@
5858
"simplebar-react": "^3.2.6",
5959
"tippy.js": "^6.3.7",
6060
"use-immer": "^0.10.0",
61+
"tailwind-merge": "^2.6.0",
62+
"react-markdown": "^9.0.3",
6163
"vite-plugin-mkcert": "^1.17.5"
6264
},
6365
"devDependencies": {
@@ -142,4 +144,4 @@
142144
"vite-tsconfig-paths": "^5.0.1",
143145
"vitest": "^1.6.0"
144146
}
145-
}
147+
}

0 commit comments

Comments
 (0)