mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-06-02 16:09:59 -04:00
The History PR: I - Move to redux (#1156)
This commit is contained in:
parent
bba2b207c4
commit
8e5a667d18
24 changed files with 629 additions and 417 deletions
|
@ -4,22 +4,37 @@
|
|||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
import { HistoryEntry } from '../../components/history-page/history-page'
|
||||
import { defaultFetchConfig, expectResponseCode, getApiUrl } from '../utils'
|
||||
import { HistoryEntryDto, HistoryEntryPutDto, HistoryEntryUpdateDto } from './types'
|
||||
|
||||
export const getHistory = async (): Promise<HistoryEntry[]> => {
|
||||
export const getHistory = async (): Promise<HistoryEntryDto[]> => {
|
||||
const response = await fetch(getApiUrl() + '/history')
|
||||
expectResponseCode(response)
|
||||
return await response.json() as Promise<HistoryEntry[]>
|
||||
return await response.json() as Promise<HistoryEntryDto[]>
|
||||
}
|
||||
|
||||
export const setHistory = async (entries: HistoryEntry[]): Promise<void> => {
|
||||
export const postHistory = async (entries: HistoryEntryPutDto[]): Promise<void> => {
|
||||
const response = await fetch(getApiUrl() + '/history', {
|
||||
...defaultFetchConfig,
|
||||
method: 'POST',
|
||||
body: JSON.stringify({
|
||||
history: entries
|
||||
})
|
||||
body: JSON.stringify(entries)
|
||||
})
|
||||
expectResponseCode(response)
|
||||
}
|
||||
|
||||
export const updateHistoryEntryPinStatus = async (noteId: string, entry: HistoryEntryUpdateDto): Promise<void> => {
|
||||
const response = await fetch(getApiUrl() + '/history/' + noteId, {
|
||||
...defaultFetchConfig,
|
||||
method: 'PUT',
|
||||
body: JSON.stringify(entry)
|
||||
})
|
||||
expectResponseCode(response)
|
||||
}
|
||||
|
||||
export const deleteHistoryEntry = async (noteId: string): Promise<void> => {
|
||||
const response = await fetch(getApiUrl() + '/history/' + noteId, {
|
||||
...defaultFetchConfig,
|
||||
method: 'DELETE'
|
||||
})
|
||||
expectResponseCode(response)
|
||||
}
|
||||
|
@ -31,21 +46,3 @@ export const deleteHistory = async (): Promise<void> => {
|
|||
})
|
||||
expectResponseCode(response)
|
||||
}
|
||||
|
||||
export const updateHistoryEntry = async (noteId: string, entry: HistoryEntry): Promise<HistoryEntry> => {
|
||||
const response = await fetch(getApiUrl() + '/history/' + noteId, {
|
||||
...defaultFetchConfig,
|
||||
method: 'PUT',
|
||||
body: JSON.stringify(entry)
|
||||
})
|
||||
expectResponseCode(response)
|
||||
return await response.json() as Promise<HistoryEntry>
|
||||
}
|
||||
|
||||
export const deleteHistoryEntry = async (noteId: string): Promise<void> => {
|
||||
const response = await fetch(getApiUrl() + '/history/' + noteId, {
|
||||
...defaultFetchConfig,
|
||||
method: 'DELETE'
|
||||
})
|
||||
expectResponseCode(response)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue