Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrobonamin committed Sep 30, 2024
1 parent d2ca86d commit 3f67c7e
Show file tree
Hide file tree
Showing 6 changed files with 1,571 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,24 @@ const getTimelineController = ({
})
}

// TODO: This is not used, remove it?
const getTransactions = async (
client: SanityClient,
documentIds: string | string[],
): Promise<TransactionLogEventWithMutations[]> => {
const ids = Array.isArray(documentIds) ? documentIds : [documentIds]
const dataset = client.config().dataset
const query = {excludeContent: 'true', includeIdentifiedDocumentsOnly: 'true'}
// https://www.sanity.io/docs/history-api#45ac5eece4ca
const query = {
excludeContent: 'true',
includeIdentifiedDocumentsOnly: 'true',
tag: 'sanity.studio.structure.transactions',
effectFormat: 'mendoza',
excludeMutations: 'true',
reverse: 'true',
limit: '50',
}

const url = `/data/history/${dataset}/transactions/${ids.join(',')}`
const result = await client.request({url, query})
const transactions = result
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
BehaviorSubject,
catchError,
distinctUntilChanged,
from,
map,
of,
type Subscription,
Expand All @@ -14,6 +15,7 @@ import {
import {
type Annotation,
type Chunk,
getDraftId,
type SelectionState,
type TimelineController,
useHistoryStore,
Expand All @@ -23,6 +25,7 @@ import {useClient} from '../../../hooks'
import {DEFAULT_STUDIO_CLIENT_OPTIONS} from '../../../studioClient'
import {remoteSnapshots, type RemoteSnapshotVersionEvent} from '../document'
import {fetchFeatureToggle} from '../document/document-pair/utils/fetchFeatureToggle'
import {useObservable} from 'react-rx'

interface UseTimelineControllerOpts {
documentId: string
Expand Down Expand Up @@ -104,6 +107,12 @@ export function useTimelineStore({
const client = useClient(DEFAULT_STUDIO_CLIENT_OPTIONS)
const workspace = useWorkspace()

const transactions$ = useMemo(() => {
return from(historyStore.getTransactions([documentId, getDraftId(documentId)]))
}, [historyStore, documentId])

const transactions = useObservable(transactions$)
console.log('transactions', transactions)
/**
* The mutable TimelineController, used internally
*/
Expand Down
Loading

0 comments on commit 3f67c7e

Please sign in to comment.