diff --git a/src/containers/thread/DashboardThread/index.tsx b/src/containers/thread/DashboardThread/index.tsx index e5aafe279..4a30dbea1 100755 --- a/src/containers/thread/DashboardThread/index.tsx +++ b/src/containers/thread/DashboardThread/index.tsx @@ -47,7 +47,6 @@ const DashboardThread: FC = () => { const { curTab, overviewData, - curCommunity, baseInfoSettings, seoSettings, enableSettings, diff --git a/src/containers/thread/DashboardThread/store/index.ts b/src/containers/thread/DashboardThread/store/index.ts index 358d145b9..9ec46434d 100644 --- a/src/containers/thread/DashboardThread/store/index.ts +++ b/src/containers/thread/DashboardThread/store/index.ts @@ -150,6 +150,11 @@ const DashboardThread = T.model('DashboardThread', { allRootRules: T.opt(T.str, '{}'), }) .views((self) => ({ + get curCommunity(): TCommunity { + const root = getParent(self) as TRootStore + + return toJS(root.viewing.community) + }, get overviewData(): TOverview { return toJS(self.overview) }, @@ -185,12 +190,6 @@ const DashboardThread = T.model('DashboardThread', { enable: init.enable, } }, - get curCommunity(): TCommunity { - const root = getParent(self) as TRootStore - - return toJS(root.viewing.community) - }, - get cmsContents(): TCMSContents { const slf = self as TStore const { batchSelectedIDs, docTab, editingFAQIndex } = slf diff --git a/src/containers/thread/ThreadSidebar/ClassicLayout/index.tsx b/src/containers/thread/PostThread/ThreadSidebar.tsx old mode 100755 new mode 100644 similarity index 80% rename from src/containers/thread/ThreadSidebar/ClassicLayout/index.tsx rename to src/containers/thread/PostThread/ThreadSidebar.tsx index 029b3afde..7b108c78a --- a/src/containers/thread/ThreadSidebar/ClassicLayout/index.tsx +++ b/src/containers/thread/PostThread/ThreadSidebar.tsx @@ -10,11 +10,12 @@ import { FC, Fragment } from 'react' import { observer } from 'mobx-react-lite' import useAvatarLayout from '@/hooks/useAvatarLayout' +import useCommunityDigestViewport from '@/hooks/useCommunityDigestViewport' import EVENT from '@/constant/event' import { ARTICLE_CAT } from '@/constant/gtd' import { buildLog } from '@/logger' -import { send } from '@/signal' +import { send, callGEditor, callSyncSelector } from '@/signal' import { mockUsers } from '@/mock' import ImgFallback from '@/widgets/ImgFallback' @@ -34,17 +35,13 @@ import { MoreNum, CommunityNoteWrapper, PublishWrapper, -} from '../styles/classic_layout' -import { onPublish } from '../logic' +} from './styles/thread_sidebar' /* eslint-disable-next-line */ const log = buildLog('w:ClassicSidebar') -export type TProps = { - showCommunityBadge: boolean -} - -const ClassicLayout: FC = ({ showCommunityBadge }) => { +const ThreadSidebar: FC = () => { + const { inView: showCommunityBadge } = useCommunityDigestViewport() const avatarLayout = useAvatarLayout() return ( @@ -86,8 +83,14 @@ const ClassicLayout: FC = ({ showCommunityBadge }) => { onPublish(ARTICLE_CAT.FEATURE)} - onMenuSelect={onPublish} + onClick={() => { + // callGEditor() + // setTimeout(() => callSyncSelector({ cat, tag: store.activeTag }), 500) + // onPublish(ARTICLE_CAT.FEATURE) + }} + onMenuSelect={() => { + console.log('## TODO') + }} left={-2} offset={[0, 5]} /> @@ -104,4 +107,4 @@ const ClassicLayout: FC = ({ showCommunityBadge }) => { ) } -export default observer(ClassicLayout) +export default observer(ThreadSidebar) diff --git a/src/containers/thread/PostThread/index.tsx b/src/containers/thread/PostThread/index.tsx index 85e0f93a2..48face4ec 100644 --- a/src/containers/thread/PostThread/index.tsx +++ b/src/containers/thread/PostThread/index.tsx @@ -16,13 +16,14 @@ import useBannerLayout from '@/hooks/useBannerLayout' import usePagedPosts from '@/hooks/usePagedPosts' import { THREAD } from '@/constant/thread' -import ThreadSidebar from '@/containers/thread/ThreadSidebar' import PagedPosts from '@/widgets/PagedPosts' import TagNote from '@/widgets/TagNote' import ViewportTracker from '@/widgets/ViewportTracker' import ArticlesFilter from '@/widgets/ArticlesFilter' // import LavaLampLoading from '@/widgets/Loading/LavaLampLoading' +import ThreadSidebar from './ThreadSidebar' + import { Wrapper, MainWrapper, SidebarWrapper, FilterWrapper } from './styles' import { inAnchor, outAnchor, onFilterSelect } from './logic' diff --git a/src/containers/thread/ThreadSidebar/styles/classic_layout.ts b/src/containers/thread/PostThread/styles/thread_sidebar.ts old mode 100755 new mode 100644 similarity index 100% rename from src/containers/thread/ThreadSidebar/styles/classic_layout.ts rename to src/containers/thread/PostThread/styles/thread_sidebar.ts diff --git a/src/containers/thread/ThreadSidebar/index.tsx b/src/containers/thread/ThreadSidebar/index.tsx deleted file mode 100755 index 190b59da8..000000000 --- a/src/containers/thread/ThreadSidebar/index.tsx +++ /dev/null @@ -1,30 +0,0 @@ -// - -/* - * - * ThreadSidebar - * - */ - -import { FC } from 'react' - -import { buildLog } from '@/logger' - -import ClassicLayout from './ClassicLayout' - -import { useStore } from './store' -import { useInit } from './logic' -import { observer } from 'mobx-react-lite' - -/* eslint-disable-next-line */ -const log = buildLog('C:ThreadSidebar') - -const ThreadSidebar: FC = () => { - const store = useStore() - useInit(store) - const { isCommunityDigestInViewport } = store - - return -} - -export default observer(ThreadSidebar) diff --git a/src/containers/thread/ThreadSidebar/logic.ts b/src/containers/thread/ThreadSidebar/logic.ts deleted file mode 100755 index 0d65dd6b7..000000000 --- a/src/containers/thread/ThreadSidebar/logic.ts +++ /dev/null @@ -1,129 +0,0 @@ -import { useEffect } from 'react' -// import { } from 'ramda' - -import type { TArticleCat, TID } from '@/spec' -import { ARTICLE_THREAD } from '@/constant/thread' - -import EVENT from '@/constant/event' -import ERR from '@/constant/err' -import TYPE from '@/constant/type' - -import asyncSuit from '@/async' -import { errRescue, listUsers, callGEditor, callSyncSelector } from '@/signal' -import { buildLog } from '@/logger' - -import type { TStore } from './store' -import S from './schema' - -const { SR71, $solver, asyncRes, asyncErr } = asyncSuit -// @ts-ignore -const sr71$ = new SR71({ receive: [EVENT.COMMUNITY_CHANGE] }) - -let sub$ = null -let store: TStore | undefined - -/* eslint-disable-next-line */ -const log = buildLog('L:ThreadSidebar') - -export const onPublish = (cat: TArticleCat) => { - callGEditor() - setTimeout(() => callSyncSelector({ cat, tag: store.activeTag }), 500) -} - -export const subscribeCommunity = (communityId: TID): void => { - sr71$.mutate(S.subscribeCommunity, { communityId }) -} - -export const unsubscribeCommunity = (communityId: TID): void => { - sr71$.mutate(S.unsubscribeCommunity, { communityId }) -} - -// 查看当前社区志愿者列表 -export const onShowEditorList = (): void => { - listUsers(TYPE.USER_LISTER_COMMUNITY_EDITORS) -} - -export const onShowSubscriberList = (): void => { - listUsers(TYPE.USER_LISTER_COMMUNITY_SUBSCRIBERS) -} - -const loadCommunity = (): void => { - const userHasLogin = store.isLogin - const { slug } = store.curCommunity - - markLoading(true) - - sr71$.query(S.community, { slug, userHasLogin }) -} - -const markLoading = (maybe = true) => store.mark({ loading: maybe }) - -// ############################### -// init & uninit handlers -// ############################### - -const DataSolver = [ - { - match: asyncRes('community'), - action: ({ community }) => { - markLoading(false) - log('community: ', community) - const activeThread = ARTICLE_THREAD.POST - store.setViewing({ community, activeThread }) - }, - }, - { - match: asyncRes('subscribeCommunity'), - action: ({ subscribeCommunity }) => { - store.addSubscribedCommunity(subscribeCommunity) - loadCommunity() - }, - }, - { - match: asyncRes('unsubscribeCommunity'), - action: ({ unsubscribeCommunity }) => { - store.removeSubscribedCommunity(unsubscribeCommunity) - loadCommunity() - }, - }, - { - match: asyncRes(EVENT.COMMUNITY_CHANGE), - action: () => loadCommunity(), - }, -] - -const ErrSolver = [ - { - match: asyncErr(ERR.GRAPHQL), - action: () => markLoading(false), - }, - { - match: asyncErr(ERR.TIMEOUT), - action: ({ details }) => { - markLoading(false) - errRescue({ type: ERR.TIMEOUT, details, path: 'ThreadSidebar' }) - }, - }, - { - match: asyncErr(ERR.NETWORK), - action: () => { - markLoading(false) - errRescue({ type: ERR.NETWORK, path: 'ThreadSidebar' }) - }, - }, -] -export const useInit = (_store: TStore): void => { - useEffect(() => { - store = _store - // log('effect init') - sub$ = sr71$.data().subscribe($solver(DataSolver, ErrSolver)) - - return () => { - if (sub$) { - sr71$.stop() - sub$.unsubscribe() - } - // log('effect uninit') - } - }, [_store]) -} diff --git a/src/containers/thread/ThreadSidebar/schema.ts b/src/containers/thread/ThreadSidebar/schema.ts deleted file mode 100755 index e4f54ce26..000000000 --- a/src/containers/thread/ThreadSidebar/schema.ts +++ /dev/null @@ -1,29 +0,0 @@ -import { gql } from 'urql/core' -import { P } from '@/schemas' - -const community = gql` - ${P.community} -` -const subscribeCommunity = gql` - mutation ($communityId: ID!) { - subscribeCommunity(communityId: $communityId) { - id - slug - } - } -` -const unsubscribeCommunity = gql` - mutation ($communityId: ID!) { - unsubscribeCommunity(communityId: $communityId) { - id - slug - } - } -` -const schema = { - community, - subscribeCommunity, - unsubscribeCommunity, -} - -export default schema diff --git a/src/containers/thread/ThreadSidebar/store.ts b/src/containers/thread/ThreadSidebar/store.ts deleted file mode 100755 index 81114ad24..000000000 --- a/src/containers/thread/ThreadSidebar/store.ts +++ /dev/null @@ -1,79 +0,0 @@ -/* - * ThreadSidebar store - */ - -// import {} from 'ramda' - -import type { TAccount, TC11N, TCommunity, TThread, TRootStore, TTag } from '@/spec' -import { T, getParent, markStates, Instance, toJS, useMobxContext } from '@/mobx' -import { buildLog } from '@/logger' - -/* eslint-disable-next-line */ -const log = buildLog('S:ThreadSidebar') - -const ThreadSidebar = T.model('ThreadSidebar', {}) - .views((self) => ({ - get accountInfo(): TAccount { - const root = getParent(self) as TRootStore - return root.accountInfo - }, - get isLogin(): boolean { - const root = getParent(self) as TRootStore - return root.account.isLogin - }, - get c11n(): TC11N { - const root = getParent(self) as TRootStore - return root.account.c11n - }, - get curCommunity(): TCommunity { - const root = getParent(self) as TRootStore - - return toJS(root.viewing.community) - }, - - get curThread(): TThread { - const root = getParent(self) as TRootStore - return root.viewing.activeThread - }, - - get isCommunityDigestInViewport(): boolean { - const root = getParent(self) as TRootStore - return root.communityDigestInView - }, - - get realtimeVisitors(): number { - return 0 - }, - - get activeTag(): TTag { - const root = getParent(self) as TRootStore - - return root.tagsBar.activeTagData - }, - })) - .actions((self) => ({ - authWarning(options = {}): void { - const root = getParent(self) as TRootStore - root.authWarning(options) - }, - setViewing(sobj): void { - const root = getParent(self) as TRootStore - root.setViewing(sobj) - }, - addSubscribedCommunity(community: TCommunity): void { - const root = getParent(self) as TRootStore - root.account.addSubscribedCommunity(community) - }, - removeSubscribedCommunity(community: TCommunity): void { - const root = getParent(self) as TRootStore - root.account.removeSubscribedCommunity(community) - }, - mark(sobj: Record): void { - markStates(sobj, self) - }, - })) - -export type TStore = Instance -export const useStore = (): TStore => useMobxContext().store.threadSidebar - -export default ThreadSidebar diff --git a/src/containers/thread/ThreadSidebar/tests/index.test.js b/src/containers/thread/ThreadSidebar/tests/index.test.js deleted file mode 100755 index fc8abb077..000000000 --- a/src/containers/thread/ThreadSidebar/tests/index.test.js +++ /dev/null @@ -1,10 +0,0 @@ -// import React from 'react' -// import { shallow } from 'enzyme' - -// import ThreadSidebar from '..' - -describe('TODO ', () => { - it('Expect to have unit tests specified', () => { - expect(true).toEqual(true) - }) -}) diff --git a/src/containers/thread/ThreadSidebar/tests/store.test.js b/src/containers/thread/ThreadSidebar/tests/store.test.js deleted file mode 100755 index 940a4cdfc..000000000 --- a/src/containers/thread/ThreadSidebar/tests/store.test.js +++ /dev/null @@ -1,10 +0,0 @@ -/* - * ThreadSidebar store test - * - */ - -// import ThreadSidebar from '..' - -it('TODO: store test ThreadSidebar', () => { - expect(1 + 1).toBe(2) -}) diff --git a/src/containers/unit/TagsBar/DesktopView/Folder.tsx b/src/containers/unit/TagsBar/DesktopView/Folder.tsx index a59015e2e..9dc13616b 100755 --- a/src/containers/unit/TagsBar/DesktopView/Folder.tsx +++ b/src/containers/unit/TagsBar/DesktopView/Folder.tsx @@ -6,7 +6,6 @@ import { sortByColor } from '@/helper' import TagItem from './TagItem' -import { TagsWrapper } from '../styles/desktop_view' import { Wrapper, Header, @@ -86,16 +85,14 @@ const Folder: FC = ({ - - {sortedTags.slice(0, curDisplayCount).map((tag) => ( - - ))} - + {sortedTags.slice(0, curDisplayCount).map((tag) => ( + + ))} {needSubToggle && ( void leaveView: () => void + inView: boolean } /** @@ -21,6 +22,7 @@ const useCommunityDigestViewport = (): TRet => { return { enterView: (): void => store.mark({ communityDigestInView: true }), leaveView: (): void => store.mark({ communityDigestInView: false }), + inView: store.communityDigestInView, } } diff --git a/src/stores/RootStore/index.ts b/src/stores/RootStore/index.ts index a252251b9..554464c38 100755 --- a/src/stores/RootStore/index.ts +++ b/src/stores/RootStore/index.ts @@ -62,7 +62,6 @@ import { AboutThreadStore, // CollectionFolderStore, ArticleViewerStore, - ThreadSidebarStore, // AbuseReportStore, ArticleEditorStore, // UserProfileStore, @@ -140,7 +139,6 @@ const rootStore = T.model({ aboutThread: T.opt(AboutThreadStore, {}), // collectionFolder: T.opt(CollectionFolderStore, {}), articleViewer: T.opt(ArticleViewerStore, {}), - threadSidebar: T.opt(ThreadSidebarStore, {}), // abuseReport: T.opt(AbuseReportStore, {}), articleEditor: T.opt(ArticleEditorStore, {}), // userProfile: T.opt(UserProfileStore, {}), diff --git a/src/stores/index.ts b/src/stores/index.ts index 1d5d4f7fc..34554e946 100755 --- a/src/stores/index.ts +++ b/src/stores/index.ts @@ -63,7 +63,6 @@ export { default as DocThreadStore } from '@/containers/thread/DocThread/store' export { default as AboutThreadStore } from '@/containers/thread/AboutThread/store' // export { default as BlogEditorStore } from '@/containers/editor/BlogEditor/store' export { default as ArticleViewerStore } from '@/containers/viewer/ArticleViewer/store' -export { default as ThreadSidebarStore } from '@/containers/thread/ThreadSidebar/store' export { default as ArticleEditorStore } from '@/containers/editor/ArticleEditor/store' export { default as ModeLineMenuStore } from '@/containers/unit/ModeLineMenu/store' export { default as ModeLineStore } from '@/containers/unit/ModeLine/store' diff --git a/src/widgets/CommunityDigest/SidebarLayout/CommunityBrief.tsx b/src/widgets/CommunityDigest/SidebarLayout/CommunityBrief.tsx index f7eaec898..171e7c892 100644 --- a/src/widgets/CommunityDigest/SidebarLayout/CommunityBrief.tsx +++ b/src/widgets/CommunityDigest/SidebarLayout/CommunityBrief.tsx @@ -4,6 +4,7 @@ import { useRouter } from 'next/navigation' import { BANNER_LAYOUT } from '@/constant/layout' import { THREAD } from '@/constant/thread' +import { assetSrc } from '@/helper' import useViewingCommunity from '@/hooks/useViewingCommunity' import useViewingThread from '@/hooks/useViewingThread' @@ -39,7 +40,7 @@ const CommunityBrief: FC = () => { - + {title} diff --git a/src/widgets/CommunityDigest/styles/sidebar_layout/index.ts b/src/widgets/CommunityDigest/styles/sidebar_layout/index.ts index 1d1a542ba..d0c93ca76 100644 --- a/src/widgets/CommunityDigest/styles/sidebar_layout/index.ts +++ b/src/widgets/CommunityDigest/styles/sidebar_layout/index.ts @@ -38,6 +38,7 @@ export const TabBarWrapper = styled.div` ${css.row('align-center', 'justify-start')}; margin-left: 10px; transform: scale(1.05); + width: 80%; ` export const Divider = styled(SexyDivider)` width: 200px; diff --git a/src/widgets/CommunityDigest/styles/sidebar_layout/main_menu.ts b/src/widgets/CommunityDigest/styles/sidebar_layout/main_menu.ts index 2a4d485fa..4e39df731 100644 --- a/src/widgets/CommunityDigest/styles/sidebar_layout/main_menu.ts +++ b/src/widgets/CommunityDigest/styles/sidebar_layout/main_menu.ts @@ -25,6 +25,7 @@ export const MenuItem = styled(Link)` width: 160px; border: 1px solid; border-color: ${({ $active }) => ($active ? theme('hoverBorder') : 'transparent')}; + filter: ${({ $active }) => ($active ? 'saturate(1.1) brightness(1.1)' : '')}; text-decoration: none; height: 32px; padding-left: 8px;