-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #269 from k35o/blog-views
Blogに閲覧数をカウントするような機能を追加する
- Loading branch information
Showing
20 changed files
with
188 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,19 @@ | ||
/** @type {import("eslint").Linter.Config} */ | ||
const config = { | ||
extends: [ | ||
"prettier", | ||
"next/core-web-vitals", | ||
"plugin:storybook/recommended", | ||
"plugin:jsx-a11y/recommended" | ||
'prettier', | ||
'next/core-web-vitals', | ||
'plugin:storybook/recommended', | ||
'plugin:jsx-a11y/recommended', | ||
], | ||
overrides: [ | ||
{ | ||
files: ["*.stories.tsx"], | ||
files: ['*.stories.tsx'], | ||
rules: { | ||
'react-hooks/rules-of-hooks': 'off', | ||
}, | ||
}, | ||
], | ||
} | ||
}; | ||
|
||
module.exports = config; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,6 @@ const config = { | |
tailwindcss: {}, | ||
autoprefixer: {}, | ||
}, | ||
} | ||
}; | ||
|
||
export default config; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './view-counter'; |
20 changes: 20 additions & 0 deletions
20
src/app/blog/_components/view-counter/view-counter.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import type { Meta, StoryObj } from '@storybook/react'; | ||
import { ViewCoounter } from './view-counter'; | ||
import { kv } from '#src/mocks/vercel-kv.mock'; | ||
|
||
const meta: Meta<typeof ViewCoounter> = { | ||
title: 'app/blog/view-counter', | ||
component: ViewCoounter, | ||
beforeEach: () => { | ||
kv.incr.mockResolvedValue(74931); | ||
}, | ||
}; | ||
|
||
export default meta; | ||
type Story = StoryObj<typeof ViewCoounter>; | ||
|
||
export const Primary: Story = { | ||
args: { | ||
slug: 'color-contrast', | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { FC } from 'react'; | ||
import { kv } from '#vercel/kv'; | ||
import { commalize } from '@/utils/number/commalize'; | ||
import { Slug } from '../../_types'; | ||
|
||
export const ViewCoounter: FC<{ slug: Slug }> = async ({ slug }) => { | ||
const views = await kv.incr(`views-${slug}`); | ||
return <span>{commalize(views)}</span>; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export type Slug = 'tanstack-router-introduction' | 'color-contrast'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.