Skip to content

Commit

Permalink
chore: sync up remaining changes
Browse files Browse the repository at this point in the history
  • Loading branch information
stipsan committed Dec 4, 2024
1 parent cc4e393 commit 62fced2
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 71 deletions.
6 changes: 2 additions & 4 deletions packages/presentation/src/PostMessageDocumentVersions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ import type {VisualEditingConnection} from './types'
export interface PostMessageDocumentVersionsProps {
comlink: VisualEditingConnection
perspective: ClientPerspective
bundlesPerspective: string[]
}

const PostMessageDocumentVersions: FC<PostMessageDocumentVersionsProps> = (props) => {
const {comlink, perspective, bundlesPerspective} = props
const {comlink, perspective} = props

const client = useClient({apiVersion: 'vX'})

Expand All @@ -31,11 +30,10 @@ const PostMessageDocumentVersions: FC<PostMessageDocumentVersionsProps> = (props

return {
versions: res,
bundlesPerspective,
perspective,
}
})
}, [bundlesPerspective, client, comlink, perspective])
}, [client, comlink, perspective])

return null
}
Expand Down
6 changes: 2 additions & 4 deletions packages/presentation/src/PostMessageReleases.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,23 @@ import type {VisualEditingConnection} from './types'
export interface PostMessageReleasesProps {
comlink: VisualEditingConnection
perspective: ClientPerspective
bundlesPerspective: string[]
}

const PostMessageReleases: FC<PostMessageReleasesProps> = (props) => {
const {comlink, perspective, bundlesPerspective} = props
const {comlink, perspective} = props

const releases = useReleases()

useEffect(() => {
const run = async () => {
comlink.post('presentation/releases', {
releases: releases.data,
bundlesPerspective,
perspective,
})
}

run()
}, [bundlesPerspective, comlink, perspective, releases.data])
}, [comlink, perspective, releases.data])

