Skip to content

Commit 139a225

Browse files
authored
Merge pull request #190 from shogo4131/release/v1.4.0
Release/v1.4.0
2 parents 2edd57b + 62c2104 commit 139a225

File tree

26 files changed

+1067
-515
lines changed

26 files changed

+1067
-515
lines changed

LICENSE

Lines changed: 0 additions & 21 deletions
This file was deleted.

package.json

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
{
22
"name": "tech-blog",
3-
"version": "1.3.7",
3+
"version": "1.4.0",
44
"private": true,
5-
"license": "MIT",
65
"scripts": {
76
"dev": "next dev && node createData.js",
87
"build": "next build && node createData.js && next export && next-sitemap --config next-sitemap.config.js",
@@ -36,30 +35,30 @@
3635
},
3736
"devDependencies": {
3837
"@babel/core": "^7.19.3",
39-
"@netlify/plugin-nextjs": "^4.29.1",
40-
"@next/bundle-analyzer": "^13.0.3",
38+
"@netlify/plugin-nextjs": "^4.29.4",
39+
"@next/bundle-analyzer": "^13.1.1",
4140
"@storybook/addon-actions": "^6.5.9",
4241
"@storybook/addon-essentials": "^6.5.12",
43-
"@storybook/addon-interactions": "^6.5.13",
44-
"@storybook/addon-links": "^6.5.12",
42+
"@storybook/addon-interactions": "^6.5.14",
43+
"@storybook/addon-links": "^6.5.15",
4544
"@storybook/builder-webpack5": "^6.5.12",
4645
"@storybook/manager-webpack5": "^6.5.12",
47-
"@storybook/react": "^6.5.13",
46+
"@storybook/react": "^6.5.15",
4847
"@storybook/testing-library": "^0.0.13",
4948
"@testing-library/jest-dom": "^5.16.4",
5049
"@testing-library/react": "^13.4.0",
5150
"@types/cheerio": "^0.22.31",
5251
"@types/highlight.js": "^10.1.0",
53-
"@types/jest": "^29.2.3",
52+
"@types/jest": "^29.2.4",
5453
"@types/node": "^18.11.8",
55-
"@types/react": "18.0.25",
54+
"@types/react": "18.0.26",
5655
"@types/react-dom": "18.0.9",
5756
"@types/react-gtm-module": "^2.0.1",
5857
"@typescript-eslint/eslint-plugin": "^5.43.0",
5958
"@typescript-eslint/parser": "^5.42.1",
6059
"babel-loader": "^9.1.0",
6160
"eslint": "8.28.0",
62-
"eslint-config-next": "13.0.5",
61+
"eslint-config-next": "13.1.1",
6362
"eslint-config-prettier": "^8.5.0",
6463
"eslint-import-resolver-typescript": "^3.5.1",
6564
"eslint-plugin-import": "^2.26.0",
@@ -70,11 +69,11 @@
7069
"husky": "^8.0.2",
7170
"jest": "^29.3.1",
7271
"jest-environment-jsdom": "^29.3.1",
73-
"netlify-cli": "^12.0.9",
72+
"netlify-cli": "^12.5.0",
7473
"next-sitemap": "^3.1.32",
7574
"prettier": "^2.8.0",
7675
"scaffdog": "^2.4.0",
77-
"storybook-addon-next-router": "^4.0.1",
76+
"storybook-addon-next-router": "^4.0.2",
7877
"storybook-css-modules-preset": "^1.1.1",
7978
"stylelint": "^14.13.0",
8079
"stylelint-config-idiomatic-order": "^9.0.0",

src/components/BlogCard/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import type { Blog } from '@/types/api';
66

77
import { Chip } from '@/components/Chip';
88

9-
import { page } from '../../constants/page';
9+
import { pages } from '../../constants/pages';
1010

1111
import styles from './index.module.css';
1212

@@ -15,7 +15,7 @@ type Props = Pick<Blog, 'id' | 'title' | 'thumbnail' | 'tags' | 'createdAt'>;
1515
export const BlogCard: FC<Props> = ({ id, title, thumbnail, tags, createdAt }) => {
1616
return (
1717
<div className={styles.root}>
18-
<Link href={`${page.blog.url}/${id}`}>
18+
<Link href={`${pages.blog.url}/${id}`}>
1919
<img
2020
src={thumbnail.url}
2121
height={600}
@@ -26,7 +26,7 @@ export const BlogCard: FC<Props> = ({ id, title, thumbnail, tags, createdAt }) =
2626
</Link>
2727
<div className={styles.title}>
2828
<h3>
29-
<Link href={`${page.blog.url}/${id}`}>{title}</Link>
29+
<Link href={`${pages.blog.url}/${id}`}>{title}</Link>
3030
</h3>
3131
</div>
3232
<div className={styles.date}>

src/components/Chip/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { clsx } from 'clsx';
66

77
import { Tag } from '@/types/api';
88

9-
import { page } from '../../constants/page';
9+
import { pages } from '../../constants/pages';
1010

1111
import styles from './index.module.css';
1212

@@ -20,7 +20,7 @@ export const Chip: FC<Props> = ({ className, tagClassName, tags }) => {
2020
return (
2121
<div className={clsx(styles.tags, className)}>
2222
{tags.map(({ id, tag }) => (
23-
<Link href={`${page.tags.url}/${id}`} key={id} className={clsx(styles.tag, tagClassName)}>
23+
<Link href={`${pages.tags.url}/${id}`} key={id} className={clsx(styles.tag, tagClassName)}>
2424
<span>{tag}</span>
2525
</Link>
2626
))}

src/components/Footer/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ import { FC } from 'react';
22

33
import Link from 'next/link';
44

5-
import { page, seoContents } from '../../constants';
5+
import { pages, seoContents } from '../../constants';
66

77
import styles from './index.module.css';
88

99
export const Footer: FC = () => {
1010
return (
1111
<footer className={styles.root}>
1212
<div className={styles.linkArea}>
13-
<Link href={page.privacy.url}>免責事項・プライバシーポリシー</Link>
13+
<Link href={pages.privacy.url}>免責事項・プライバシーポリシー</Link>
1414
<div className={styles.divider} />
1515
<a href="https://forms.gle/Dvt3wWcXDzENR97CA" target="_blank" rel="noopener noreferrer">
1616
お問合せ

src/components/Header/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { useRouter } from 'next/router';
55

66
import { clsx } from 'clsx';
77

8-
import { page } from '../../constants/page';
8+
import { pages } from '../../constants/pages';
99
import { useMediaQuery } from '../../hooks/useMediaQuery';
1010

1111
import styles from './index.module.css';
@@ -24,14 +24,14 @@ export const Header: FC = () => {
2424
const { sm } = useMediaQuery();
2525

2626
const headerTitle = (
27-
<Link href={page.top.url} title="Reactおじさんブログ">
27+
<Link href={pages.top.url} title="Reactおじさんブログ">
2828
Reactおじさんブログ
2929
</Link>
3030
);
3131

3232
return (
3333
<header className={clsx(styles.root, { [styles.sm]: sm })}>
34-
{page.top.url === asPath ? <h1>{headerTitle}</h1> : <div>{headerTitle}</div>}
34+
{pages.top.url === asPath ? <h1>{headerTitle}</h1> : <div>{headerTitle}</div>}
3535
<ul className={styles.headerBanner}>
3636
{headerLinks.map(({ title, url, imagePath, alt }) => (
3737
<li key={title}>

src/components/Navigation/index.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,30 @@ import { FC } from 'react';
22

33
import Link from 'next/link';
44

5-
import { page } from '../../constants/page';
5+
import { pages } from '../../constants/pages';
66

77
import styles from './index.module.css';
88

99
const navigationHeaders = [
1010
{
1111
title: 'フロントエンド',
1212
subtitle: 'Frontend',
13-
href: `${page.category.url}/frontend`,
13+
href: `${pages.category.url}/frontend`,
1414
},
1515
// {
1616
// title: 'バックエンド',
1717
// subtitle: 'Backend',
18-
// href: `${page.category.url}/backend`,
18+
// href: `${pages.category.url}/backend`,
1919
// },
2020
{
2121
title: 'その他',
2222
subtitle: 'Others',
23-
href: `${page.category.url}/others`,
23+
href: `${pages.category.url}/others`,
2424
},
2525
{
2626
title: 'サイトマップ',
2727
subtitle: 'Sitemap',
28-
href: `${page.sitemap.url}`,
28+
href: `${pages.sitemap.url}`,
2929
},
3030
] as const;
3131

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,24 @@
11
.root {
22
display: flex;
33
align-items: center;
4-
column-gap: 8px;
5-
font-size: 14px;
6-
}
7-
8-
.arrowIcon {
9-
transform: rotate(180deg);
10-
}
11-
12-
.numButton {
13-
display: flex;
14-
width: 22px;
15-
height: 22px;
16-
align-items: center;
174
justify-content: center;
18-
border-radius: 50%;
5+
margin-top: 40px;
6+
font-size: 1.8rem;
197
}
208

21-
.hiddenButton {
22-
visibility: hidden;
9+
.pageNum {
10+
display: flex;
2311
}
2412

25-
.active {
13+
.num {
14+
padding: 12px 16px;
15+
border-radius: 50%;
16+
margin: 0 4px;
2617
background-color: var(--color-gray-500);
2718
color: var(--color-white);
2819
}
20+
21+
.num:hover {
22+
background-color: var(--color-gray-400);
23+
cursor: pointer;
24+
}
Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,17 @@
1-
import { useState } from 'react';
2-
31
import { ComponentMeta, Story } from '@storybook/react';
42

5-
import { Pagination, Props } from './index';
3+
import { Pagenation, Props } from './index';
64

75
export default {
8-
component: Pagination,
9-
} as ComponentMeta<typeof Pagination>;
6+
component: Pagenation,
7+
} as ComponentMeta<typeof Pagenation>;
108

119
const Template: Story<Props> = (args) => {
12-
const { activePage } = args;
13-
14-
const [page, setPage] = useState<number>(activePage);
15-
const onChange = (p: number) => setPage(p);
16-
17-
return <Pagination {...args} activePage={page} onChange={onChange} />;
10+
return <Pagenation {...args} />;
1811
};
1912

2013
export const Default = Template.bind({});
2114

2215
Default.args = {
23-
activePage: 1,
24-
totalPageSize: 12,
16+
totalCount: 12,
2517
};

src/components/Pagination/index.tsx

Lines changed: 17 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,91 +1,33 @@
1-
import { FC, useMemo } from 'react';
1+
import { FC } from 'react';
2+
3+
import Link from 'next/link';
24

35
import { clsx } from 'clsx';
46

5-
import { range } from '../../utils/range';
7+
import { range } from '@/utils/range';
68

79
import styles from './index.module.css';
810

911
export type Props = {
1012
className?: string;
11-
activePage: number;
12-
totalPageSize: number;
13-
onChange: (page: number) => void;
13+
totalCount: number;
14+
pageUrl: string;
1415
};
1516

16-
const START_PAGE = 1;
17-
const DIFFERENCE = 1;
18-
const DISPLAY_PAGE_SIZE = 5;
19-
const STATIC_POSITION_NUMBER = 5;
20-
21-
export const Pagination: FC<Props> = ({ className, activePage, totalPageSize, onChange }) => {
22-
const min = useMemo(() => {
23-
let minPage: number;
24-
if (activePage < STATIC_POSITION_NUMBER) minPage = START_PAGE;
25-
26-
if (totalPageSize - activePage < DISPLAY_PAGE_SIZE - STATIC_POSITION_NUMBER) {
27-
minPage = totalPageSize - DISPLAY_PAGE_SIZE + 1;
28-
} else {
29-
minPage = activePage - STATIC_POSITION_NUMBER + 1;
30-
}
31-
32-
return Math.max(Math.min(minPage, totalPageSize), START_PAGE);
33-
}, [activePage, totalPageSize]);
34-
35-
const max = useMemo(() => {
36-
return Math.min(min + DISPLAY_PAGE_SIZE - 1, totalPageSize);
37-
}, [min, totalPageSize]);
38-
39-
const displayLength = useMemo(() => max - min + 1, [max, min]);
17+
const PER_PAGE = 9;
4018

19+
export const Pagenation: FC<Props> = ({ className, totalCount, pageUrl }) => {
4120
return (
4221
<div className={clsx(styles.root, className)}>
43-
<div
44-
className={clsx(styles.buttonContainer, {
45-
[styles.hiddenButton]: activePage === START_PAGE,
46-
})}
47-
>
48-
<button
49-
type="button"
50-
className={styles.arrowIcon}
51-
disabled={activePage === START_PAGE}
52-
onClick={() => onChange(START_PAGE)}
53-
>
54-
<img src="/images/arrow-right-double-gray.svg" alt="top" height={22} width={22} />
55-
</button>
56-
<button
57-
type="button"
58-
className={styles.arrowIcon}
59-
onClick={() => onChange(Math.max(activePage - DIFFERENCE, START_PAGE))}
60-
>
61-
<img src="/images/arrow-right-gray.svg" alt="prev" height={20} width={20} />
62-
</button>
63-
</div>
64-
{range(displayLength, min).map((num) => (
65-
<button
66-
type="button"
67-
key={num}
68-
className={clsx(styles.numButton, { [styles.active]: num === activePage })}
69-
onClick={() => onChange(num)}
70-
>
71-
{num}
72-
</button>
73-
))}
74-
<div
75-
className={clsx(styles.buttonContainer, {
76-
[styles.hiddenButton]: activePage === totalPageSize,
77-
})}
78-
>
79-
<button
80-
type="button"
81-
onClick={() => onChange(Math.min(activePage + DIFFERENCE, totalPageSize))}
82-
>
83-
<img src="/images/arrow-right-gray.svg" alt="next" height={20} width={20} />
84-
</button>
85-
<button type="button" onClick={() => onChange(totalPageSize)}>
86-
<img src="/images/arrow-right-double-gray.svg" alt="last" height={20} width={20} />
87-
</button>
88-
</div>
22+
<ul className={styles.pageNum}>
23+
{range(1, Math.ceil(totalCount / PER_PAGE)).map((number) => (
24+
<li key={number}>
25+
<Link href={`${pageUrl}/${number}`} className={styles.num}>
26+
{number}
27+
</Link>
28+
</li>
29+
))}
30+
</ul>
8931
</div>
9032
);
9133
};

0 commit comments

Comments
 (0)