Files
overleaf-cep/services/web/frontend/js/features/history/services/api.ts
Tim Down b612ad09f5 Connect up document diff viewer to history state
GitOrigin-RevId: 610a254ea77c194969033d0791ecf1129e02c4bf
2023-03-31 08:03:47 +00:00

47 lines
1.4 KiB
TypeScript

import { getJSON } from '../../../infrastructure/fetch-json'
import { FileDiff } from './types/file'
import { Update } from './types/update'
import { DocDiffResponse } from './types/doc'
const BATCH_SIZE = 10
export function fetchUpdates(projectId: string, before?: number) {
const queryParams: Record<string, string> = {
min_count: BATCH_SIZE.toString(),
}
if (before != null) {
queryParams.before = before.toString()
}
const queryParamsSerialized = new URLSearchParams(queryParams).toString()
const updatesURL = `/project/${projectId}/updates?${queryParamsSerialized}`
return getJSON<{ updates: Update[] }>(updatesURL)
}
export function diffFiles(projectId: string, fromV: number, toV: number) {
const queryParams: Record<string, string> = {
from: fromV.toString(),
to: toV.toString(),
}
const queryParamsSerialized = new URLSearchParams(queryParams).toString()
const diffUrl = `/project/${projectId}/filetree/diff?${queryParamsSerialized}`
return getJSON<{ diff: FileDiff[] }>(diffUrl)
}
export function diffDoc(
projectId: string,
fromV: number,
toV: number,
pathname: string
) {
const queryParams: Record<string, string> = {
from: fromV.toString(),
to: toV.toString(),
pathname,
}
const queryParamsSerialized = new URLSearchParams(queryParams).toString()
const diffUrl = `/project/${projectId}/diff?${queryParamsSerialized}`
return getJSON<DocDiffResponse>(diffUrl)
}