overleaf/services/web/frontend/js/features/file-tree/util/sync-mutation.js
Timothée Alby 420aa4a657 Merge pull request #3232 from overleaf/ta-file-tree-react
React File Tree

GitOrigin-RevId: fb3141ba8cd9ca0d68e87edb74764a360144c8fe
2020-11-27 03:05:05 +00:00

43 lines
1.1 KiB
JavaScript

import { postJSON, deleteJSON } from '../../../infrastructure/fetch-json'
export function syncRename(projectId, entityType, entityId, newName) {
return postJSON(
`/project/${projectId}/${getEntityPathName(entityType)}/${entityId}/rename`,
{
body: {
name: newName
}
}
)
}
export function syncDelete(projectId, entityType, entityId) {
return deleteJSON(
`/project/${projectId}/${getEntityPathName(entityType)}/${entityId}`
)
}
export function syncMove(projectId, entityType, entityId, toFolderId) {
return postJSON(
`/project/${projectId}/${getEntityPathName(entityType)}/${entityId}/move`,
{
body: {
folder_id: toFolderId
}
}
)
}
export function syncCreateEntity(projectId, parentFolderId, newEntityData) {
const { endpoint, ...newEntity } = newEntityData
return postJSON(`/project/${projectId}/${endpoint}`, {
body: {
parent_folder_id: parentFolderId,
...newEntity
}
})
}
function getEntityPathName(entityType) {
return entityType === 'fileRef' ? 'file' : entityType
}