Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(articles): move articles pages to app dir #187

Merged
merged 1 commit into from
Nov 30, 2023
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
9 changes: 9 additions & 0 deletions src/app/[community]/(articles)/about/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
'use client'

import AboutThread from '@/containers/thread/AboutThread'

const CommunityAboutPage = () => {
return <AboutThread />
}

export default CommunityAboutPage
9 changes: 9 additions & 0 deletions src/app/[community]/(articles)/changelog/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
'use client'

import ChangelogThread from '@/containers/thread/ChangelogThread'

const CommunityChangelogPage = () => {
return <ChangelogThread />
}

export default CommunityChangelogPage
9 changes: 9 additions & 0 deletions src/app/[community]/(articles)/doc/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
'use client'

import DocThread from '@/containers//thread/DocThread'

const CommunityDocPage = () => {
return <DocThread />
}

export default CommunityDocPage
9 changes: 9 additions & 0 deletions src/app/[community]/(articles)/kanban/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
'use client'

import KanbanThread from '@/containers//thread/KanbanThread'

const CommunityKanbanPage = () => {
return <KanbanThread />
}

export default CommunityKanbanPage
32 changes: 32 additions & 0 deletions src/app/[community]/(articles)/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
'use client'

import { observer } from 'mobx-react-lite'

import { BANNER_LAYOUT } from '@/constant/layout'

import useMetric from '@/hooks/useMetric'
import useBannerLayout from '@/hooks/useBannerLayout'

import CommunityDigest from '@/widgets/CommunityDigest'

import { Wrapper, SidebarWrapper, InnerWrapper, ContentWrapper } from './styles'

const Layout = ({ children }) => {
const metric = useMetric()

const bannerLayout = useBannerLayout()
const isSidebarLayout = bannerLayout === BANNER_LAYOUT.SIDEBAR
const LayoutWrapper = isSidebarLayout ? SidebarWrapper : Wrapper

return (
<LayoutWrapper $testid="post-thread-content" metric={metric}>
<CommunityDigest />

<InnerWrapper metric={metric} $bannerLayout={bannerLayout}>
<ContentWrapper>{children}</ContentWrapper>
</InnerWrapper>
</LayoutWrapper>
)
}

export default observer(Layout)
18 changes: 18 additions & 0 deletions src/app/[community]/(articles)/post/[id]/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
'use client'

import useMetric from '@/hooks/useMetric'

import { Wrapper, InnerWrapper } from '@/widgets/Article/styles/post'

const Layout = ({ children }) => {
const metric = useMetric()

return (
<Wrapper metric={metric}>
{/* <FixedHeader show={!inViewport} article={viewingArticle} metric={metric} /> */}
<InnerWrapper metric={metric}>{children}</InnerWrapper>
</Wrapper>
)
}

export default Layout
9 changes: 9 additions & 0 deletions src/app/[community]/(articles)/post/[id]/loading.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const Loading = () => {
return (
<div>
<h2>post id loading</h2>
</div>
)
}

export default Loading
9 changes: 9 additions & 0 deletions src/app/[community]/(articles)/post/loading.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const Loading = () => {
return (
<div>
<h2>post loading</h2>
</div>
)
}

export default Loading
19 changes: 19 additions & 0 deletions src/app/[community]/(articles)/post/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
'use client'

import useIsSidebarLayout from '@/hooks/useIsSidebarLayout'

import PostThread from '@/containers//thread/PostThread'
import { Br } from '@/widgets/Common'

const CommunityPostPage = () => {
const isSidebarLayout = useIsSidebarLayout()

return (
<>
{isSidebarLayout && <Br top={20} />}
<PostThread />
</>
)
}

export default CommunityPostPage
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { BANNER_LAYOUT } from '@/constant/layout'

import css, { theme } from '@/css'

export const BaseWrapper = styled.div.attrs<TTestable>(({ $testid }) => ({
const BaseWrapper = styled.div.attrs<TTestable>(({ $testid }) => ({
'data-test-id': $testid,
}))<TTestable>`
min-height: 70vh;
Expand All @@ -32,10 +32,6 @@ export const BaseInnerWrapper = styled.div<{ metric?: TMetric }>`
padding: 0;
`};
`
export const BaseContentWrapper = styled.div`
${css.column()};
width: 100%;
`
export const Wrapper = styled(BaseWrapper)<{ metric?: TMetric }>`
${css.column('justify-start', 'align-center')};

Expand Down Expand Up @@ -67,4 +63,7 @@ export const InnerWrapper = styled(BaseInnerWrapper)<{ $bannerLayout?: TBannerLa
margin-left: 0;
`};
`
export const ContentWrapper = styled(BaseContentWrapper)``
export const ContentWrapper = styled.div`
${css.column()};
width: 100%;
`
9 changes: 0 additions & 9 deletions src/app/[community]/about/page.tsx

This file was deleted.

9 changes: 0 additions & 9 deletions src/app/[community]/changelog/page.tsx

This file was deleted.

12 changes: 5 additions & 7 deletions src/app/[community]/dashboard/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,28 +1,26 @@
'use client'

import { observer } from 'mobx-react-lite'

import useDashboardSettings from '@/hooks/useDashboardSettings'
import useMetric from '@/hooks/useMetric'

import CommunityDigest from '@/widgets/CommunityDigest'

import {
Wrapper as WrapperRoot,
InnerWrapper,
ContentWrapper,
// MobileCardsWrapper,
} from '@/containers/content/CommunityContent/styles/dashboard_content'
import { Wrapper as WrapperRoot, InnerWrapper, ContentWrapper } from './styles'

import { Wrapper, MainWrapper } from '@/containers/thread/DashboardThread/styles'
import SideMenu from '@/containers/thread/DashboardThread/SideMenu'

const Layout = ({ children }) => {
const { curTab, touched } = useDashboardSettings()
const metric = useMetric()

return (
<WrapperRoot $testid="dashboard-thread-content">
<CommunityDigest />

<InnerWrapper metric="COMMUNITY">
<InnerWrapper metric={metric}>
<ContentWrapper>
<Wrapper $testid="dashboard-thread" metric="COMMUNITY">
<SideMenu curTab={curTab} touched={touched} />
Expand Down
41 changes: 41 additions & 0 deletions src/app/[community]/dashboard/styles/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import styled from 'styled-components'

import type { TMetric, TTestable } from '@/spec'
import css from '@/css'

export const BaseWrapper = styled.div.attrs<TTestable>(({ $testid }) => ({
'data-test-id': $testid,
}))<TTestable>`
min-height: 70vh;
width: 100%;

${css.media.tablet`
width: 100%;
margin: 0;
padding: .6em;
padding-top: 0;
padding-right: 0;
`};
`

export const Wrapper = styled(BaseWrapper)<{ metric?: TMetric }>`
${css.column('justify-start', 'align-center')};

${css.media.mobile`
padding-left: 0;
`};
`

export const InnerWrapper = styled.div<{ metric: TMetric }>`
${({ metric }) => css.fitContentWidth(metric)};

width: 100%;
margin-top: 15px;
padding-top: 0;
${css.column('align-center')};
`

export const ContentWrapper = styled.div`
${css.column()};
width: 100%;
`
9 changes: 0 additions & 9 deletions src/app/[community]/doc/page.tsx

This file was deleted.

9 changes: 0 additions & 9 deletions src/app/[community]/kanban/page.tsx

This file was deleted.

24 changes: 10 additions & 14 deletions src/app/[community]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
'use client'

import Link from 'next/link'
import useIsSidebarLayout from '@/hooks/useIsSidebarLayout'

import PostContent from '@/containers/content/CommunityContent/PostContent'
import PostThread from '@/containers//thread/PostThread'
import { Br } from '@/widgets/Common'

const CommunityPage = () => {
// const rootStore = useRootStore()

// console.log('## in community render, ', data)
const CommunityPostPage = () => {
const isSidebarLayout = useIsSidebarLayout()

return (
<div>
<div>
<Link href="/test">go to test</Link>
</div>

<PostContent />
</div>
<>
{isSidebarLayout && <Br top={20} />}
<PostThread />
</>
)
}

export default CommunityPage
export default CommunityPostPage
9 changes: 0 additions & 9 deletions src/app/[community]/post/page.tsx

This file was deleted.

3 changes: 3 additions & 0 deletions src/app/providers/RootStoreProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { enableStaticRendering } from 'mobx-react-lite'
import { useStore } from '@/stores/init'

import {
useMetric,
useSession,
useCommunity,
useTags,
Expand All @@ -32,6 +33,7 @@ type TProps = {
const RootStoreWrapper: FC<TProps> = ({ children, token }) => {
const userHasLogin = !!token

const metric = useMetric()
const activeThread = useThreadParam()
// console.log('## activeThread: ', activeThread)

Expand All @@ -50,6 +52,7 @@ const RootStoreWrapper: FC<TProps> = ({ children, token }) => {
const filterSearchParams = useFilterSearchParams()

const store = useStore({
metric,
...sesstion,
articles: {
pagedPosts,
Expand Down
14 changes: 13 additions & 1 deletion src/app/queries/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ import { values, includes } from 'ramda'
import { useQuery } from '@urql/next'
import { usePathname, useSearchParams } from 'next/navigation'

import type { TCommunity } from '@/spec'
import type { TCommunity, TMetric } from '@/spec'
import { P } from '@/schemas'
import { DEFAULT_THEME } from '@/config'
import { THREAD, ARTICLE_THREAD } from '@/constant/thread'
import METRIC from '@/constant/metric'
import URL_PARAM from '@/constant/url_param'
import { ARTICLE_CAT, ARTICLE_STATE, ARTICLE_ORDER } from '@/constant/gtd'

Expand Down Expand Up @@ -43,6 +44,17 @@ import {

export { parseCommunity, useThreadParam } from './helper'

export const useMetric = (): TMetric => {
const thread = useThreadParam()
const articleParams = useArticleParams()

if (includes(thread, values(ARTICLE_THREAD)) && articleParams.id) {
return METRIC.ARTICLE
}

return METRIC.COMMUNITY
}

export const useSession = (): TSessionRes => {
const isStaticQuery = useIsStaticQuery()

Expand Down
Loading
Loading