Skip to content

Commit

Permalink
refactor(inputs): update new patch observable type for PTE
Browse files Browse the repository at this point in the history
  • Loading branch information
skogsmaskin committed Aug 11, 2022
1 parent 8bda33a commit e7f36a5
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions packages/sanity/src/form/inputs/PortableText/PortableTextInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,11 @@ export function PortableTextInput(props: PortableTextInputProps) {
const portableTextMemberItemsRef: React.MutableRefObject<PortableTextMemberItem[]> = useRef([])

// Memoized patch stream
const remotePatchSubject: Subject<EditorPatch> = useMemo(() => new Subject(), [])
const remotePatch$ = useMemo(() => remotePatchSubject.asObservable(), [remotePatchSubject])
const patchSubject: Subject<{
patches: EditorPatch[]
snapshot: PortableTextBlock[] | undefined
}> = useMemo(() => new Subject(), [])
const remotePatch$ = useMemo(() => patchSubject.asObservable(), [patchSubject])

const innerElementRef = useRef<HTMLDivElement | null>(null)

Expand All @@ -133,17 +136,12 @@ export function PortableTextInput(props: PortableTextInputProps) {
}
}, [invalidValue, value])

// Subscribe to incoming patches
// Subscribe to patches
useEffect(() => {
return subscribe(({patches}): void => {
const patchSelection =
patches && patches.length > 0 && patches.filter((patch) => patch.origin !== 'local')

if (patchSelection) {
patchSelection.map((patch) => remotePatchSubject.next(patch))
}
return subscribe(({patches, snapshot}): void => {
patchSubject.next({patches, snapshot})
})
}, [remotePatchSubject, subscribe])
}, [patchSubject, subscribe])

// Populate the portableTextMembers Map
const portableTextMemberItems: PortableTextMemberItem[] = useMemo(() => {
Expand Down

0 comments on commit e7f36a5

Please sign in to comment.