-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathuseRevisions.ts
More file actions
35 lines (31 loc) · 1.04 KB
/
useRevisions.ts
File metadata and controls
35 lines (31 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import apiClient from '@/repositories/apiClient';
import { useMutation, useQuery } from '@tanstack/react-query';
// Revision Type
export interface Revision {
id: number;
article_id: number;
content: string;
created_at: string;
}
// Fetch Revisions
export const useRevisions = (articleId: number) =>
useQuery<Revision[]>(["revisions", articleId], async () => {
const { data } = await apiClient.get(`/articles/${articleId}/revisions`);
return data;
});
// Fetch Single Revision
export const useRevision = (articleId: number, revisionId: number) =>
useQuery<Revision>(["revision", articleId, revisionId], async () => {
const { data } = await apiClient.get(
`/articles/${articleId}/revisions/${revisionId}`
);
return data;
});
// Revert to a Revision
export const useRevertRevision = () =>
useMutation(async ({ articleId, revisionId }: { articleId: number; revisionId: number }) => {
const { data } = await apiClient.post(
`/articles/${articleId}/revisions/${revisionId}/revert`
);
return data;
});