Skip to content

Commit

Permalink
Fix up the final pages!
Browse files Browse the repository at this point in the history
  • Loading branch information
robin-macpherson committed Jun 27, 2024
1 parent 49c642b commit 73e637e
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 31 deletions.
64 changes: 45 additions & 19 deletions packages/web/pages/post/[id]/edit.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React from 'react'
import { NextPage } from 'next'
import { useRouter } from 'next/router'
import { withApollo } from '@/lib/apollo'
import { useTranslation } from '@/config/i18n'
import { TElement } from '@udecode/plate'

Expand All @@ -13,12 +12,19 @@ import PostEditor, {
} from '@/components/PostEditor'
import theme from '@/theme'
import Button, { ButtonVariant } from '@/components/Button'
import { useEditPostQuery, useUpdatePostMutation } from '@/generated/graphql'
import {
EditPostDocument,
PostPageDocument,
useEditPostQuery,
useUpdatePostMutation,
} from '@/generated/graphql'
import AuthGate from '@/components/AuthGate'
import ConfirmationModal from '@/components/Modals/ConfirmationModal'
import useUILanguage from '@/hooks/useUILanguage'
import useAuthCheck from '@/hooks/useAuthCheck'
import useUploadInlineImages from '@/hooks/useUploadInlineImages'
import { journalyMiddleware } from '@/lib/journalyMiddleware'
import { getUiLanguage } from '@/utils/getUiLanguage'

const EditPostPage: NextPage = () => {
const router = useRouter()
Expand Down Expand Up @@ -123,19 +129,15 @@ const EditPostPage: NextPage = () => {
clear()
setSaving(false)
router.push({ pathname: `/post/${postId}` })
}, [
setSaving,
setErrorMessage,
dataRef,
uploadInlineImages,
updatePost,
router,
])

const onSaveClick = React.useCallback((e: React.MouseEvent) => {
e.preventDefault()
savePost()
}, [savePost])
}, [setSaving, setErrorMessage, dataRef, uploadInlineImages, updatePost, router])

const onSaveClick = React.useCallback(
(e: React.MouseEvent) => {
e.preventDefault()
savePost()
},
[savePost],
)

return (
<AuthGate>
Expand Down Expand Up @@ -225,8 +227,32 @@ const EditPostPage: NextPage = () => {
)
}

EditPostPage.getInitialProps = async () => ({
namespacesRequired: ['common', 'post'],
})
EditPostPage.getInitialProps = async (ctx) => {
const props = await journalyMiddleware(ctx, async (apolloClient) => {
const idStr = ctx.query.id as string
const id = parseInt(idStr, 10)

await apolloClient.query({
query: PostPageDocument,
variables: {
id,
uiLanguage: getUiLanguage(ctx),
},
})

await apolloClient.query({
query: EditPostDocument,
variables: {
id,
uiLanguage: getUiLanguage(ctx),
},
})
})

return {
...props,
namespacesRequired: ['common', 'post'],
}
}

export default withApollo(EditPostPage)
export default EditPostPage
6 changes: 0 additions & 6 deletions packages/web/pages/post/[id]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,6 @@ PostPage.getInitialProps = async (ctx) => {
const idStr = ctx.query.id as string
const id = parseInt(idStr, 10)

// const uiLanguage = useUILanguage()

// const { i18n: { language } } = React.useContext(I18nContext)

// return langCodeToUILangMap[language] || UILanguage.English

await apolloClient.query({
query: PostPageDocument,
variables: {
Expand Down
29 changes: 23 additions & 6 deletions packages/web/pages/post/private/[id]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ import React from 'react'
import { NextPage } from 'next'
import { useRouter } from 'next/router'

import { withApollo } from '@/lib/apollo'
import Post from '@/components/Dashboard/Post'
import LoadingWrapper from '@/components/LoadingWrapper'
import DashboardLayout from '@/components/Layouts/DashboardLayout'
import { usePrivatePostPageQuery } from '@/generated/graphql'
import { PostPageDocument, usePrivatePostPageQuery } from '@/generated/graphql'
import PostAuthorCard from '@/components/Dashboard/Post/PostAuthorCard'
import PostComments from '@/components/Dashboard/Post/PostComments'
import useUILanguage from '@/hooks/useUILanguage'
import theme from '@/theme'
import { journalyMiddleware } from '@/lib/journalyMiddleware'
import { getUiLanguage } from '@/utils/getUiLanguage'

const PostPage: NextPage = () => {
const privateShareId = useRouter().query.id as string
Expand Down Expand Up @@ -66,8 +67,24 @@ const PostPage: NextPage = () => {
)
}

PostPage.getInitialProps = async () => ({
namespacesRequired: ['common', 'post', 'comment', 'post-author-card'],
})
PostPage.getInitialProps = async (ctx) => {
const props = await journalyMiddleware(ctx, async (apolloClient) => {
const idStr = ctx.query.id as string
const id = parseInt(idStr, 10)

export default withApollo(PostPage)
await apolloClient.query({
query: PostPageDocument,
variables: {
id,
uiLanguage: getUiLanguage(ctx),
},
})
})

return {
...props,
namespacesRequired: ['common', 'post', 'comment', 'post-author-card'],
}
}

export default PostPage

0 comments on commit 73e637e

Please sign in to comment.