Skip to content
This repository was archived by the owner on Nov 8, 2022. It is now read-only.

Commit 32c2916

Browse files
authored
refactor(article): remove community in article url (#1042)
* refactor(post-content): js -> ts * refactor(footer): adjust BriefView for article page usage * style(post-content): adjust with * refactor(article-digest): adjust width & tsfy * style(post-content): adjust sticker width * refactor(post-thread): remove community info on jump link * style(footer): adjust metric
1 parent c6e5644 commit 32c2916

File tree

45 files changed

+403
-236
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+403
-236
lines changed

server/routes.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//
1+
/* eslint-disable @typescript-eslint/no-var-requires */
22

33
const router = require('express').Router()
44
const R = require('ramda')
@@ -78,7 +78,7 @@ router.route('/user/:userId').get((req, res) => {
7878
})
7979

8080
// 帖子页
81-
router.route('/:community/post/:id').get((req, res) => {
81+
router.route('/post/:id').get((req, res) => {
8282
return renderAndCache({ req, res, path: '/post' })
8383
})
8484

src/components/Buttons/Button.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ type TProps = {
2424
children?: React.ReactNode
2525
className?: string
2626
ghost?: boolean
27-
type: 'primary' | 'red' | 'ghost'
27+
type?: 'primary' | 'red' | 'ghost'
2828
size?: TSIZE_TSM
2929
onClick?: () => void
3030
loading?: boolean | null

src/components/PostItem/DigestView/DesktopView/Header.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ import {
1717
TagListWrapper,
1818
} from '../../styles/digest_view/header'
1919

20-
const Header = ({ item, community, onUserSelect }) => {
20+
const Header = ({ item, onUserSelect }) => {
2121
return (
2222
<Wrapper>
2323
<Brief>
24-
<Link href={`/${community}/${ROUTE.POST}/${item.id}`} passHref>
24+
<Link href={`/${ROUTE.POST}/${item.id}`} passHref>
2525
<Title>{item.title}</Title>
2626
</Link>
2727
{item.linkAddr && (

src/containers/content/PostContent/DesktopView.js renamed to src/containers/content/PostContent/DesktopView.tsx

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import React, { useRef } from 'react'
88
import { Waypoint } from 'react-waypoint'
99

10-
import { pluggedIn, buildLog, isElementInViewport } from '@/utils'
10+
import { pluggedIn, buildLog } from '@/utils'
1111

1212
import Comments from '@/containers/unit/Comments'
1313
// import ArticleAuthorCard from '@/containers/unit/ArticleAuthorCard'
@@ -17,6 +17,8 @@ import ArticleFooter from '@/containers/unit/ArticleFooter'
1717
import Maybe from '@/components/Maybe'
1818
import MarkDownRender from '@/components/MarkDownRender'
1919

20+
import type { TStore } from './store'
21+
2022
import {
2123
Wrapper,
2224
InnerWrapper,
@@ -26,38 +28,47 @@ import {
2628
CommentsWrapper,
2729
} from './styles/desktop_view'
2830

29-
import { useInit, articleInAnchor, articleOutAnchor } from './logic'
31+
import { useInit, checkAnchor } from './logic'
3032

3133
/* eslint-disable-next-line */
3234
const log = buildLog('C:PostContent')
3335

34-
const checkAnchor = (el) =>
35-
isElementInViewport(el) ? articleInAnchor() : articleOutAnchor()
36+
type TProps = {
37+
postContent?: TStore
38+
testid?: string
39+
metric?: string
40+
}
3641

37-
const PostContentContainer = ({ postContent: store, metric }) => {
42+
const PostContentContainer: React.FC<TProps> = ({
43+
postContent: store,
44+
metric,
45+
testid,
46+
}) => {
3847
useInit(store)
3948

40-
const { viewingData } = store
49+
const { viewingArticle } = store
4150
const ref = useRef()
4251

4352
return (
44-
<Wrapper>
45-
<Maybe test={viewingData.id}>
53+
<Wrapper testid={testid}>
54+
<Maybe test={viewingArticle.id}>
4655
<InnerWrapper>
4756
<Waypoint
4857
onEnter={() => checkAnchor(ref?.current)}
4958
onLeave={() => checkAnchor(ref?.current)}
5059
/>
5160
<MainWrapper metric={metric}>
5261
<ArticleWrapper ref={ref}>
53-
<MarkDownRender body={viewingData.body} />
62+
<MarkDownRender body={viewingArticle.body} />
5463
<ArticleFooter />
5564
</ArticleWrapper>
65+
5666
<Waypoint
5767
onEnter={() => checkAnchor(ref?.current)}
5868
onLeave={() => checkAnchor(ref?.current)}
5969
/>
6070
<CommentsWrapper>
71+
{/* @ts-ignore */}
6172
<Comments ssr />
6273
</CommentsWrapper>
6374
</MainWrapper>
@@ -70,4 +81,4 @@ const PostContentContainer = ({ postContent: store, metric }) => {
7081
)
7182
}
7283

73-
export default pluggedIn(PostContentContainer)
84+
export default pluggedIn(PostContentContainer) as React.FC<TProps>

src/containers/content/PostContent/MobileView.js renamed to src/containers/content/PostContent/MobileView.tsx

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import ArticleFooter from '@/containers/unit/ArticleFooter'
1616
import Maybe from '@/components/Maybe'
1717
import MarkDownRender from '@/components/MarkDownRender'
1818

19+
import type { TStore } from './store'
20+
1921
import {
2022
Wrapper,
2123
InnerWrapper,
@@ -29,21 +31,30 @@ import { useInit, articleInAnchor, articleOutAnchor } from './logic'
2931
/* eslint-disable-next-line */
3032
const log = buildLog('C:PostContent')
3133

32-
const PostContentContainer = ({ postContent: store }) => {
34+
type TProps = {
35+
postContent?: TStore
36+
testid?: string
37+
}
38+
39+
const PostContentContainer: React.FC<TProps> = ({
40+
postContent: store,
41+
testid = 'post-content',
42+
}) => {
3343
useInit(store)
34-
const { viewingData } = store
44+
const { viewingArticle } = store
3545

3646
return (
37-
<Wrapper>
38-
<Maybe test={viewingData.id}>
47+
<Wrapper testid={testid}>
48+
<Maybe test={viewingArticle.id}>
3949
<InnerWrapper>
4050
<MainWrapper>
4151
<ArticleWrapper>
42-
<MarkDownRender body={viewingData.body} />
52+
<MarkDownRender body={viewingArticle.body} />
4353
</ArticleWrapper>
4454
<Waypoint onEnter={articleInAnchor} onLeave={articleOutAnchor} />
4555
<ArticleFooter />
4656
<CommentsWrapper>
57+
{/* @ts-ignore */}
4758
<Comments ssr />
4859
</CommentsWrapper>
4960
</MainWrapper>
@@ -53,4 +64,4 @@ const PostContentContainer = ({ postContent: store }) => {
5364
)
5465
}
5566

56-
export default pluggedIn(PostContentContainer)
67+
export default pluggedIn(PostContentContainer) as React.FC<TProps>

src/containers/content/PostContent/logic.js renamed to src/containers/content/PostContent/logic.ts

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import { useEffect } from 'react'
22

33
import { EVENT, ERR } from '@/constant'
4-
import { asyncSuit, buildLog, errRescue } from '@/utils'
4+
import { asyncSuit, buildLog, errRescue, isElementInViewport } from '@/utils'
55

6+
import type { TStore } from './store'
67
import S from './schema'
78

89
const { SR71, $solver, asyncRes, asyncErr } = asyncSuit
910
const sr71$ = new SR71({
11+
/* @ts-ignore */
1012
receive: [EVENT.REFRESH_POSTS],
1113
})
1214

@@ -16,20 +18,23 @@ let store = null
1618
/* eslint-disable-next-line */
1719
const log = buildLog('L:PostContent')
1820

19-
export const articleInAnchor = () => {
21+
export const checkAnchor = (el: HTMLElement): void =>
22+
isElementInViewport(el) ? articleInAnchor() : articleOutAnchor()
23+
24+
export const articleInAnchor = (): void => {
2025
if (store) store.mark({ articleInViewport: true })
2126
}
2227

23-
export const articleOutAnchor = () => {
28+
export const articleOutAnchor = (): void => {
2429
if (store) store.mark({ articleInViewport: false })
2530
}
2631

27-
const loadPost = () => {
32+
const loadPost = (): void => {
2833
const { id } = store.viewingData
2934
sr71$.query(S.post, { id, userHasLogin: store.isLogin })
3035
}
3136

32-
export const callInformer = () => store.callInformer()
37+
export const callInformer = (): void => store.callInformer()
3338

3439
// ###############################
3540
// Data & Error handlers
@@ -48,7 +53,9 @@ const DataSolver = [
4853
const ErrSolver = [
4954
{
5055
match: asyncErr(ERR.GRAPHQL),
51-
action: () => {},
56+
action: () => {
57+
//
58+
},
5259
},
5360
{
5461
match: asyncErr(ERR.TIMEOUT),
@@ -64,16 +71,16 @@ const ErrSolver = [
6471
// ###############################
6572
// init & uninit
6673
// ###############################
67-
export const useInit = (_store, attachment) => {
74+
export const useInit = (_store: TStore): void => {
6875
useEffect(() => {
6976
store = _store
7077
// log('effect init')
7178

7279
sub$ = sr71$.data().subscribe($solver(DataSolver, ErrSolver))
7380
return () => {
74-
if (!sub$) return false
81+
if (!sub$) return
7582
sr71$.stop()
7683
sub$.unsubscribe()
7784
}
78-
}, [_store, attachment])
85+
}, [_store])
7986
}

src/containers/content/PostContent/store.js

Lines changed: 0 additions & 42 deletions
This file was deleted.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* PostContentStore store
3+
*
4+
*/
5+
6+
import { types as T, getParent, Instance } from 'mobx-state-tree'
7+
8+
import type { TRootStore, TRoute, TArticle } from '@/spec'
9+
import { markStates, buildLog } from '@/utils'
10+
11+
/* eslint-disable-next-line */
12+
const log = buildLog('S:PostContentStore')
13+
14+
const PostContentStore = T.model('PostContentStore', {
15+
articleInViewport: T.optional(T.boolean, true),
16+
})
17+
.views((self) => ({
18+
get curRoute(): TRoute {
19+
const root = getParent(self) as TRootStore
20+
return root.curRoute
21+
},
22+
get isLogin(): boolean {
23+
const root = getParent(self) as TRootStore
24+
return root.account.isLogin
25+
},
26+
get viewingArticle(): TArticle {
27+
const root = getParent(self) as TRootStore
28+
return root.viewingArticle
29+
},
30+
}))
31+
.actions((self) => ({
32+
callInformer(): void {
33+
const root = getParent(self) as TRootStore
34+
root.callInformer()
35+
},
36+
setViewing(sobj: Record<string, unknown>): void {
37+
const root = getParent(self) as TRootStore
38+
root.setViewing(sobj)
39+
},
40+
mark(sobj: Record<string, unknown>): void {
41+
markStates(sobj, self)
42+
},
43+
}))
44+
45+
export type TStore = Instance<typeof PostContentStore>
46+
export default PostContentStore

0 commit comments

Comments
 (0)