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

👽 Introduce Forum Thread View #1133

Merged
merged 4 commits into from
Jul 28, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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: 2 additions & 0 deletions packages/ui/src/app/pages/Forum/Forum.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ import { Route, Switch } from 'react-router-dom'

import { ForumCategories } from '@/app/pages/Forum/ForumCategories'
import { ForumCategory } from '@/app/pages/Forum/ForumCategory'
import { ForumThread } from '@/app/pages/Forum/ForumThread'

export const Forum = () => {
return (
<Switch>
<Route path="/forum" exact component={ForumCategories} />
<Route path="/forum/category/:id" exact component={ForumCategory} />
<Route path="/forum/thread/:id" exact component={ForumThread} />
</Switch>
)
}
5 changes: 4 additions & 1 deletion packages/ui/src/app/pages/Forum/ForumCategory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useParams } from 'react-router-dom'

import { PageLayout } from '@/app/components/PageLayout'
import { Loading } from '@/common/components/Loading'
import { RouterLink } from '@/common/components/RouterLink'
import { useForumCategoryThreads } from '@/forum/hooks/useForumCategoryThreads'

export const ForumCategory = () => {
Expand All @@ -21,7 +22,9 @@ export const ForumCategory = () => {
threads.map((thread) => {
return (
<div key={thread.id}>
{thread.id} | {thread.isSticky ? '📌' : ''} {thread.title}
<RouterLink to={'/forum/thread/' + thread.id}>
{thread.id} | {thread.isSticky ? '📌' : ''} {thread.title}
</RouterLink>
</div>
)
})}
Expand Down
71 changes: 71 additions & 0 deletions packages/ui/src/app/pages/Forum/ForumThread.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import React, { useRef } from 'react'
import { useParams } from 'react-router-dom'

import { PageLayout } from '@/app/components/PageLayout'
import { ActivitiesBlock } from '@/common/components/Activities/ActivitiesBlock'
import { ButtonGhost, ButtonsGroup } from '@/common/components/buttons'
import { LinkIcon, WatchIcon } from '@/common/components/icons'
import { Loading } from '@/common/components/Loading'
import { PageHeader } from '@/common/components/page/PageHeader'
import { PageTitle } from '@/common/components/page/PageTitle'
import { PreviousPage } from '@/common/components/page/PreviousPage'
import { SidePanel } from '@/common/components/page/SidePanel'
import { useCopyToClipboard } from '@/common/hooks/useCopyToClipboard'
import { useForumThread } from '@/forum/hooks/useForumThread'

export const ForumThread = () => {
const { id } = useParams<{ id: string }>()
const { isLoading, thread } = useForumThread(id)
Comment on lines +16 to +18
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A simple test for the "loaded" state might be beneficial as well.


const { copyValue } = useCopyToClipboard()
const sideNeighborRef = useRef<HTMLDivElement>(null)

const displayHeader = () => {
if (isLoading || !thread) {
return null
}

return (
<PageHeader>
<PreviousPage>
<PageTitle>{thread.title}</PageTitle>
</PreviousPage>
<ButtonsGroup>
<ButtonGhost size="medium" onClick={() => copyValue(window.location.href)}>
<LinkIcon />
Copy link
</ButtonGhost>
<ButtonGhost size="medium">
<WatchIcon />
Watch thread
</ButtonGhost>
</ButtonsGroup>
</PageHeader>
)
}

const displayMain = () => {
if (isLoading) {
return <Loading />
}
if (!thread) {
return <h1>404 Not Found</h1>
}
nick-olizarenko marked this conversation as resolved.
Show resolved Hide resolved

return <div>Thread content</div>
}

const displaySidebar = () => {
if (isLoading || !thread) {
return null
}

return (
<SidePanel neighbor={sideNeighborRef}>
<ActivitiesBlock activities={[]} label="Suggested Threads" />
nick-olizarenko marked this conversation as resolved.
Show resolved Hide resolved
</SidePanel>
)
}

return <PageLayout header={displayHeader()} main={displayMain()} sidebar={displaySidebar()} />
}
14 changes: 14 additions & 0 deletions packages/ui/src/common/components/icons/WatchIcon.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import React from 'react'

import { Icon } from './Icon'

export const WatchIcon = React.memo(() => (
<Icon size="16" viewBox="0 0 16 16" fill="none" color="currentColor">
<path
fill-rule="evenodd"
clip-rule="evenodd"
d="M8.18185 4.94346C6.62683 4.94346 5.36187 6.20841 5.36187 7.76343C5.36187 9.31844 6.62683 10.5834 8.18185 10.5834C9.73686 10.5834 11.0018 9.31844 11.0018 7.76343C11.0018 6.20841 9.73686 4.94346 8.18185 4.94346ZM14.9399 7.44899C14.503 6.74506 12.0895 3.21657 7.99681 3.33494C4.21092 3.42357 2.0091 6.50641 1.42423 7.44899C1.30301 7.64396 1.30301 7.88388 1.42423 8.07885C1.855 8.77328 4.18352 12.1948 8.19885 12.1948C8.25501 12.1948 8.31116 12.1942 8.36732 12.1929C12.1525 12.1036 14.355 9.02143 14.9399 8.07885C15.0604 7.88388 15.0604 7.64396 14.9399 7.44899Z"
fill="currentColor"
/>
</Icon>
))
1 change: 1 addition & 0 deletions packages/ui/src/common/components/icons/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ export * from './SuccessIcon'
export * from './TransferIcon'
export * from './VerifiedMemberIcon'
export * from './WaitingIcon'
export * from './WatchIcon'
11 changes: 11 additions & 0 deletions packages/ui/src/forum/hooks/useForumThread.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { useGetForumThreadQuery } from '@/forum/queries/__generated__/forum.generated'
import { asForumThread } from '@/forum/types'

export const useForumThread = (threadId: string) => {
const { loading, data } = useGetForumThreadQuery({ variables: { where: { id: threadId } } })

return {
isLoading: loading,
thread: data && data.thread ? asForumThread(data.thread) : null,
}
}
49 changes: 49 additions & 0 deletions packages/ui/src/forum/queries/__generated__/forum.generated.tsx

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions packages/ui/src/forum/queries/forum.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,9 @@ query GetForumThreads($where: ForumThreadWhereInput) {
...ForumThreadFields
}
}

query GetForumThread($where: ForumThreadWhereUniqueInput!) {
thread: forumThreadByUniqueInput(where: $where) {
...ForumThreadFields
}
}
1 change: 1 addition & 0 deletions packages/ui/src/mocks/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export const makeServer = (environment = 'development') => {
budgetSpendingEvents: getWhereResolver('BudgetSpendingEvent'),
forumCategories: getWhereResolver('ForumCategory'),
forumThreads: getWhereResolver('ForumThread'),
forumThreadByUniqueInput: getUniqueResolver('ForumThread'),
membershipByUniqueInput: getUniqueResolver('Membership'),
memberships: getWhereResolver('Membership'),
membershipsConnection: getConnectionResolver('MembershipConnection'),
Expand Down