return null
}
Expand Down
21 changes: 3 additions & 18 deletions packages/presentation/src/PresentationTool.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,6 @@ export default function PresentationTool(props: {
liveDocument={displayedDocument}
onDocumentsOnPage={setDocumentsOnPage}
onLoadersConnection={setLoadersConnection}
bundlesPerspective={bundlesPerspective}
/>
) : (
<LoaderQueries
Expand All @@ -558,7 +557,6 @@ export default function PresentationTool(props: {
onDocumentsOnPage={setDocumentsOnPage}
onLoadersConnection={setLoadersConnection}
documentsOnPage={documentsOnPage}
bundlesPerspective={bundlesPerspective}
/>
)}
</Suspense>
Expand All @@ -576,11 +574,7 @@ export default function PresentationTool(props: {
)}
{visualEditingComlink && (
<Suspense>
<PostMessageSchema
comlink={visualEditingComlink}
perspective={perspective}
bundlesPerspective={bundlesPerspective}
/>
<PostMessageSchema comlink={visualEditingComlink} perspective={perspective} />
</Suspense>
)}
{visualEditingComlink && documentsOnPage.length > 0 && (
Expand All @@ -589,7 +583,6 @@ export default function PresentationTool(props: {
comlink={visualEditingComlink}
perspective={perspective}
refs={documentsOnPage}
bundlesPerspective={bundlesPerspective}
/>
</Suspense>
)}
Expand All @@ -605,20 +598,12 @@ export default function PresentationTool(props: {
)}
{visualEditingComlink && (
<Suspense>
<PostMessageReleases
comlink={visualEditingComlink}
perspective={perspective}
bundlesPerspective={bundlesPerspective}
/>
<PostMessageReleases comlink={visualEditingComlink} perspective={perspective} />
</Suspense>
)}
{visualEditingComlink && (
<Suspense>
<PostMessageDocumentVersions
comlink={visualEditingComlink}
perspective={perspective}
bundlesPerspective={bundlesPerspective}
/>
<PostMessageDocumentVersions comlink={visualEditingComlink} perspective={perspective} />
</Suspense>
)}
{visualEditingComlink && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ type Ref = {
export interface PostMessagePreviewsProps {
comlink: VisualEditingConnection
perspective: ClientPerspective
bundlesPerspective: string[]
refs: Ref[]
}

Expand Down
25 changes: 4 additions & 21 deletions packages/presentation/src/loader/LiveQueries.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ export interface LoaderQueriesProps {
liveDocument: Partial<SanityDocument> | null | undefined
controller: Controller | undefined
perspective: ClientPerspective
bundlesPerspective: string[]
onLoadersConnection: (event: StatusEvent) => void
onDocumentsOnPage: (
key: string,
Expand All @@ -61,7 +60,6 @@ export default function LoaderQueries(props: LoaderQueriesProps): JSX.Element {
controller,
perspective: activePerspective,
onLoadersConnection,
bundlesPerspective,
onDocumentsOnPage,
} = props

Expand Down Expand Up @@ -251,7 +249,6 @@ export default function LoaderQueries(props: LoaderQueriesProps): JSX.Element {
key={`${key}${perspective}`}
projectId={clientConfig.projectId!}
dataset={clientConfig.dataset!}
bundlesPerspective={bundlesPerspective}
perspective={perspective}
query={query}
params={params}
Expand All @@ -277,7 +274,6 @@ interface QuerySubscriptionProps
extends Pick<UseQuerySubscriptionProps, 'client' | 'liveDocument' | 'lastLiveEventId'> {
projectId: string
dataset: string
bundlesPerspective: string[]
perspective: ClientPerspective
query: string
params: QueryParams
Expand All @@ -288,7 +284,6 @@ function QuerySubscriptionComponent(props: QuerySubscriptionProps) {
const {
projectId,
dataset,
bundlesPerspective,
perspective,
query,
client,
Expand All @@ -307,7 +302,6 @@ function QuerySubscriptionComponent(props: QuerySubscriptionProps) {
client,
liveDocument,
params,
bundlesPerspective,
perspective,
query,
lastLiveEventId,
Expand Down Expand Up @@ -368,13 +362,11 @@ interface UseQuerySubscriptionProps extends Required<Pick<SharedProps, 'client'>
liveDocument: Partial<SanityDocument> | null | undefined
query: string
params: QueryParams
bundlesPerspective: string[]
perspective: ClientPerspective
lastLiveEventId: string | null
}
function useQuerySubscription(props: UseQuerySubscriptionProps) {
const {liveDocument, client, query, params, perspective, lastLiveEventId, bundlesPerspective} =
props
const {liveDocument, client, query, params, perspective, lastLiveEventId} = props
const [snapshot, setSnapshot] = useState<{
result: unknown
resultSourceMap?: ContentSourceMap
Expand Down Expand Up @@ -409,7 +401,7 @@ function useQuerySubscription(props: UseQuerySubscriptionProps) {
lastLiveEventId,
tag: 'presentation-loader',
signal,
perspective: undefined,
perspective,
filterResponse: false,
returnQuery: false,
})
Expand Down Expand Up @@ -441,16 +433,7 @@ function useQuerySubscription(props: UseQuerySubscriptionProps) {
controller.abort()
}
}
}, [
client,
lastLiveEventId,
params,
perspective,
query,
shouldRefetch,
startRefresh,
bundlesPerspective,
])
}, [client, lastLiveEventId, params, perspective, query, shouldRefetch, startRefresh])

const {result, resultSourceMap, syncTags} = snapshot ?? {}
return useMemo(() => {
Expand Down Expand Up @@ -497,7 +480,7 @@ export function turboChargeResultIfSourceMap<T = unknown>(
}
return changedValue
},
// TODO: Update applySourceDocuments to support bundlePerspective.
// TODO: Update applySourceDocuments to support releases.
Array.isArray(perspective) &&
perspective.some((part) => typeof part === 'string' && part.startsWith('r') && part !== 'raw')
? 'previewDrafts'
Expand Down
13 changes: 2 additions & 11 deletions packages/presentation/src/loader/LoaderQueries.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ export interface LoaderQueriesProps {
liveDocument: Partial<SanityDocument> | null | undefined
controller: Controller | undefined
perspective: ClientPerspective
bundlesPerspective: string[]
documentsOnPage: {_id: string; _type: string}[]
onLoadersConnection: (event: StatusEvent) => void
onDocumentsOnPage: (
Expand All @@ -62,7 +61,6 @@ export default function LoaderQueries(props: LoaderQueriesProps): JSX.Element {
liveDocument,
controller,
perspective: activePerspective,
bundlesPerspective,
documentsOnPage,
onLoadersConnection,
onDocumentsOnPage,
Expand Down Expand Up @@ -209,7 +207,6 @@ export default function LoaderQueries(props: LoaderQueriesProps): JSX.Element {
cache={cache}
projectId={clientConfig.projectId!}
dataset={clientConfig.dataset!}
bundlesPerspective={bundlesPerspective}
perspective={perspective}
query={query}
params={params}
Expand Down Expand Up @@ -350,7 +347,6 @@ interface QuerySubscriptionProps
projectId: string
dataset: string
perspective: ClientPerspective
bundlesPerspective: string[]
query: string
params: QueryParams
comlink: LoaderConnection | undefined
Expand All @@ -361,7 +357,6 @@ function QuerySubscription(props: QuerySubscriptionProps) {
projectId,
dataset,
perspective,
bundlesPerspective,
query,
client,
refreshInterval,
Expand All @@ -376,7 +371,6 @@ function QuerySubscription(props: QuerySubscriptionProps) {
client,
liveDocument,
params,
bundlesPerspective,
perspective,
query,
refreshInterval,
Expand Down Expand Up @@ -409,7 +403,6 @@ interface UseQuerySubscriptionProps
liveDocument: Partial<SanityDocument> | null | undefined
query: string
params: QueryParams
bundlesPerspective: string[]
perspective: ClientPerspective
documentsCacheLastUpdated: number
}
Expand All @@ -421,7 +414,6 @@ function useQuerySubscription(props: UseQuerySubscriptionProps) {
refreshInterval,
query,
params,
bundlesPerspective,
perspective,
documentsCacheLastUpdated,
} = props
Expand Down Expand Up @@ -456,7 +448,7 @@ function useQuerySubscription(props: UseQuerySubscriptionProps) {
const {result, resultSourceMap, syncTags} = await client.fetch(query, params, {
tag: 'presentation-loader',
signal,
perspective: undefined,
perspective,
filterResponse: false,
})
fetching = false
Expand Down Expand Up @@ -487,7 +479,6 @@ function useQuerySubscription(props: UseQuerySubscriptionProps) {
liveDocument,
params,
perspective,
bundlesPerspective,
projectId,
query,
shouldRefetch,
Expand Down Expand Up @@ -556,7 +547,7 @@ export function turboChargeResultIfSourceMap<T = unknown>(
}
return changedValue
},
// TODO: Update applySourceDocuments to support bundlePerspective.
// TODO: Update applySourceDocuments to support releases.
Array.isArray(perspective) &&
perspective.some((part) => typeof part === 'string' && part.startsWith('r') && part !== 'raw')
? 'previewDrafts'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {extractSchema} from './extract'
export interface PostMessageSchemaProps {
comlink: VisualEditingConnection
perspective: ClientPerspective
bundlesPerspective: string[]
}

function getDocumentPathArray(paths: UnresolvedPath[]) {
Expand All @@ -34,7 +33,7 @@ function getDocumentPathArray(paths: UnresolvedPath[]) {
* over postMessage so it can be used to enrich the Visual Editing experience
*/
function PostMessageSchema(props: PostMessageSchemaProps): JSX.Element | null {
const {comlink, perspective, bundlesPerspective} = props
const {comlink, perspective} = props
const workspace = useWorkspace()
const theme = useRootTheme()

Expand Down Expand Up @@ -80,7 +79,7 @@ function PostMessageSchema(props: PostMessageSchemaProps): JSX.Element | null {
})
return {types: newState}
})
}, [comlink, client, perspective, bundlesPerspective])
}, [comlink, client, perspective])

return null
}
Expand Down
2 changes: 0 additions & 2 deletions packages/visual-editing-helpers/src/types/comlink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ export type VisualEditingControllerMsg =
type: 'presentation/releases'
data: {
perspective: ClientPerspective
bundlesPerspective: string[]
releases: unknown[]
}
}
Expand Down Expand Up @@ -285,7 +284,6 @@ export type VisualEditingNodeMsg =
data: {elements: string[]}
response: {
perspective: ClientPerspective
bundlesPerspective: string[]
versions: {
_id: string
versions: {_id: string}[]
Expand Down
Loading

0 comments on commit 62fced2

Please sign in to comment.