mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-20 18:25:21 -04:00
Improvement/move document content into redux (#691)
This commit is contained in:
parent
0750695e2f
commit
1690a7bdcf
15 changed files with 101 additions and 51 deletions
10
src/redux/document-content/methods.ts
Normal file
10
src/redux/document-content/methods.ts
Normal file
|
@ -0,0 +1,10 @@
|
|||
import { store } from '..'
|
||||
import { DocumentContentActionType, SetDocumentContentAction } from './types'
|
||||
|
||||
export const setDocumentContent = (content: string): void => {
|
||||
const action: SetDocumentContentAction = {
|
||||
type: DocumentContentActionType.SET_DOCUMENT_CONTENT,
|
||||
content: content
|
||||
}
|
||||
store.dispatch(action)
|
||||
}
|
15
src/redux/document-content/reducers.ts
Normal file
15
src/redux/document-content/reducers.ts
Normal file
|
@ -0,0 +1,15 @@
|
|||
import { Reducer } from 'redux'
|
||||
import { DocumentContent, DocumentContentAction, DocumentContentActionType, SetDocumentContentAction } from './types'
|
||||
|
||||
export const initialState: DocumentContent = {
|
||||
content: ''
|
||||
}
|
||||
|
||||
export const DocumentContentReducer: Reducer<DocumentContent, DocumentContentAction> = (state: DocumentContent = initialState, action: DocumentContentAction) => {
|
||||
switch (action.type) {
|
||||
case DocumentContentActionType.SET_DOCUMENT_CONTENT:
|
||||
return { content: (action as SetDocumentContentAction).content }
|
||||
default:
|
||||
return state
|
||||
}
|
||||
}
|
17
src/redux/document-content/types.ts
Normal file
17
src/redux/document-content/types.ts
Normal file
|
@ -0,0 +1,17 @@
|
|||
import { Action } from 'redux'
|
||||
|
||||
export enum DocumentContentActionType {
|
||||
SET_DOCUMENT_CONTENT = 'document-content/set',
|
||||
}
|
||||
|
||||
export interface DocumentContent {
|
||||
content: string
|
||||
}
|
||||
|
||||
export interface DocumentContentAction extends Action<DocumentContentActionType> {
|
||||
type: DocumentContentActionType
|
||||
}
|
||||
|
||||
export interface SetDocumentContentAction extends DocumentContentAction {
|
||||
content: string
|
||||
}
|
|
@ -7,6 +7,8 @@ import { BannerState } from './banner/types'
|
|||
import { ConfigReducer } from './config/reducers'
|
||||
import { DarkModeConfigReducer } from './dark-mode/reducers'
|
||||
import { DarkModeConfig } from './dark-mode/types'
|
||||
import { DocumentContentReducer } from './document-content/reducers'
|
||||
import { DocumentContent } from './document-content/types'
|
||||
import { EditorConfigReducer } from './editor/reducers'
|
||||
import { EditorConfig } from './editor/types'
|
||||
import { UserReducer } from './user/reducers'
|
||||
|
@ -19,6 +21,7 @@ export interface ApplicationState {
|
|||
apiUrl: ApiUrlObject;
|
||||
editorConfig: EditorConfig;
|
||||
darkMode: DarkModeConfig;
|
||||
documentContent: DocumentContent;
|
||||
}
|
||||
|
||||
export const allReducers: Reducer<ApplicationState> = combineReducers<ApplicationState>({
|
||||
|
@ -27,7 +30,8 @@ export const allReducers: Reducer<ApplicationState> = combineReducers<Applicatio
|
|||
banner: BannerReducer,
|
||||
apiUrl: ApiUrlReducer,
|
||||
editorConfig: EditorConfigReducer,
|
||||
darkMode: DarkModeConfigReducer
|
||||
darkMode: DarkModeConfigReducer,
|
||||
documentContent: DocumentContentReducer
|
||||
})
|
||||
|
||||
export const store = createStore(allReducers)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue