Skip to content
This repository was archived by the owner on Nov 8, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ module.exports = {
'@/schemas': 'src/schemas',
'@/Img': 'src/components/Img',
'@/SvgIcons': 'src/components/SvgIcons',
'@/icons': 'src/components/Icons',
'@/i18n': 'i18n',
'@/spec': 'src/spec',
},
Expand All @@ -40,6 +41,7 @@ module.exports = {
},
},
rules: {
'@typescript-eslint/no-var-requires': 0,
'@typescript-eslint/ban-ts-comment': 0,
'react/jsx-uses-react': 'off',
'react/react-in-jsx-scope': 'off',
Expand Down
1 change: 1 addition & 0 deletions jsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"@/schemas": ["src/schemas"],
"@/Img": ["src/components/Img"],
"@/SvgIcons/*": ["src/components/SvgIcons/*"],
"@/icons/*": ["src/components/icons/*"],
"@/i18n": ["i18n"]
}
},
Expand Down
3 changes: 0 additions & 3 deletions next.config.docker.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ const nextConfig = {
'process.env.SENTRY_RELEASE': JSON.stringify(buildId),
}),
)
if (!isServer) {
config.resolve.alias['@sentry/node'] = '@sentry/browser'
}

return config
},
Expand Down
50 changes: 9 additions & 41 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ const withBundleAnalyzer = require('@next/bundle-analyzer')({
const offlineConfig = require('./config/next_offline')

// Use the SentryWebpack plugin to upload the source maps during build step
const SentryWebpackPlugin = require('@sentry/webpack-plugin')
// const SentryWebpackPlugin = require('@sentry/webpack-plugin')

const {
NEXT_PUBLIC_SENTRY_DSN: SENTRY_DSN,
SENTRY_ORG,
SENTRY_PROJECT,
SENTRY_AUTH_TOKEN,
NODE_ENV,
} = process.env
// const {
// NEXT_PUBLIC_SENTRY_DSN: SENTRY_DSN,
// SENTRY_ORG,
// SENTRY_PROJECT,
// SENTRY_AUTH_TOKEN,
// NODE_ENV,
// } = process.env

process.env.SENTRY_DSN = SENTRY_DSN
// process.env.SENTRY_DSN = SENTRY_DSN

// next-plugins end

Expand All @@ -34,38 +34,6 @@ const nextConfig = {
new webpack.ContextReplacementPlugin(/moment[/\\]locale$/, /(en)/),
)

// for sentry
config.plugins.push(
new webpack.DefinePlugin({
'process.env.SENTRY_RELEASE': JSON.stringify(buildId),
}),
)
if (!isServer) {
config.resolve.alias['@sentry/node'] = '@sentry/browser'
}

// When all the Sentry configuration env variables are available/configured
// The Sentry webpack plugin gets pushed to the webpack plugins to build
// and upload the source maps to sentry.
// This is an alternative to manually uploading the source maps
// Note: This is disabled in development mode.
if (
SENTRY_DSN &&
SENTRY_ORG &&
SENTRY_PROJECT &&
SENTRY_AUTH_TOKEN &&
NODE_ENV === 'production'
) {
config.plugins.push(
new SentryWebpackPlugin({
include: '.next',
ignore: ['node_modules'],
urlPrefix: '~/_next',
release: buildId,
}),
)
}

return config
},
}
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@
"graphql-voyager": "^1.0.0-rc.31",
"js-cookie": "^2.2.0",
"mastani-codehighlight": "0.0.7",
"mobile-device-detect": "^0.4.3",
"mobx": "6.3.2",
"mobx-react": "7.2.0",
"mobx-react-lite": "3.2.0",
Expand All @@ -95,7 +94,6 @@
"next-compose-plugins": "^2.2.0",
"next-i18next": "4.4.1",
"next-offline": "4.0.6",
"next-seo": "4.4.0",
"nextjs-progressbar": "^0.0.6",
"overlayscrollbars": "1.13.1",
"path-match": "^1.2.4",
Expand All @@ -110,6 +108,7 @@
"react-calendar-heatmap": "1.8.1",
"react-content-loader": "3.4.2",
"react-copy-to-clipboard": "^5.0.3",
"react-device-detect": "^1.17.0",
"react-dom": "17.0.2",
"react-highlight-words": "^0.16.0",
"react-lazy-load-image-component": "1.5.0",
Expand Down
9 changes: 5 additions & 4 deletions server/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-var-requires */
/**
*
* this server is only used for next.js SSR
Expand All @@ -13,8 +14,8 @@ const mobxReact = require('mobx-react')
// inspect graphql model
const { express: voyagerMiddleware } = require('graphql-voyager/middleware')
// i18n setup
const nextI18NextMiddleware = require('next-i18next/middleware').default
const nextI18next = require('../i18n')
// const nextI18NextMiddleware = require('next-i18next/middleware').default
// const nextI18next = require('../i18n')

const app = require('./app')
const { redirectToNakedUrl } = require('./helper')
Expand Down Expand Up @@ -44,8 +45,8 @@ mobxReact.enableStaticRendering(true)
voyagerMiddleware({ endpointUrl: CONFIG.GRAPHQL_ENDPOINT }),
)

await nextI18next.initPromise
server.use(nextI18NextMiddleware(nextI18next))
// await nextI18next.initPromise
// server.use(nextI18NextMiddleware(nextI18next))

// eslint-disable-next-line global-require
server.use('/', require('./routes'))
Expand Down
5 changes: 2 additions & 3 deletions src/components/ArticleBaseStats/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import { FC, memo } from 'react'

import type { TArticle, TContainer } from '@/spec'
import { ICON } from '@/config'
import { buildLog, scrollToComments } from '@/utils'

import { Space } from '@/components/Common'
Expand Down Expand Up @@ -36,11 +35,11 @@ const ArticleBaseStats: FC<TProps> = ({
}) => {
return (
<Wrapper testid={testid}>
<ViewsIcon src={`${ICON}/article/viewed.svg`} />
<ViewsIcon />
<Count>{article.views}</Count>
<Space left={14} />
<CommentWrapper onClick={() => scrollToComments(container)}>
<CommentIcon src={`${ICON}/article/comment.svg`} />
<CommentIcon />
<CommentCount>{article.commentsCount}</CommentCount>
</CommentWrapper>
</Wrapper>
Expand Down
14 changes: 9 additions & 5 deletions src/components/ArticleBaseStats/styles/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,29 @@ import styled from 'styled-components'

import type { TTestable } from '@/spec'

import Img from '@/Img'
import ViewSVGIcon from '@/icons/View'
import CommentSVGIcon from '@/icons/Comment'

import { css, theme } from '@/utils'

export const Wrapper = styled.div.attrs(({ testid }: TTestable) => ({
'data-test-id': testid,
}))<TTestable>`
${css.flex('align-center')};
`
const Icon = styled(Img)`
export const ViewsIcon = styled(ViewSVGIcon)`
fill: ${theme('thread.articleDigest')};
${css.size(14)};
transition: fill 0.25s;
`
export const ViewsIcon = styled(Icon)``

export const CommentWrapper = styled.div`
${css.flex('align-center')};
`
export const CommentIcon = styled(Icon)`
export const CommentIcon = styled(CommentSVGIcon)`
fill: ${theme('thread.articleDigest')};
${css.size(14)};
transition: fill 0.25s;

${CommentWrapper}:hover & {
cursor: pointer;
fill: ${theme('thread.articleTitle')};
Expand Down
9 changes: 5 additions & 4 deletions src/components/ArticlesFilter/DesktopView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import dynamic from 'next/dynamic'

import type { TArticleFilter, TResState } from '@/spec'

import { TYPE } from '@/constant'
import { TYPE, THREAD } from '@/constant'
import { buildLog } from '@/utils'
import { useViewing } from '@/hooks'
// import { useViewing } from '@/hooks'

import FilterButton from './FilterButton'
import SelectedFilters from './SelectedFilters'
Expand Down Expand Up @@ -46,13 +46,14 @@ const ArticlesFilter: FC<TProps> = ({
totalCount = 0,
resState = TYPE.RES_STATE.DONE,
}) => {
const { activeThread } = useViewing()
// NOTE: 这里使用 useViewing 会导致 build-size blow
// const { activeThread } = useViewing()

return (
<Wrapper>
<MainFilterWrapper>
<FilterButton
thread={activeThread}
thread={THREAD.POST}
onSelect={onSelect}
activeFilter={activeFilter}
/>
Expand Down
6 changes: 1 addition & 5 deletions src/components/ArticlesFilter/FilterButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import dynamic from 'next/dynamic'

import type { TThread, TArticleFilter } from '@/spec'
import { ICON_CMD } from '@/config'
import { useAccount } from '@/hooks'

import Tooltip from '@/components/Tooltip'

Expand All @@ -14,7 +13,7 @@ import {
FilterIcon,
} from './styles/filter_button'

const FilterPanel = dynamic(() => import('./FilterPanel/index'), {
const FilterPanel = dynamic(() => import('./FilterPanel'), {
/* eslint-disable react/display-name */
loading: () => <div />,
ssr: false,
Expand All @@ -27,8 +26,6 @@ type TProps = {
}

const FilterButton: FC<TProps> = ({ thread, onSelect, activeFilter }) => {
const { isLogin } = useAccount()

return (
<Wrapper>
<Tooltip
Expand All @@ -40,7 +37,6 @@ const FilterButton: FC<TProps> = ({ thread, onSelect, activeFilter }) => {
<FilterPanel
thread={thread}
onSelect={onSelect}
isLogin={isLogin}
activeFilter={activeFilter}
/>
)
Expand Down
11 changes: 4 additions & 7 deletions src/components/ArticlesFilter/FilterPanel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { FC, memo } from 'react'

import type { TThread, TArticleFilter } from '@/spec'
import { THREAD } from '@/constant'
import { useAccount } from '@/hooks'

import TimeFilter from './TimeFilter'
import SortFilter from './SortFilter'
Expand All @@ -15,15 +16,11 @@ type TProps = {
activeFilter: TArticleFilter
onSelect: (filter: TArticleFilter) => void
thread: TThread
isLogin?: boolean
}

const FilterPanel: FC<TProps> = ({
thread,
activeFilter,
onSelect,
isLogin,
}) => {
const FilterPanel: FC<TProps> = ({ thread, activeFilter, onSelect }) => {
const { isLogin } = useAccount()

switch (thread) {
case THREAD.POST:
return (
Expand Down
4 changes: 1 addition & 3 deletions src/components/ArticlesFilter/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import { Fragment, memo } from 'react'

import { useDevice } from '@/hooks'
import { isMobile } from 'react-device-detect'
import { buildLog } from '@/utils'

import DesktopView from './DesktopView'
Expand All @@ -15,8 +15,6 @@ import DesktopView from './DesktopView'
const log = buildLog('c:ArticlesFilter:index')

const ArticlesFilter = (props) => {
const { isMobile } = useDevice()

return <Fragment>{!isMobile && <DesktopView {...props} />}</Fragment>
}

Expand Down
2 changes: 1 addition & 1 deletion src/components/ArticlesFilter/styles/filter_button.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import styled from 'styled-components'

import { Button } from '@/components/Buttons'
import Button from '@/components/Buttons/Button'
import { theme, css } from '@/utils'
import Img from '@/Img'

Expand Down
Loading