mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-21 10:45:20 -04:00
Fix Communication between frontend and backend (#1201)
Co-authored-by: Tilman Vatteroth <git@tilmanvatteroth.de> Signed-off-by: Philip Molares <philip.molares@udo.edu> Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
This commit is contained in:
parent
4a18e51c83
commit
9cf7980334
38 changed files with 268 additions and 164 deletions
|
@ -8,7 +8,7 @@ import { Reducer } from 'redux'
|
|||
import { BannerActions, BannerActionType, BannerState, SetBannerAction } from './types'
|
||||
|
||||
export const initialState: BannerState = {
|
||||
show: true,
|
||||
show: false,
|
||||
text: '',
|
||||
timestamp: ''
|
||||
}
|
||||
|
|
|
@ -40,15 +40,15 @@ export const initialState: Config = {
|
|||
maxDocumentLength: 0,
|
||||
useImageProxy: false,
|
||||
plantumlServer: null,
|
||||
specialLinks: {
|
||||
specialUrls: {
|
||||
privacy: '',
|
||||
termsOfUse: '',
|
||||
imprint: ''
|
||||
},
|
||||
version: {
|
||||
version: '',
|
||||
sourceCodeUrl: '',
|
||||
issueTrackerUrl: ''
|
||||
major: -1,
|
||||
minor: -1,
|
||||
patch: -1,
|
||||
},
|
||||
iframeCommunication: {
|
||||
editorOrigin: '',
|
||||
|
|
|
@ -91,8 +91,8 @@ export const toggleHistoryEntryPinning = async (noteId: string): Promise<void> =
|
|||
updateLocalHistoryEntry(noteId, entryToUpdate)
|
||||
} else {
|
||||
const historyUpdateDto = historyEntryToHistoryEntryUpdateDto(entryToUpdate)
|
||||
updateHistoryEntryRedux(noteId, entryToUpdate)
|
||||
await updateHistoryEntryPinStatus(noteId, historyUpdateDto)
|
||||
updateHistoryEntryRedux(noteId, entryToUpdate)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
*/
|
||||
|
||||
import { store } from '..'
|
||||
import { Note } from '../../api/notes'
|
||||
import { NoteDto } from '../../api/notes/types'
|
||||
import { NoteFrontmatter } from '../../components/editor-page/note-frontmatter/note-frontmatter'
|
||||
import { initialState } from './reducers'
|
||||
import {
|
||||
|
@ -24,7 +24,7 @@ export const setNoteMarkdownContent = (content: string): void => {
|
|||
} as SetNoteDetailsAction)
|
||||
}
|
||||
|
||||
export const setNoteDataFromServer = (apiResponse: Note): void => {
|
||||
export const setNoteDataFromServer = (apiResponse: NoteDto): void => {
|
||||
store.dispatch({
|
||||
type: NoteDetailsActionType.SET_NOTE_DATA_FROM_SERVER,
|
||||
note: apiResponse
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
|
||||
import { DateTime } from 'luxon'
|
||||
import { Reducer } from 'redux'
|
||||
import { Note } from '../../api/notes'
|
||||
import {
|
||||
NoteFrontmatter,
|
||||
NoteTextDirection,
|
||||
|
@ -22,6 +21,7 @@ import {
|
|||
SetNoteFrontmatterFromRenderingAction,
|
||||
UpdateNoteTitleByFirstHeadingAction
|
||||
} from './types'
|
||||
import { noteDtoToNoteDetails } from '../../api/notes/dto-methods'
|
||||
|
||||
export const initialState: NoteDetails = {
|
||||
markdownContent: '',
|
||||
|
@ -29,10 +29,9 @@ export const initialState: NoteDetails = {
|
|||
createTime: DateTime.fromSeconds(0),
|
||||
lastChange: {
|
||||
timestamp: DateTime.fromSeconds(0),
|
||||
userId: ''
|
||||
userName: ''
|
||||
},
|
||||
alias: '',
|
||||
preVersionTwoNote: false,
|
||||
viewCount: 0,
|
||||
authorship: [],
|
||||
noteTitle: '',
|
||||
|
@ -67,7 +66,7 @@ export const NoteDetailsReducer: Reducer<NoteDetails, NoteDetailsAction> = (stat
|
|||
noteTitle: generateNoteTitle(state.frontmatter, (action as UpdateNoteTitleByFirstHeadingAction).firstHeading)
|
||||
}
|
||||
case NoteDetailsActionType.SET_NOTE_DATA_FROM_SERVER:
|
||||
return convertNoteToNoteDetails((action as SetNoteDetailsFromServerAction).note)
|
||||
return noteDtoToNoteDetails((action as SetNoteDetailsFromServerAction).note)
|
||||
case NoteDetailsActionType.SET_NOTE_FRONTMATTER:
|
||||
return {
|
||||
...state,
|
||||
|
@ -111,21 +110,4 @@ const generateNoteTitle = (frontmatter: NoteFrontmatter, firstHeading?: string)
|
|||
}
|
||||
}
|
||||
|
||||
const convertNoteToNoteDetails = (note: Note): NoteDetails => {
|
||||
return {
|
||||
markdownContent: note.content,
|
||||
frontmatter: initialState.frontmatter,
|
||||
id: note.id,
|
||||
noteTitle: initialState.noteTitle,
|
||||
createTime: DateTime.fromSeconds(note.createTime),
|
||||
lastChange: {
|
||||
userId: note.lastChange.userId,
|
||||
timestamp: DateTime.fromSeconds(note.lastChange.timestamp)
|
||||
},
|
||||
firstHeading: initialState.firstHeading,
|
||||
preVersionTwoNote: note.preVersionTwoNote,
|
||||
viewCount: note.viewCount,
|
||||
alias: note.alias,
|
||||
authorship: note.authorship
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
|
||||
import { DateTime } from 'luxon'
|
||||
import { Action } from 'redux'
|
||||
import { Note } from '../../api/notes'
|
||||
import { NoteFrontmatter } from '../../components/editor-page/note-frontmatter/note-frontmatter'
|
||||
import { NoteDto } from '../../api/notes/types'
|
||||
|
||||
export enum NoteDetailsActionType {
|
||||
SET_DOCUMENT_CONTENT = 'note-details/set',
|
||||
|
@ -18,7 +18,7 @@ export enum NoteDetailsActionType {
|
|||
}
|
||||
|
||||
interface LastChange {
|
||||
userId: string
|
||||
userName: string
|
||||
timestamp: DateTime
|
||||
}
|
||||
|
||||
|
@ -27,10 +27,9 @@ export interface NoteDetails {
|
|||
id: string
|
||||
createTime: DateTime
|
||||
lastChange: LastChange
|
||||
preVersionTwoNote: boolean
|
||||
viewCount: number
|
||||
alias: string
|
||||
authorship: number[]
|
||||
authorship: string[]
|
||||
noteTitle: string
|
||||
firstHeading?: string
|
||||
frontmatter: NoteFrontmatter
|
||||
|
@ -47,7 +46,7 @@ export interface SetNoteDetailsAction extends NoteDetailsAction {
|
|||
|
||||
export interface SetNoteDetailsFromServerAction extends NoteDetailsAction {
|
||||
type: NoteDetailsActionType.SET_NOTE_DATA_FROM_SERVER
|
||||
note: Note
|
||||
note: NoteDto
|
||||
}
|
||||
|
||||
export interface UpdateNoteTitleByFirstHeadingAction extends NoteDetailsAction {
|
||||
|
|
|
@ -39,9 +39,7 @@ export const dismissUiNotification = (notificationId: number): void => {
|
|||
} as DismissUiNotificationAction)
|
||||
}
|
||||
|
||||
// Promises catch errors as any.
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any,@typescript-eslint/explicit-module-boundary-types
|
||||
export const showErrorNotification = (message: string) => (error: any): void => {
|
||||
export const showErrorNotification = (message: string) => (error: Error): void => {
|
||||
console.error(message, error)
|
||||
dispatchUiNotification(i18n.t('common.errorOccurred'), message, DEFAULT_DURATION_IN_SECONDS, 'exclamation-triangle')
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue