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

Fixed Joystream Pioneer Forum Back Link #3768 #4147

Merged
merged 6 commits into from
Mar 3, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
3 changes: 2 additions & 1 deletion packages/ui/src/app/pages/Forum/ForumCategory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@ import { ThreadFilters } from '@/forum/components/threads/ThreadFilters'
import { ThreadList } from '@/forum/components/threads/ThreadList'
import { THREADS_PER_PAGE } from '@/forum/constant'
import { useForumCategory } from '@/forum/hooks/useForumCategory'
import { useForumCategoryThreadPage } from '@/forum/hooks/useForumCategoryThreadPage'
import { useForumCategoryThreads } from '@/forum/hooks/useForumCategoryThreads'
import { MemberStack, moderatorsSummary } from '@/memberships/components/MemberStack'

import { ForumPageLayout } from './components/ForumPageLayout'

export const ForumCategory = () => {
const [page, setPage] = useState<number>(1)
const [page, setPage] = useState<number>(useForumCategoryThreadPage())
const { id, type } = useParams<{ id: string; type?: 'archive' }>()
const isArchive = type === 'archive'

Expand Down
9 changes: 8 additions & 1 deletion packages/ui/src/common/components/Pagination/Pagination.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { FC } from 'react'
import ReactPaginate from 'react-paginate'
import { useHistory } from 'react-router'
import styled from 'styled-components'

import { Arrow } from '@/common/components/icons'
Expand All @@ -12,9 +13,15 @@ interface PaginationProps {
}

export const Pagination: FC<PaginationProps> = ({ pageCount = 0, handlePageChange, page }) => {
const history = useHistory()

if (pageCount < 2) {
return null
}
const pageChangeAction = (value: any) => {
history.push(`?page=${value.selected + 1}`)
handlePageChange(value.selected + 1)
vrrayz marked this conversation as resolved.
Show resolved Hide resolved
}

return (
<StyledPaginateContainer>
Expand All @@ -32,7 +39,7 @@ export const Pagination: FC<PaginationProps> = ({ pageCount = 0, handlePageChang
nextLabel={<Arrow direction="right" />}
nextLinkClassName="pagination__link"
previousLinkClassName="pagination__link pagination__link--previous"
onPageChange={(value) => handlePageChange(value.selected + 1)}
onPageChange={(value) => pageChangeAction(value)}
forcePage={page && page - 1}
/>
</StyledPaginateContainer>
Expand Down
6 changes: 6 additions & 0 deletions packages/ui/src/forum/hooks/useForumCategoryThreadPage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export const useForumCategoryThreadPage = () => {
const locationHash = window.location.hash
const queryString = locationHash.substring(locationHash.indexOf('?'))
const urlParams = new URLSearchParams(queryString)
return Number(urlParams.get('page')) || 1
}