The History PR: I - Move to redux (#1156)

This commit is contained in:
Erik Michelson 2021-04-22 22:46:24 +02:00 committed by GitHub
parent bba2b207c4
commit 8e5a667d18
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
24 changed files with 629 additions and 417 deletions

View file

@ -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)
}