From 7f0941524e30aeb61238fbb884a553eacaee0730 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E8=9B=99?= <49180735+littlefrogfromthenorth@users.noreply.github.com> Date: Mon, 5 Sep 2022 09:17:06 +0800 Subject: [PATCH 1/7] 111 --- gatsby-theme-oi-wiki/src/components/Comment/Card/styles.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gatsby-theme-oi-wiki/src/components/Comment/Card/styles.ts b/gatsby-theme-oi-wiki/src/components/Comment/Card/styles.ts index 2683b10d..c643ea65 100644 --- a/gatsby-theme-oi-wiki/src/components/Comment/Card/styles.ts +++ b/gatsby-theme-oi-wiki/src/components/Comment/Card/styles.ts @@ -1,4 +1,4 @@ -import { makeStyles } from '@material-ui/core' +import { makeStyles } from '@material-ui/core' import Red from '@material-ui/core/colors/red' export const useStyles = makeStyles(theme => ({ From 6fb2356fe5f9f14a87bf6bc0a238ab5737662769 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E8=9B=99?= <49180735+littlefrogfromthenorth@users.noreply.github.com> Date: Mon, 5 Sep 2022 10:07:21 +0800 Subject: [PATCH 2/7] Delete gh-pages.yml --- .github/workflows/gh-pages.yml | 54 ---------------------------------- 1 file changed, 54 deletions(-) delete mode 100644 .github/workflows/gh-pages.yml diff --git a/.github/workflows/gh-pages.yml b/.github/workflows/gh-pages.yml deleted file mode 100644 index 3f3c4ace..00000000 --- a/.github/workflows/gh-pages.yml +++ /dev/null @@ -1,54 +0,0 @@ -name: GitHub Pages - -on: - push: - branches: - - master - -jobs: - deploy: - env: - PRODUCTION: true - runs-on: ubuntu-18.04 - steps: - - uses: actions/checkout@v2 - with: - fetch-depth: 0 - - - name: Setup Node - uses: actions/setup-node@v1 - with: - node-version: "14" - - - name: Get node version - id: node-version - run: | - echo "::set-output name=ver::$(node --version)" - - name: Get yarn cache directory path - id: yarn-cache-dir-path - run: echo "::set-output name=dir::$(yarn cache dir)" - - - uses: actions/cache@v2 - id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`) - with: - path: ${{ steps.yarn-cache-dir-path.outputs.dir }} - key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} - - - name: Cache install - uses: actions/cache@v1 - with: - path: ./node_modules - key: ${{ runner.os }}-dep-${{ steps.node-version.outputs.ver }}-${{ hashFiles('**/yarn.lock') }} - - - run: yarn install - - - run: yarn build - - - name: Deploy - uses: peaceiris/actions-gh-pages@v3 - with: - deploy_key: ${{ secrets.ACTIONS_DEPLOY_KEY }} - publish_dir: ./public - force_orphan: true - user_name: "github-actions[bot]" - user_email: "github-actions[bot]@users.noreply.github.com" From daf9afefceead4ddb2558829159d07641a5e14cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E8=9B=99?= <49180735+littlefrogfromthenorth@users.noreply.github.com> Date: Mon, 5 Sep 2022 10:07:44 +0800 Subject: [PATCH 3/7] Create gh-pages.yml --- .github/workflows/gh-pages.yml | 54 ++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 .github/workflows/gh-pages.yml diff --git a/.github/workflows/gh-pages.yml b/.github/workflows/gh-pages.yml new file mode 100644 index 00000000..3f3c4ace --- /dev/null +++ b/.github/workflows/gh-pages.yml @@ -0,0 +1,54 @@ +name: GitHub Pages + +on: + push: + branches: + - master + +jobs: + deploy: + env: + PRODUCTION: true + runs-on: ubuntu-18.04 + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Setup Node + uses: actions/setup-node@v1 + with: + node-version: "14" + + - name: Get node version + id: node-version + run: | + echo "::set-output name=ver::$(node --version)" + - name: Get yarn cache directory path + id: yarn-cache-dir-path + run: echo "::set-output name=dir::$(yarn cache dir)" + + - uses: actions/cache@v2 + id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`) + with: + path: ${{ steps.yarn-cache-dir-path.outputs.dir }} + key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} + + - name: Cache install + uses: actions/cache@v1 + with: + path: ./node_modules + key: ${{ runner.os }}-dep-${{ steps.node-version.outputs.ver }}-${{ hashFiles('**/yarn.lock') }} + + - run: yarn install + + - run: yarn build + + - name: Deploy + uses: peaceiris/actions-gh-pages@v3 + with: + deploy_key: ${{ secrets.ACTIONS_DEPLOY_KEY }} + publish_dir: ./public + force_orphan: true + user_name: "github-actions[bot]" + user_email: "github-actions[bot]@users.noreply.github.com" From 4beb80142d753d07ab335873e9722ca63e14036c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E8=9B=99?= <49180735+littlefrogfromthenorth@users.noreply.github.com> Date: Tue, 6 Sep 2022 10:27:25 +0800 Subject: [PATCH 4/7] Implement giscus --- gatsby-theme-oi-wiki/package.json | 3 +- .../Comment/Card/ReactionButton.tsx | 76 ------- .../src/components/Comment/Card/index.tsx | 121 ---------- .../src/components/Comment/Card/styles.ts | 48 ---- .../src/components/Comment/Comment.tsx | 208 ++---------------- .../src/components/Comment/CommentInput.tsx | 87 -------- .../src/components/Comment/api.ts | 23 -- .../src/components/Comment/index.tsx | 20 +- .../src/components/Comment/inputContext.ts | 9 - .../src/components/Comment/types.ts | 16 -- 10 files changed, 28 insertions(+), 583 deletions(-) delete mode 100644 gatsby-theme-oi-wiki/src/components/Comment/Card/ReactionButton.tsx delete mode 100644 gatsby-theme-oi-wiki/src/components/Comment/Card/index.tsx delete mode 100644 gatsby-theme-oi-wiki/src/components/Comment/Card/styles.ts delete mode 100644 gatsby-theme-oi-wiki/src/components/Comment/CommentInput.tsx delete mode 100644 gatsby-theme-oi-wiki/src/components/Comment/api.ts delete mode 100644 gatsby-theme-oi-wiki/src/components/Comment/inputContext.ts delete mode 100644 gatsby-theme-oi-wiki/src/components/Comment/types.ts diff --git a/gatsby-theme-oi-wiki/package.json b/gatsby-theme-oi-wiki/package.json index f6949ee7..363cd20b 100644 --- a/gatsby-theme-oi-wiki/package.json +++ b/gatsby-theme-oi-wiki/package.json @@ -65,7 +65,8 @@ "simple-git": "^2.41.1", "sitemap-manager": "^2.0.1", "unified": "^10.1.0", - "use-persisted-state": "^0.3.0" + "use-persisted-state": "^0.3.0", + "@giscus/react": "^1.2.0" }, "devDependencies": { "@types/autosuggest-highlight": "^3.1.1", diff --git a/gatsby-theme-oi-wiki/src/components/Comment/Card/ReactionButton.tsx b/gatsby-theme-oi-wiki/src/components/Comment/Card/ReactionButton.tsx deleted file mode 100644 index 61771de6..00000000 --- a/gatsby-theme-oi-wiki/src/components/Comment/Card/ReactionButton.tsx +++ /dev/null @@ -1,76 +0,0 @@ -import { - Avatar, - Button, - CircularProgress, -} from '@material-ui/core' - -import React, { useState } from 'react' -import AvatarGroup from '@material-ui/lab/AvatarGroup' -import clsx from 'clsx' -import { User } from '@mgtd/vssue-api-github-v4/lib/types' -import { useStyles } from './styles' - -import { SvgIconComponent } from '@material-ui/icons' - -const reactionButtonDefaultProps = { - initialCount: 0, - isClicked: false, -} - -type ReactionButtonProps = { - icon: SvgIconComponent - clickedClass: string - disabled: boolean - currentUser: User - addReaction: () => Promise, - removeReaction: () => Promise, - users: User[], -} & Partial - -const ReactionButton: React.FC = (props) => { - const classes = useStyles() - const propsMerged = { ...reactionButtonDefaultProps, ...props } - const [isClicked, setIsClicked] = useState(propsMerged.isClicked) - const [count, setCount] = useState(propsMerged.initialCount) - const [users, setUsers] = useState(propsMerged.users) - const [loading, setLoading] = useState(false) - const clickFunc = async (): Promise => { - if (isClicked) { - setCount(count - 1) - setLoading(true) - await propsMerged.removeReaction() - setLoading(false) - const tmpUsers = users.filter(({ username }) => username !== propsMerged.currentUser.username) - setUsers(tmpUsers) - } else { - setCount(count + 1) - setLoading(true) - await propsMerged.addReaction() - setLoading(false) - const tmpUsers: User[] = [...users, propsMerged.currentUser] - setUsers(tmpUsers) - } - setIsClicked(!isClicked) - } - const SvgTag = props.icon - return ( - - ) -} - -export default ReactionButton diff --git a/gatsby-theme-oi-wiki/src/components/Comment/Card/index.tsx b/gatsby-theme-oi-wiki/src/components/Comment/Card/index.tsx deleted file mode 100644 index 5ca22d2c..00000000 --- a/gatsby-theme-oi-wiki/src/components/Comment/Card/index.tsx +++ /dev/null @@ -1,121 +0,0 @@ -import { - Avatar, - Card, - CardActions, - CardContent, - CardHeader, - CircularProgress, - IconButton, -} from '@material-ui/core' - -import { - Favorite as FavoriteIcon, - ThumbUp as ThumbUpIcon, - ThumbDown as ThumbDownIcon, - Reply as ReplyIcon, - Delete as DeleteIcon, -} from '@material-ui/icons' - -import React, { useState } from 'react' -import { User } from '@mgtd/vssue-api-github-v4/lib/types' -import Time from '../../Time' -import { Reactions } from '../types' -import { useInputContentContext } from '../inputContext' -import { useStyles } from './styles' -import ReactionButton from './ReactionButton' - -interface Props { - disabled: boolean, - currentUser: User, - commentID: string | number, - avatarLink: string, - name: string, - contentHTML: string, - contentRaw: string - time: number | string | Date, - reactions: Reactions, - deleteComment: (commentID: string | number, setLoading: (loading: boolean) => void) => Promise, - addReaction: (commentID: string | number, reaction: 'heart' | 'unlike' | 'like') => Promise, - removeReaction: (commentID: string | number, reaction: 'heart' | 'unlike' | 'like') => Promise -} - -const CommentCard: React.FC = (props) => { - const { name, time, disabled, currentUser, reactions, commentID } = props - const classes = useStyles() - const like = reactions.find(item => item.type === 'like') - const unlike = reactions.find(item => item.type === 'unlike') - const heart = reactions.find(item => item.type === 'heart') - const [deleteLoading, setDeleteLoading] = useState(false) - const { setInputContent } = useInputContentContext() - return ( - - } - title={<> - {props.name} {currentUser.username === props.name && - { props.deleteComment(commentID, setDeleteLoading) } - }> - {deleteLoading - ? - : } - } - { - setInputContent(`> ${props.contentRaw}`) - }}> - - - } - classes={{ root: classes.headerRoot }} - subheader={