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: 1 addition & 1 deletion config/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"//--- contact configs ---//": "",
"EMAIL_SUPPORT": "coderplanets@outlook.com",
"// GRAPHQL_ENDPOINT": "https://api.coderplanets.com/graphiql",
"BUILD_VERSION": "v2.1.3",
"BUILD_VERSION": "v2.1.5",
"// 1000 * 60 * 10 = 10 mins": "",
"SSR_CACHE_TIME": 60000
}
Binary file modified deploy/production/web.tar.gz
Binary file not shown.
4 changes: 0 additions & 4 deletions src/containers/content/CommunityContent/ThreadContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@ type TProps = {
}

const ThreadContent: FC<TProps> = ({ thread }) => {
console.log('# thread: ', thread)

switch (thread) {
// case THREAD.REPO:
// return <ReposThread />
case THREAD.KANBAN: {
return <WipThread title="看板" />
}
Expand Down
2 changes: 1 addition & 1 deletion src/containers/content/CommunityContent/logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ const tabOnChange = (activeThread: TThread): void => {
const subPath =
activeThread !== ARTICLE_THREAD.POST ? plural(activeThread) : ''

store.markRoute({ mainPath, subPath })
// store.setViewing({ activeThread })
store.setCurThread(activeThread)
store.markRoute({ mainPath, subPath })
}

// ###############################
Expand Down
2 changes: 1 addition & 1 deletion src/containers/thread/ArticlesThread/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const ArticlesThreadContainer: FC<TProps> = ({ articlesThread: store }) => {
? MobileCardsMainWrapper
: MainWrapper

console.log('# got pagedArticlesData: ', pagedArticlesData)
log('# got pagedArticlesData: ', pagedArticlesData)

return (
<Wrapper>
Expand Down
5 changes: 3 additions & 2 deletions src/containers/thread/ArticlesThread/logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ const DataSolver = [
{
match: asyncRes(EVENT.ARTICLE_THREAD_CHANGE),
action: () => {
log('EVENT.ARTICLE_THREAD_CHANGE')
// 之前如果请求过,那么 GraphQL 会被缓存,不必重复请求
if (store.isEmpty) loadArticles()
},
Expand Down Expand Up @@ -169,9 +168,10 @@ const ErrSolver = [
// ###############################
// init & uninit
// ###############################
export const useInit = (_store: TStore): void =>
export const useInit = (_store: TStore): void => {
useEffect(() => {
store = _store
store.afterInitLoading()
sub$ = sr71$.data().subscribe($solver(DataSolver, ErrSolver))

// if (store.isEmpty) loadArticles()
Expand All @@ -183,3 +183,4 @@ export const useInit = (_store: TStore): void =>
sub$.unsubscribe()
}
}, [_store])
}
20 changes: 16 additions & 4 deletions src/containers/thread/ArticlesThread/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const ArticlesThread = T.model('ArticlesThread', {
filters: T.optional(ArticlesFilter, {}),
resState: T.optional(
T.enumeration('resState', values(TYPE.RES_STATE)),
TYPE.RES_STATE.DONE,
TYPE.RES_STATE.LOADING,
),
})
.views((self) => ({
Expand Down Expand Up @@ -109,9 +109,21 @@ const ArticlesThread = T.model('ArticlesThread', {
},
}))
.actions((self) => ({
afterInitLoading(): void {
const slf = self as TStore
const { totalCount } = slf.pagedArticlesData

console.log('totalCount -> ', totalCount)

if (totalCount === 0) {
self.resState = TYPE.RES_STATE.EMPTY
} else {
self.resState = TYPE.RES_STATE.DONE
}
},
// the args pass to server when load articles
getLoadArgs(page = 1): Record<string, unknown> {
// self.resState = TYPE.RES_STATE.LOADING
self.resState = TYPE.RES_STATE.LOADING

const root = getParent(self) as TRootStore
return root.getPagedArticleArgs(page, self.filtersData)
Expand All @@ -121,9 +133,9 @@ const ArticlesThread = T.model('ArticlesThread', {
const pagedData = values(res)[0] as TPagedArticles

if (pagedData.totalCount === 0) {
// slf.resState = TYPE.RES_STATE.EMPTY
slf.resState = TYPE.RES_STATE.EMPTY
} else {
// slf.resState = TYPE.RES_STATE.DONE
slf.resState = TYPE.RES_STATE.DONE
}

slf.mark(res)
Expand Down
7 changes: 6 additions & 1 deletion src/widgets/PagedArticles/ArticleList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ const ArticleList = (props) => {
return <LavaLampLoading top={20} left={30} />
}

if (resState === TYPE.RES_STATE.EMPTY) {
// 加入 length 的判断是因为 Graphql 客户端如果有缓存的话会导致 RES_STATE 没有更新(因为没有请求)
if (
(resState === TYPE.RES_STATE.EMPTY && entries.length === 0) ||
(resState === TYPE.RES_STATE.DONE && entries.length === 0)
) {
return <EmptyThread thread={thread} />
}

Expand Down Expand Up @@ -59,6 +63,7 @@ const ArticleList = (props) => {

default:
// common post
// return <h3>PostItems</h3>
return (
<Fragment>
{entries.map((entry) => (
Expand Down
5 changes: 2 additions & 3 deletions src/widgets/PagedArticles/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,10 @@ const PagedArticles: FC<TProps> = ({
{...pagi}
onChange={(page) => send(EVENT.REFRESH_ARTICLES, { page })}
margin={{ bottom: '60px', top: '60px' }}
>
{/* <CommunityRecommends /> */}
</Pagi>
/>
</Fragment>
)
}

/* <CommunityRecommends /> */
export default memo(PagedArticles)
19 changes: 16 additions & 3 deletions src/widgets/PostItem/DesktopView/Body.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { FC, Fragment } from 'react'
import dynamic from 'next/dynamic'
import TimeAgo from 'timeago-react'

import Link from 'next/link'
Expand All @@ -9,11 +10,11 @@ import { send, changeToCommunity } from '@/utils/helper'

import { SpaceGrow } from '@/widgets/Common'
import DigestSentence from '@/widgets/DigestSentence'
import CommunityCard from '@/widgets/Cards/CommunityCard'
import UserCard from '@/widgets/Cards/UserCard'
// import CommunityCard from '@/widgets/Cards/CommunityCard'
// import UserCard from '@/widgets/Cards/UserCard'
import Tooltip from '@/widgets/Tooltip'

import ActiveBadge from './ActiveBadge'
// import ActiveBadge from './ActiveBadge'

import {
Wrapper,
Expand All @@ -28,6 +29,18 @@ import {
ViewsIcon,
} from '../styles/desktop_view/body'

const CommunityCard = dynamic(() => import('@/widgets/Cards/CommunityCard'), {
ssr: false,
})

const UserCard = dynamic(() => import('@/widgets/Cards/UserCard'), {
ssr: false,
})

const ActiveBadge = dynamic(() => import('./ActiveBadge'), {
ssr: false,
})

type TProps = {
curCommunity: TCommunity | null
item: TPost
Expand Down
12 changes: 11 additions & 1 deletion src/widgets/PostItem/DesktopView/Header.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { FC } from 'react'
import Link from 'next/link'
import dynamic from 'next/dynamic'

import type { TPost } from '@/spec'
import { ARTICLE_THREAD } from '@/constant'
import { parseDomain } from '@/utils/route'

import AvatarsRow from '@/widgets/AvatarsRow'
import TagsList from '@/widgets/TagsList'
// import TagsList from '@/widgets/TagsList'

import {
Wrapper,
Expand All @@ -18,6 +19,14 @@ import {
Participants,
} from '../styles/desktop_view/header'

// const AvatarsRow = dynamic(() => import('@/widgets/AvatarsRow'), {
// ssr: false,
// })

const TagsList = dynamic(() => import('@/widgets/TagsList'), {
ssr: false,
})

type TProps = {
item: TPost
}
Expand All @@ -35,6 +44,7 @@ const Header: FC<TProps> = ({ item }) => {
<span style={{ marginLeft: 9 }}>{parseDomain(item.linkAddr)}</span>
</TitleLink>
)}

<TagListWrapper>
<TagsList items={item.articleTags} />
</TagListWrapper>
Expand Down
53 changes: 39 additions & 14 deletions src/widgets/PostItem/DesktopView/index.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
import { FC, Fragment, memo } from 'react'
import { FC, Fragment, memo, useEffect, useState } from 'react'
import dynamic from 'next/dynamic'

import type { TCommunity, TPost } from '@/spec'
import { UPVOTE_LAYOUT } from '@/constant'

import { upvoteOnArticleList } from '@/utils/helper'
import TheAvatar from '@/widgets/TheAvatar'
import Upvote from '@/widgets/Upvote'

import { ArticleReadLabel, ArticlePinLabel } from '@/widgets/dynamic'

import Header from './Header'
import Body from './Body'

import { AvatarWrapper, UpvoteWrapper, Main } from '../styles/desktop_view'

let Upvote = null
let ArticleReadLabel = null
let ArticlePinLabel = null

type TProps = {
curCommunity: TCommunity | null
entry: TPost
Expand All @@ -23,21 +25,44 @@ type TProps = {
}

const DigestView: FC<TProps> = ({ curCommunity, entry }) => {
const [loaded, setLoaded] = useState(false)

// 如果同步渲染 Upvote, ArticleReadLabel, ArticlePinLabel 等组件会导致难以忍受的卡顿
// 尤其是在 Tab 切换的时候。手机端因为目前没有这些组件,性能暂无问题。
// 本不应该存在的无聊问题,蛋疼的解决办法,
useEffect(() => {
const cfg = { ssr: false }

Upvote = dynamic(() => import('@/widgets/Upvote'), cfg)
ArticleReadLabel = dynamic(() => import('@/widgets/ArticleReadLabel'), cfg)
ArticlePinLabel = dynamic(() => import('@/widgets/ArticlePinLabel'), cfg)

setTimeout(() => {
setLoaded(true)
}, 200)
}, [])

return (
<Fragment>
<ArticleReadLabel entry={entry} />
<ArticlePinLabel entry={entry} />
{loaded && (
<Fragment>
<ArticleReadLabel entry={entry} />
<ArticlePinLabel entry={entry} />
</Fragment>
)}
<AvatarWrapper>
<TheAvatar user={entry.author} />
<UpvoteWrapper>
<Upvote
type={UPVOTE_LAYOUT.POST_LIST}
count={entry.upvotesCount}
viewerHasUpvoted={entry.viewerHasUpvoted}
onAction={(viewerHasUpvoted) =>
upvoteOnArticleList(entry, viewerHasUpvoted)
}
/>
{loaded && (
<Upvote
type={UPVOTE_LAYOUT.POST_LIST}
count={entry.upvotesCount}
viewerHasUpvoted={entry.viewerHasUpvoted}
onAction={(viewerHasUpvoted) =>
upvoteOnArticleList(entry, viewerHasUpvoted)
}
/>
)}
</UpvoteWrapper>
</AvatarWrapper>
<Main>
Expand Down
16 changes: 10 additions & 6 deletions src/widgets/TheAvatar/PostItemAvatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,14 @@ type TProps = {
}

const PostItemAvatar: FC<TProps> = ({ user, onSelect }) => {
const quoteLogin = 'laury2'
// const quoteLogin = 'laury2'
return (
<Wrapper onClick={() => onSelect(user)}>
{user.login === quoteLogin ? (
<Avatar
src={user.avatar}
fallback={<ImgFallback user={user} size={30} top={-2} left={0} />}
/>
{/* {user.login === quoteLogin ? (
<QuoteAvatar
src={user.avatar}
fallback={
Expand All @@ -34,11 +38,11 @@ const PostItemAvatar: FC<TProps> = ({ user, onSelect }) => {
src={user.avatar}
fallback={<ImgFallback user={user} size={30} top={-2} left={0} />}
/>
)}
{user.login === quoteLogin ? <QuoteShadow /> : <InnerShadow />}
{user.login === quoteLogin && (
)} */}
{/* {user.login === quoteLogin ? <QuoteShadow /> : <InnerShadow />} */}
{/* {user.login === quoteLogin && (
<MaskIcon src={`${ICON}/user/mute-mask.svg`} />
)}
)} */}
</Wrapper>
)
}
Expand Down