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

Commit fff92d8

Browse files
authored
fix(article-list): views auto increase on list (#1261)
* refactor(post): remve auto link fetch on post item * refactor(post): remve auto link fetch on article cards
1 parent 59f647e commit fff92d8

File tree

4 files changed

+25
-21
lines changed

4 files changed

+25
-21
lines changed

src/widgets/ArticleCard/Header.tsx

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { FC, memo } from 'react'
2-
import Link from 'next/link'
1+
import { FC, memo, useCallback } from 'react'
2+
import Router from 'next/router'
33
import { isMobile } from 'react-device-detect'
44

55
import type { TJob, TRadar } from '@/spec'
@@ -21,9 +21,13 @@ import {
2121
} from './styles/header'
2222

2323
const Header: FC<TIndex> = ({ data, thread }) => {
24+
const gotoArticle = useCallback(() => {
25+
Router.push(`/${thread}/${data.id}`)
26+
}, [data.id, thread])
27+
2428
switch (thread) {
2529
case ARTICLE_THREAD.RADAR: {
26-
const { id, title, articleTags, linkAddr } = data as TRadar
30+
const { title, articleTags, linkAddr } = data as TRadar
2731

2832
return (
2933
<Wrapper>
@@ -33,9 +37,7 @@ const Header: FC<TIndex> = ({ data, thread }) => {
3337
<LinkSrc>{linkAddr}</LinkSrc>
3438
</LinkWraper>
3539
<Br top={4} />
36-
<Link href={`/${ARTICLE_THREAD.RADAR}/${id}`} passHref>
37-
<Title>{cutRest(title, 100)}</Title>
38-
</Link>
40+
<Title onClick={gotoArticle}>{cutRest(title, 100)}</Title>
3941
<Br top={6} />
4042
<TagsList
4143
items={articleTags}
@@ -47,7 +49,7 @@ const Header: FC<TIndex> = ({ data, thread }) => {
4749
}
4850

4951
default: {
50-
const { id, title, articleTags, company, companyLink } = data as TJob
52+
const { title, articleTags, company, companyLink } = data as TJob
5153

5254
return (
5355
<Wrapper>
@@ -64,9 +66,7 @@ const Header: FC<TIndex> = ({ data, thread }) => {
6466
</CompanyLink>
6567
</ExtraInfo>
6668
)}
67-
<Link href={`/${ARTICLE_THREAD.JOB}/${id}`} passHref>
68-
<Title>{cutRest(title, 100)}</Title>
69-
</Link>
69+
<Title onClick={gotoArticle}>{cutRest(title, 100)}</Title>
7070
</Wrapper>
7171
)
7272
}

src/widgets/PostItem/DesktopView/Header.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { FC } from 'react'
2-
import Link from 'next/link'
1+
import { FC, useCallback } from 'react'
2+
import Router from 'next/router'
33
import dynamic from 'next/dynamic'
44

55
import type { TPost } from '@/spec'
@@ -32,12 +32,14 @@ type TProps = {
3232
}
3333

3434
const Header: FC<TProps> = ({ item }) => {
35+
const gotoArticle = useCallback(() => {
36+
Router.push(`/${ARTICLE_THREAD.POST}/${item.id}`)
37+
}, [item.id])
38+
3539
return (
3640
<Wrapper>
3741
<Brief>
38-
<Link href={`/${ARTICLE_THREAD.POST}/${item.id}`} passHref>
39-
<Title>{item.title}</Title>
40-
</Link>
42+
<Title onClick={gotoArticle}>{item.title}</Title>
4143
{item.linkAddr && (
4244
<TitleLink>
4345
<LinkIcon />

src/widgets/PostItem/MobileView/Body.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { FC, memo } from 'react'
1+
import { FC, memo, useCallback } from 'react'
2+
import Router from 'next/router'
23

3-
import Link from 'next/link'
44
import type { TPost } from '@/spec'
55
import { parseDomain } from '@/utils/route'
66
import { ARTICLE_THREAD } from '@/constant'
@@ -12,11 +12,13 @@ type TProps = {
1212
}
1313

1414
const Body: FC<TProps> = ({ item }) => {
15+
const gotoArticle = useCallback(() => {
16+
Router.push(`/${ARTICLE_THREAD.POST}/${item.id}`)
17+
}, [item.id])
18+
1519
return (
1620
<Wrapper>
17-
<Link href={`/${ARTICLE_THREAD.POST}/${item.id}`} passHref>
18-
<Title>{item.title}</Title>
19-
</Link>
21+
<Title onClick={gotoArticle}>{item.title}</Title>
2022
{item.linkAddr && (
2123
<TitleLink>
2224
<LinkIcon />

src/widgets/PostItem/styles/desktop_view/header.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export const Brief = styled.div`
1313
margin-left: 10px;
1414
color: ${theme('thread.articleTitle')};
1515
`
16-
export const Title = styled.a`
16+
export const Title = styled.div`
1717
font-size: 15.5px;
1818
color: ${theme('thread.articleTitle')};
1919
text-decoration: none;

0 commit comments

Comments
 (0)