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(sanity): add changes to allow for comments in version documents #7404

Merged
merged 8 commits into from
Aug 27, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,9 @@ export const CommentsListItem = memo(function CommentsListItem(props: CommentsLi
}
}, [replies])

/* TODO - once we understand how to set up with "finished" releases
we need to add a condition to the readOnly prop in this component */

const renderedReplies = useMemo(
() =>
splicedReplies.map((reply) => (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {CommentsContext} from 'sanity/_singletons'
import {useEditState, useSchema, useUserListWithPermissions} from '../../../hooks'
import {useCurrentUser} from '../../../store'
import {useAddonDataset, useWorkspace} from '../../../studio'
import {getPublishedId} from '../../../util'
import {
type CommentOperationsHookOptions,
useCommentOperations,
Expand Down Expand Up @@ -84,7 +83,7 @@ export const CommentsProvider = memo(function CommentsProvider(props: CommentsPr
const commentsEnabled = useCommentsEnabled()
const [status, setStatus] = useState<CommentStatus>('open')
const {client, createAddonDataset, isCreatingDataset} = useAddonDataset()
const publishedId = getPublishedId(documentId)
const publishedId = documentId
RitaDias marked this conversation as resolved.
Show resolved Hide resolved

const bundlePerspective = perspective?.startsWith('bundle.')
? perspective.split('bundle.').at(1)
Expand Down
5 changes: 2 additions & 3 deletions packages/sanity/src/core/comments/store/useCommentsStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {type ListenEvent, type ListenOptions, type SanityClient} from '@sanity/c
import {useCallback, useEffect, useMemo, useReducer, useRef, useState} from 'react'
import {catchError, of} from 'rxjs'

import {getPublishedId} from '../../util'
import {type CommentDocument, type Loadable} from '../types'
import {commentsReducer, type CommentsReducerAction, type CommentsReducerState} from './reducer'

Expand Down Expand Up @@ -64,7 +63,7 @@ export function useCommentsStore(opts: CommentsStoreOptions): CommentsStoreRetur

const didInitialFetch = useRef<boolean>(false)

const params = useMemo(() => ({documentId: getPublishedId(documentId)}), [documentId])
const params = useMemo(() => ({documentId: documentId}), [documentId])

const initialFetch = useCallback(async () => {
if (!client) {
Expand All @@ -84,7 +83,7 @@ export function useCommentsStore(opts: CommentsStoreOptions): CommentsStoreRetur
const handleListenerEvent = useCallback(
async (event: ListenEvent<Record<string, CommentDocument>>) => {
// Fetch all comments on initial connection
if (event.type === 'welcome' && !didInitialFetch.current) {
if (event.type === 'welcome') {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

needed to remove it in order for the comments to be refetched on switching perspectives in a document

Screen.Recording.2024-08-26.at.13.42.37.mov

Copy link
Contributor

Choose a reason for hiding this comment

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

Good catch, let's discuss in slack

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you ping the other reviewers when you come to a conclusion on this? 🙂

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll be making this change 🔜

setLoading(true)
await initialFetch()
setLoading(false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
COMMENTS_INSPECTOR_NAME,
CommentsEnabledProvider,
CommentsProvider,
getVersionId,
useCommentsEnabled,
} from 'sanity'
import {useRouter} from 'sanity/router'
Expand Down Expand Up @@ -37,10 +38,11 @@ function CommentsProviderWrapper(props: CommentsWrapperProps) {
const {children, documentId, documentType} = props

const {enabled} = useCommentsEnabled()
const {connectionState, onPathOpen, inspector, openInspector} = useDocumentPane()
const {connectionState, onPathOpen, inspector, openInspector, version} = useDocumentPane()
const router = useRouter()
const {params, setParams, createPathWithParams, ...paneRouter} = usePaneRouter()
const perspective = paneRouter.perspective ?? router.stickyParams.perspective
const docId = version ? getVersionId(documentId, version) : documentId
RitaDias marked this conversation as resolved.
Show resolved Hide resolved

const selectedCommentId = params?.comment
const paramsRef = useRef(params)
Expand Down Expand Up @@ -82,7 +84,7 @@ function CommentsProviderWrapper(props: CommentsWrapperProps) {

return (
<CommentsProvider
documentId={documentId}
documentId={docId}
documentType={documentType}
getCommentLink={getCommentLink}
isCommentsOpen={inspector?.name === COMMENTS_INSPECTOR_NAME}
Expand Down
Loading