From 45de49c41323b153b0d0d90c3053044a2ea701f3 Mon Sep 17 00:00:00 2001 From: mydearxym Date: Thu, 29 Apr 2021 08:59:23 +0800 Subject: [PATCH 1/3] refactor(psots): remove topic concept --- .../digest/CommunityDigest/logic.js | 2 +- src/containers/editor/PostEditor/logic.js | 2 -- src/containers/editor/PostEditor/schema.ts | 2 -- src/containers/thread/PostsThread/index.js | 2 -- src/containers/thread/PostsThread/logic.js | 7 ----- .../unit/ArticleBodyHeader/logic.js | 13 +++------- .../unit/ArticleBodyHeader/schema.ts | 26 ++++++------------- src/containers/unit/Header/logic.ts | 2 +- src/containers/unit/ModeLine/logic.js | 2 +- src/containers/unit/TagsBar/CardView.js | 14 +++------- .../unit/TagsBar/DesktopView/index.js | 14 +++------- src/containers/unit/TagsBar/logic.js | 15 +++++------ src/containers/unit/TagsBar/schema.ts | 4 +-- src/containers/unit/TagsBar/store.ts | 2 -- src/pages/home/posts.js | 14 ++++------ src/stores/SharedModel/Tag.ts | 6 ----- utils/constant/index.ts | 1 - utils/constant/topic.ts | 9 ------- utils/index.ts | 1 - utils/ssr.js | 9 ------- 20 files changed, 34 insertions(+), 113 deletions(-) delete mode 100755 utils/constant/topic.ts diff --git a/src/containers/digest/CommunityDigest/logic.js b/src/containers/digest/CommunityDigest/logic.js index 5a4c37319..996386b7b 100755 --- a/src/containers/digest/CommunityDigest/logic.js +++ b/src/containers/digest/CommunityDigest/logic.js @@ -38,7 +38,7 @@ export const tabOnChange = (activeThread) => { store.markRoute({ subPath }) store.setViewing({ activeThread }) - send(EVENT.THREAD_CHANGE, { data: { activeThread, topic: subPath } }) + send(EVENT.THREAD_CHANGE, { data: { activeThread } }) } export const onShowEditorList = () => { diff --git a/src/containers/editor/PostEditor/logic.js b/src/containers/editor/PostEditor/logic.js index 954331948..3d3621177 100755 --- a/src/containers/editor/PostEditor/logic.js +++ b/src/containers/editor/PostEditor/logic.js @@ -67,7 +67,6 @@ export const onPublish = () => { if (!store.validator('general')) return false if (!specCheck()) return false - const { subPath: topic } = store.curRoute const { body } = store.editData const { isEdit } = store publishing() @@ -80,7 +79,6 @@ export const onPublish = () => { communityId: store.viewing.community.id, digest, length, - topic, mentionUsers: map((user) => ({ id: user.id }), store.referUsersData), } if (!isEmpty(store.labelsData.tags)) { diff --git a/src/containers/editor/PostEditor/schema.ts b/src/containers/editor/PostEditor/schema.ts index c518cf525..eb44a394f 100755 --- a/src/containers/editor/PostEditor/schema.ts +++ b/src/containers/editor/PostEditor/schema.ts @@ -12,7 +12,6 @@ const createPost = gql` $communityId: ID! $tags: [Ids] $mentionUsers: [Ids] - $topic: String ) { createPost( title: $title @@ -24,7 +23,6 @@ const createPost = gql` communityId: $communityId tags: $tags mentionUsers: $mentionUsers - topic: $topic ) { id title diff --git a/src/containers/thread/PostsThread/index.js b/src/containers/thread/PostsThread/index.js index fa2375bc4..eb801b8c6 100755 --- a/src/containers/thread/PostsThread/index.js +++ b/src/containers/thread/PostsThread/index.js @@ -103,7 +103,6 @@ const PostsThreadContainer = ({ postsThread: store }) => { const { subPath } = curRoute const { totalCount } = pagedPostsData - const topic = subPath return ( @@ -184,7 +183,6 @@ const PostsThreadContainer = ({ postsThread: store }) => { diff --git a/src/containers/thread/PostsThread/logic.js b/src/containers/thread/PostsThread/logic.js index a2a9fe55c..80a7ccbf4 100755 --- a/src/containers/thread/PostsThread/logic.js +++ b/src/containers/thread/PostsThread/logic.js @@ -49,10 +49,6 @@ export const outAnchor = () => { export const loadPosts = (page = 1) => { const { curCommunity } = store - const { subPath: topic } = store.curRoute - - // display same-city list instead - if (curCommunity.raw === ROUTE.HOME && topic === THREAD.CITY) return false const userHasLogin = store.isLogin @@ -67,9 +63,6 @@ export const loadPosts = (page = 1) => { userHasLogin, } - if (curCommunity.raw === ROUTE.HOME) { - args.filter = merge(args.filter, { topic }) - } args.filter = pickBy(notEmpty, args.filter) store.mark({ curView: TYPE.LOADING }) diff --git a/src/containers/unit/ArticleBodyHeader/logic.js b/src/containers/unit/ArticleBodyHeader/logic.js index 3d44c9dbc..c9c4a3b61 100755 --- a/src/containers/unit/ArticleBodyHeader/logic.js +++ b/src/containers/unit/ArticleBodyHeader/logic.js @@ -51,8 +51,7 @@ export const onPin = (thread) => { return sr71$.mutate(S.pinRepo, args) default: { - const { subPath: topic } = store.curRoute - return sr71$.mutate(S.pinPost, merge(args, { topic })) + return sr71$.mutate(S.pinPost, args) } } } @@ -71,24 +70,18 @@ export const onUndoPin = (thread) => { return sr71$.mutate(S.undoPinRepo, args) default: { - const { subPath: topic } = store.curRoute - return sr71$.mutate(S.undoPinPost, merge(args, { topic })) + return sr71$.mutate(S.undoPinPost, args) } } } const getRefinedArgs = (thread) => { - let args = { + const args = { id: store.viewingData.id, communityId: store.curCommunity.id, thread: toUpper(thread), } - if (thread === THREAD.POST) { - const { subPath: topic } = store.curRoute - args = merge(args, { topic }) - } - return args } diff --git a/src/containers/unit/ArticleBodyHeader/schema.ts b/src/containers/unit/ArticleBodyHeader/schema.ts index f8e610bf0..60f0e9631 100755 --- a/src/containers/unit/ArticleBodyHeader/schema.ts +++ b/src/containers/unit/ArticleBodyHeader/schema.ts @@ -3,15 +3,15 @@ import { P } from '@/schemas' // post const pinPost = gql` - mutation($id: ID!, $communityId: ID!, $topic: String) { - pinPost(id: $id, communityId: $communityId, topic: $topic) { + mutation($id: ID!, $communityId: ID!) { + pinPost(id: $id, communityId: $communityId) { id } } ` const undoPinPost = gql` - mutation($id: ID!, $communityId: ID!, $topic: String) { - undoPinPost(id: $id, communityId: $communityId, topic: $topic) { + mutation($id: ID!, $communityId: ID!) { + undoPinPost(id: $id, communityId: $communityId) { id } } @@ -71,26 +71,16 @@ const deleteRepo = gql` // refined tag const setRefinedTag = gql` - mutation($communityId: ID!, $thread: CmsThread, $topic: String, $id: ID!) { - setRefinedTag( - communityId: $communityId - thread: $thread - topic: $topic - id: $id - ) { + mutation($communityId: ID!, $thread: CmsThread, $id: ID!) { + setRefinedTag(communityId: $communityId, thread: $thread, id: $id) { id title } } ` const unsetRefinedTag = gql` - mutation($communityId: ID!, $thread: CmsThread, $topic: String, $id: ID!) { - unsetRefinedTag( - communityId: $communityId - thread: $thread - topic: $topic - id: $id - ) { + mutation($communityId: ID!, $thread: CmsThread, $id: ID!) { + unsetRefinedTag(communityId: $communityId, thread: $thread, id: $id) { id title } diff --git a/src/containers/unit/Header/logic.ts b/src/containers/unit/Header/logic.ts index 10524ba37..08a551256 100755 --- a/src/containers/unit/Header/logic.ts +++ b/src/containers/unit/Header/logic.ts @@ -43,7 +43,7 @@ export const onThreadChange = (activeThread: TThread): void => { store.markRoute({ subPath }) store.setViewing({ activeThread }) - send(EVENT.THREAD_CHANGE, { data: { activeThread, topic: subPath } }) + send(EVENT.THREAD_CHANGE, { data: { activeThread } }) } export const onLogin = (): void => send(EVENT.LOGIN_PANEL) diff --git a/src/containers/unit/ModeLine/logic.js b/src/containers/unit/ModeLine/logic.js index 506953fd0..fbf960258 100755 --- a/src/containers/unit/ModeLine/logic.js +++ b/src/containers/unit/ModeLine/logic.js @@ -25,7 +25,7 @@ export const tabOnChange = (activeThread) => { store.markRoute({ subPath }) store.setViewing({ activeThread }) - send(EVENT.THREAD_CHANGE, { data: { activeThread, topic: subPath } }) + send(EVENT.THREAD_CHANGE, { data: { activeThread } }) } export const openMenu = (activeMenu) => { diff --git a/src/containers/unit/TagsBar/CardView.js b/src/containers/unit/TagsBar/CardView.js index 8254800f0..e165468da 100644 --- a/src/containers/unit/TagsBar/CardView.js +++ b/src/containers/unit/TagsBar/CardView.js @@ -8,7 +8,7 @@ import React from 'react' import T from 'prop-types' import { ICON_CMD } from '@/config' -import { THREAD, TOPIC } from '@/constant' +import { THREAD } from '@/constant' import { buildLog, pluggedIn, sortByColor, Trans } from '@/utils' import { @@ -24,14 +24,8 @@ import { useInit, onTagSelect } from './logic' /* eslint-disable-next-line */ const log = buildLog('C:TagsBar') -const TagsBarContainer = ({ - tagsBar: store, - thread, - topic, - active, - onSelect, -}) => { - useInit(store, thread, topic, active) +const TagsBarContainer = ({ tagsBar: store, thread, active, onSelect }) => { + useInit(store, thread, active) const { tagsData, activeTagData } = store @@ -67,7 +61,6 @@ const TagsBarContainer = ({ TagsBarContainer.propTypes = { tagsBar: T.object.isRequired, thread: T.string, - topic: T.string, onSelect: T.func.isRequired, active: T.shape({ id: T.string, @@ -78,7 +71,6 @@ TagsBarContainer.propTypes = { TagsBarContainer.defaultProps = { thread: THREAD.POST, - topic: TOPIC.POST, active: {}, } diff --git a/src/containers/unit/TagsBar/DesktopView/index.js b/src/containers/unit/TagsBar/DesktopView/index.js index 9834c9f1a..d970ecafa 100644 --- a/src/containers/unit/TagsBar/DesktopView/index.js +++ b/src/containers/unit/TagsBar/DesktopView/index.js @@ -8,7 +8,7 @@ import React from 'react' import T from 'prop-types' import { keys } from 'ramda' -import { THREAD, TOPIC } from '@/constant' +import { THREAD } from '@/constant' import { buildLog, pluggedIn } from '@/utils' import GobackTag from './GobackTag' @@ -21,14 +21,8 @@ import { useInit, onTagSelect } from '../logic' /* eslint-disable-next-line */ const log = buildLog('C:TagsBar') -const TagsBarContainer = ({ - tagsBar: store, - thread, - topic, - active, - onSelect, -}) => { - useInit(store, thread, topic, active) +const TagsBarContainer = ({ tagsBar: store, thread, active, onSelect }) => { + useInit(store, thread, active) const { groupedTags, tagsData, activeTagData } = store const groupsKeys = keys(groupedTags) @@ -62,7 +56,6 @@ const TagsBarContainer = ({ TagsBarContainer.propTypes = { tagsBar: T.object.isRequired, thread: T.string, - topic: T.string, onSelect: T.func.isRequired, active: T.shape({ id: T.string, @@ -73,7 +66,6 @@ TagsBarContainer.propTypes = { TagsBarContainer.defaultProps = { thread: THREAD.POST, - topic: TOPIC.POST, active: {}, } diff --git a/src/containers/unit/TagsBar/logic.js b/src/containers/unit/TagsBar/logic.js index e27dc9fa5..c4d2d977f 100755 --- a/src/containers/unit/TagsBar/logic.js +++ b/src/containers/unit/TagsBar/logic.js @@ -1,7 +1,7 @@ import { useEffect } from 'react' import { isEmpty, pick, contains, toUpper } from 'ramda' -import { EVENT, ERR, THREAD, TOPIC } from '@/constant' +import { EVENT, ERR, THREAD } from '@/constant' import { asyncSuit, buildLog, errRescue } from '@/utils' import S from './schema' @@ -25,14 +25,14 @@ export const onTagSelect = (tag, cb) => { const NO_TAG_THREADS = [THREAD.USER, THREAD.CHEATSHEET, THREAD.WIKI] -export const loadTags = (topic = TOPIC.POST) => { +export const loadTags = () => { const { curThread } = store if (contains(curThread, NO_TAG_THREADS)) return false const community = store.curCommunity.raw const thread = toUpper(curThread) - const args = { community, thread, topic } + const args = { community, thread } /* log('#### loadTags --> ', args) */ store.mark({ loading: true }) @@ -58,8 +58,7 @@ const DataSolver = [ { match: asyncRes(EVENT.THREAD_CHANGE), action: (data) => { - const { topic } = data[EVENT.THREAD_CHANGE].data - loadTags(topic) + loadTags() store.mark({ activeTag: null }) }, }, @@ -91,19 +90,19 @@ const ErrSolver = [ // init & uninit // ############################### -export const useInit = (_store, thread, topic, active) => { +export const useInit = (_store, thread, active) => { useEffect(() => { store = _store log('effect init') sub$ = sr71$.data().subscribe($solver(DataSolver, ErrSolver)) let activeTag = pick(['id', 'title', 'color'], active) if (isEmpty(activeTag.title)) activeTag = null - store.mark({ thread, topic, activeTag }) + store.mark({ thread, activeTag }) return () => { log('effect uninit') sub$.unsubscribe() sr71$.stop() } - }, [_store, thread, topic, active]) + }, [_store, thread, active]) } diff --git a/src/containers/unit/TagsBar/schema.ts b/src/containers/unit/TagsBar/schema.ts index 4bbe54f3b..a20b97da0 100755 --- a/src/containers/unit/TagsBar/schema.ts +++ b/src/containers/unit/TagsBar/schema.ts @@ -2,8 +2,8 @@ import gql from 'graphql-tag' import { F } from '@/schemas' const partialTags = gql` - query($communityId: ID, $community: String, $thread: CmsThread!, $topic: String) { - partialTags(communityId: $communityId, community: $community, thread: $thread, topic: $topic) { + query($communityId: ID, $community: String, $thread: CmsThread!) { + partialTags(communityId: $communityId, community: $community, thread: $thread) { ${F.tag} } } diff --git a/src/containers/unit/TagsBar/store.ts b/src/containers/unit/TagsBar/store.ts index 430a0a3a6..38d328a15 100755 --- a/src/containers/unit/TagsBar/store.ts +++ b/src/containers/unit/TagsBar/store.ts @@ -8,7 +8,6 @@ import { findIndex, propEq } from 'ramda' import type { TRootStore, TCommunity, TTag, TThread } from '@/spec' -import { TOPIC } from '@/constant' import { markStates, buildLog, stripMobx, groupByKey } from '@/utils' import { Tag } from '@/model' @@ -19,7 +18,6 @@ const TagsBar = T.model('TagsBar', { tags: T.optional(T.array(Tag), []), activeTag: T.maybeNull(Tag), thread: T.maybeNull(T.string), - topic: T.optional(T.string, TOPIC.POST), loading: T.optional(T.boolean, false), }) diff --git a/src/pages/home/posts.js b/src/pages/home/posts.js index 9854a28f1..a7106959c 100755 --- a/src/pages/home/posts.js +++ b/src/pages/home/posts.js @@ -17,7 +17,6 @@ import { ssrPagedSchema, ssrPagedFilter, ssrContentsThread, - addTopicIfNeed, ssrAmbulance, validCommunityFilters, parseTheme, @@ -42,17 +41,14 @@ const fetchData = async (props, opt) => { // const { asPath } = props // schema - const { communityPath, threadPath: topic, thread } = ssrParseURL(props.req) + const { communityPath, thread } = ssrParseURL(props.req) const community = akaTranslate(communityPath) - let filter = addTopicIfNeed( - { - ...queryStringToJSON(props.req.url, { pagi: 'number' }), - community, - }, + let filter = { + ...queryStringToJSON(props.req.url, { pagi: 'number' }), + community, thread, - topic, - ) + } filter = pick(validCommunityFilters, filter) diff --git a/src/stores/SharedModel/Tag.ts b/src/stores/SharedModel/Tag.ts index 38c650396..8cccfb1a3 100755 --- a/src/stores/SharedModel/Tag.ts +++ b/src/stores/SharedModel/Tag.ts @@ -6,16 +6,10 @@ import { THREAD } from '@/constant' import { Community } from './Community' -export const Topic = T.model('Topic', { - id: T.maybeNull(T.string), - raw: T.maybeNull(T.string), -}) - export const Tag = T.model('Tag', { id: T.maybeNull(T.string), title: T.maybeNull(T.string), color: T.optional(T.enumeration('color', TAG_COLORS), TAG_COLORS[0]), - topic: T.maybeNull(Topic), thread: T.optional(T.enumeration('thread', values(THREAD)), THREAD.POST), community: T.maybeNull(Community), insertedAt: T.optional(T.string, ''), diff --git a/utils/constant/index.ts b/utils/constant/index.ts index cbb7cb268..e60251ef3 100755 --- a/utils/constant/index.ts +++ b/utils/constant/index.ts @@ -5,7 +5,6 @@ export { default as TYPE } from './type' export { default as EVENT } from './event' export { default as ERR } from './err' export { default as ROUTE } from './route' -export { default as TOPIC } from './topic' export { THREAD, COMMUNITY_SPEC_THREADS } from './thread' export { default as USER_THREAD } from './user_thread' export { default as FILTER } from './filter' diff --git a/utils/constant/topic.ts b/utils/constant/topic.ts deleted file mode 100755 index c699ef99a..000000000 --- a/utils/constant/topic.ts +++ /dev/null @@ -1,9 +0,0 @@ -const TOPIC = { - POST: 'posts', - JOB: 'job', - RADAR: 'radar', - SHARE: 'share', - CITY: 'city', -} - -export default TOPIC diff --git a/utils/index.ts b/utils/index.ts index f1dc40cf2..6b9b4f999 100755 --- a/utils/index.ts +++ b/utils/index.ts @@ -100,7 +100,6 @@ export { ssrPagedSchema, ssrPagedFilter, ssrContentsThread, - addTopicIfNeed, validCommunityFilters, parseTheme, } from './ssr' diff --git a/utils/ssr.js b/utils/ssr.js index 21ba7e423..ff3234e9b 100755 --- a/utils/ssr.js +++ b/utils/ssr.js @@ -129,19 +129,10 @@ export const ssrContentsThread = (resp, thread, filters = {}) => { } } -// TODO generl -export const addTopicIfNeed = (source, thread, topic) => { - if (!contains(thread, ['JOB', 'REPO', 'USER', 'WIKI'])) { - return merge(source, { topic }) - } - return source -} - export const validCommunityFilters = [ 'page', 'size', 'community', - 'topic', 'tag', 'length', 'sort', From b02c19d38426e3cbd6e210bd5b63def2e701b0e8 Mon Sep 17 00:00:00 2001 From: mydearxym Date: Thu, 29 Apr 2021 09:25:10 +0800 Subject: [PATCH 2/3] refactor(psots): remove cover concept on PostItem --- src/components/PagedContents/PostsList.js | 2 -- src/components/PagedContents/index.js | 4 ---- .../PostItem/DigestView/DesktopView/index.tsx | 13 ++----------- .../PostItem/DigestView/MobileView/Header.tsx | 17 +++++------------ .../PostItem/DigestView/MobileView/index.tsx | 10 ++-------- src/components/PostItem/index.tsx | 3 --- src/containers/thread/PostsThread/index.js | 1 - 7 files changed, 9 insertions(+), 41 deletions(-) diff --git a/src/components/PagedContents/PostsList.js b/src/components/PagedContents/PostsList.js index 6f8584e20..aec045c9e 100755 --- a/src/components/PagedContents/PostsList.js +++ b/src/components/PagedContents/PostsList.js @@ -12,7 +12,6 @@ import EmptyLabel from '@/components/EmptyLabel' const PostsList = ({ props }) => { const { entries, - cover, active, curView, community, @@ -32,7 +31,6 @@ const PostsList = ({ props }) => { void onUserSelect?: (obj: TUser) => void @@ -22,20 +20,13 @@ type TProps = { const DigestView: FC = ({ entry, - cover, onPreview, onUserSelect, onAuthorSelect, }) => { return ( - {cover === 'avatar' ? ( - - ) : ( - - )} +
diff --git a/src/components/PostItem/DigestView/MobileView/Header.tsx b/src/components/PostItem/DigestView/MobileView/Header.tsx index d894c7939..d5f01d9f3 100644 --- a/src/components/PostItem/DigestView/MobileView/Header.tsx +++ b/src/components/PostItem/DigestView/MobileView/Header.tsx @@ -19,26 +19,19 @@ import { type TProps = { item: TPost - cover: 'avatar' | 'source' onAuthorSelect?: (obj: TAccount) => void } -const Header: FC = ({ cover, item, onAuthorSelect }) => { +const Header: FC = ({ item, onAuthorSelect }) => { return ( - {cover === 'avatar' ? ( - onAuthorSelect(item.author)}> - } - /> - - ) : ( + onAuthorSelect(item.author)}> } /> - )} +
{item.author.nickname}
diff --git a/src/components/PostItem/DigestView/MobileView/index.tsx b/src/components/PostItem/DigestView/MobileView/index.tsx index 15428147a..75df3f669 100644 --- a/src/components/PostItem/DigestView/MobileView/index.tsx +++ b/src/components/PostItem/DigestView/MobileView/index.tsx @@ -10,22 +10,16 @@ import { Wrapper } from '../../styles/mobile_view/index' type TProps = { entry: TPost - cover: 'avatar' | 'source' community: string onPreview?: (obj: TPost) => void onAuthorSelect?: (obj: TAccount) => void } -const MobileView: FC = ({ - entry, - cover, - onPreview, - onAuthorSelect, -}) => { +const MobileView: FC = ({ entry, onPreview, onAuthorSelect }) => { return ( -
+