mirror of
https://github.com/usatiuk/writer.git
synced 2025-10-29 00:17:48 +01:00
rename "update" to "upload" in documents context
This commit is contained in:
@@ -12,7 +12,7 @@ import {
|
||||
deleteDocCancel,
|
||||
deleteDocStart,
|
||||
fetchDocsStart,
|
||||
updateDocStart,
|
||||
uploadDocStart,
|
||||
} from "~redux/docs/actions";
|
||||
import { IAppState } from "~redux/reducers";
|
||||
|
||||
@@ -25,7 +25,7 @@ export interface IDocumentEditComponentProps extends RouteComponentProps {
|
||||
fetchDocs: () => void;
|
||||
deleteDoc: (id: number) => void;
|
||||
cancelDelete: () => void;
|
||||
updateDoc: (id: number, name: string, content: string) => void;
|
||||
uploadDoc: (id: number, name: string, content: string) => void;
|
||||
}
|
||||
|
||||
export interface IDocumentEditComponentState {
|
||||
@@ -108,8 +108,8 @@ export class DocumentEditComponent extends React.PureComponent<
|
||||
}
|
||||
}
|
||||
|
||||
public update() {
|
||||
this.props.updateDoc(
|
||||
public upload() {
|
||||
this.props.uploadDoc(
|
||||
this.state.id,
|
||||
this.state.name,
|
||||
this.state.content,
|
||||
@@ -128,7 +128,7 @@ export class DocumentEditComponent extends React.PureComponent<
|
||||
}
|
||||
|
||||
public save() {
|
||||
this.update();
|
||||
this.upload();
|
||||
this.props.history.push(`/docs/${this.state.id}`);
|
||||
}
|
||||
|
||||
@@ -224,8 +224,8 @@ function mapDispatchToProps(dispatch: Dispatch) {
|
||||
fetchDocs: () => dispatch(fetchDocsStart()),
|
||||
cancelDelete: () => dispatch(deleteDocCancel()),
|
||||
deleteDoc: (id: number) => dispatch(deleteDocStart(id)),
|
||||
updateDoc: (id: number, name: string, content: string) =>
|
||||
dispatch(updateDocStart(id, name, content)),
|
||||
uploadDoc: (id: number, name: string, content: string) =>
|
||||
dispatch(uploadDocStart(id, name, content)),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ describe("<DocumentEdit />", () => {
|
||||
fetchDocs={mock}
|
||||
cancelDelete={mock}
|
||||
deleteDoc={mock}
|
||||
updateDoc={mock}
|
||||
uploadDoc={mock}
|
||||
history={mock}
|
||||
location={mock}
|
||||
match={{ params: { id: 1 } } as any}
|
||||
@@ -73,7 +73,7 @@ describe("<DocumentEdit />", () => {
|
||||
fetchDocs={mock}
|
||||
cancelDelete={mock}
|
||||
deleteDoc={mock}
|
||||
updateDoc={mock}
|
||||
uploadDoc={mock}
|
||||
history={mock}
|
||||
location={mock}
|
||||
match={{ params: { id: 1 } } as any}
|
||||
|
||||
@@ -16,9 +16,9 @@ export enum DocsTypes {
|
||||
DOC_DELETE_SUCCESS = "DOC_DELETE_SUCCESS",
|
||||
DOC_DELETE_CANCEL = "DOC_DELETE_CANCEL",
|
||||
|
||||
DOC_UPDATE_START = "DOC_UPDATE_START",
|
||||
DOC_UPDATE_FAIL = "DOC_UPDATE_FAIL",
|
||||
DOC_UPDATE_SUCCESS = "DOC_UPDATE_SUCCESS",
|
||||
DOC_UPLOAD_START = "DOC_UPLOAD_START",
|
||||
DOC_UPLOAD_FAIL = "DOC_UPLOAD_FAIL",
|
||||
DOC_UPLOAD_SUCCESS = "DOC_UPLOAD_SUCCESS",
|
||||
|
||||
DOCS_SHOW_SPINNER = "DOCS_SHOW_SPINNER",
|
||||
}
|
||||
@@ -140,41 +140,41 @@ export function deleteDocCancel(): IDocDeleteCancelAction {
|
||||
return { type: DocsTypes.DOC_DELETE_CANCEL };
|
||||
}
|
||||
|
||||
export interface IDocUpdateStartAction extends Action {
|
||||
type: DocsTypes.DOC_UPDATE_START;
|
||||
export interface IDocUploadStartAction extends Action {
|
||||
type: DocsTypes.DOC_UPLOAD_START;
|
||||
id: number;
|
||||
name: string;
|
||||
content: string;
|
||||
}
|
||||
|
||||
export interface IDocUpdateFailAction extends Action {
|
||||
type: DocsTypes.DOC_UPDATE_FAIL;
|
||||
export interface IDocUploadFailAction extends Action {
|
||||
type: DocsTypes.DOC_UPLOAD_FAIL;
|
||||
payload: {
|
||||
error: string;
|
||||
};
|
||||
}
|
||||
|
||||
export interface IDocUpdateSuccessAction extends Action {
|
||||
type: DocsTypes.DOC_UPDATE_SUCCESS;
|
||||
export interface IDocUploadSuccessAction extends Action {
|
||||
type: DocsTypes.DOC_UPLOAD_SUCCESS;
|
||||
payload: {
|
||||
doc: IDocumentJSON;
|
||||
};
|
||||
}
|
||||
|
||||
export function updateDocStart(
|
||||
export function uploadDocStart(
|
||||
id: number,
|
||||
name: string,
|
||||
content: string,
|
||||
): IDocUpdateStartAction {
|
||||
return { type: DocsTypes.DOC_UPDATE_START, id, name, content };
|
||||
): IDocUploadStartAction {
|
||||
return { type: DocsTypes.DOC_UPLOAD_START, id, name, content };
|
||||
}
|
||||
|
||||
export function updateDocFail(error: string): IDocUpdateFailAction {
|
||||
return { type: DocsTypes.DOC_UPDATE_FAIL, payload: { error } };
|
||||
export function uploadDocFail(error: string): IDocUploadFailAction {
|
||||
return { type: DocsTypes.DOC_UPLOAD_FAIL, payload: { error } };
|
||||
}
|
||||
|
||||
export function updateDocSuccess(doc: IDocumentJSON): IDocUpdateSuccessAction {
|
||||
return { type: DocsTypes.DOC_UPDATE_SUCCESS, payload: { doc } };
|
||||
export function uploadDocSuccess(doc: IDocumentJSON): IDocUploadSuccessAction {
|
||||
return { type: DocsTypes.DOC_UPLOAD_SUCCESS, payload: { doc } };
|
||||
}
|
||||
|
||||
export type DocsAction =
|
||||
@@ -190,6 +190,6 @@ export type DocsAction =
|
||||
| IDocDeleteStartAction
|
||||
| IDocDeleteSuccessAction
|
||||
| IDocDeleteCancelAction
|
||||
| IDocUpdateFailAction
|
||||
| IDocUpdateStartAction
|
||||
| IDocUpdateSuccessAction;
|
||||
| IDocUploadFailAction
|
||||
| IDocUploadStartAction
|
||||
| IDocUploadSuccessAction;
|
||||
|
||||
@@ -4,8 +4,13 @@ import { UserAction, UserTypes } from "~redux/user/actions";
|
||||
|
||||
import { DocsAction, DocsTypes } from "./actions";
|
||||
|
||||
export interface IDocumentEntry extends IDocumentJSON {
|
||||
remote: IDocumentJSON;
|
||||
dirty: boolean;
|
||||
}
|
||||
|
||||
export interface IDocsState {
|
||||
all: { [key: number]: IDocumentJSON };
|
||||
all: { [key: number]: IDocumentEntry };
|
||||
fetching: boolean;
|
||||
uploading: boolean;
|
||||
error: string | null;
|
||||
@@ -13,7 +18,7 @@ export interface IDocsState {
|
||||
|
||||
newDocumentID: number | null;
|
||||
|
||||
deletedDocument: IDocumentJSON | null;
|
||||
deletedDocument: IDocumentEntry | null;
|
||||
}
|
||||
|
||||
const defaultDocsState: IDocsState = {
|
||||
@@ -36,16 +41,16 @@ export const docsReducer: Reducer<IDocsState, DocsAction> = (
|
||||
case DocsTypes.DOCS_FETCH_START:
|
||||
return { ...defaultDocsState, fetching: true };
|
||||
case DocsTypes.DOCS_FETCH_SUCCESS: {
|
||||
const all: { [key: number]: IDocumentJSON } = {};
|
||||
const all: { [key: number]: IDocumentEntry } = {};
|
||||
action.payload.all.forEach(doc => {
|
||||
all[doc.id] = doc;
|
||||
all[doc.id] = { ...doc, remote: doc, dirty: false };
|
||||
});
|
||||
return { ...defaultDocsState, all };
|
||||
}
|
||||
case DocsTypes.DOC_NEW_SUCCESS: {
|
||||
const all = { ...state.all };
|
||||
const doc = action.payload.doc;
|
||||
all[doc.id] = doc;
|
||||
all[doc.id] = { ...doc, remote: doc, dirty: false };
|
||||
return { ...state, all, newDocumentID: doc.id };
|
||||
}
|
||||
case DocsTypes.DOC_NEW_RESET: {
|
||||
@@ -66,16 +71,16 @@ export const docsReducer: Reducer<IDocsState, DocsAction> = (
|
||||
all[deletedDocument.id] = deletedDocument;
|
||||
return { ...state, deletedDocument: null, all };
|
||||
}
|
||||
case DocsTypes.DOC_UPDATE_START: {
|
||||
case DocsTypes.DOC_UPLOAD_START: {
|
||||
return { ...state, uploading: true };
|
||||
}
|
||||
case DocsTypes.DOC_UPDATE_FAIL: {
|
||||
case DocsTypes.DOC_UPLOAD_FAIL: {
|
||||
return { ...state, uploading: false };
|
||||
}
|
||||
case DocsTypes.DOC_UPDATE_SUCCESS: {
|
||||
case DocsTypes.DOC_UPLOAD_SUCCESS: {
|
||||
const all = { ...state.all };
|
||||
const doc = action.payload.doc;
|
||||
all[doc.id] = doc;
|
||||
all[doc.id] = { ...doc, remote: doc, dirty: false };
|
||||
return { ...state, all, uploading: false };
|
||||
}
|
||||
case DocsTypes.DOCS_FETCH_FAIL:
|
||||
|
||||
@@ -26,12 +26,12 @@ import {
|
||||
IDocDeleteStartAction,
|
||||
IDocNewStartAction,
|
||||
IDocsFetchStartAction,
|
||||
IDocUpdateStartAction,
|
||||
IDocUploadStartAction,
|
||||
newDocFail,
|
||||
newDocSuccess,
|
||||
showDocsSpinner,
|
||||
updateDocFail,
|
||||
updateDocSuccess,
|
||||
uploadDocFail,
|
||||
uploadDocSuccess,
|
||||
} from "./actions";
|
||||
|
||||
function* startSpinner() {
|
||||
@@ -128,7 +128,7 @@ function* docDeleteStart(action: IDocDeleteStartAction) {
|
||||
}
|
||||
}
|
||||
|
||||
function* docUpdateStart(action: IDocUpdateStartAction) {
|
||||
function* docUploadStart(action: IDocUploadStartAction) {
|
||||
try {
|
||||
const spinner = yield fork(startSpinner);
|
||||
|
||||
@@ -140,20 +140,20 @@ function* docUpdateStart(action: IDocUpdateStartAction) {
|
||||
yield cancel(spinner);
|
||||
|
||||
if (timeout) {
|
||||
yield put(updateDocFail("Timeout"));
|
||||
yield put(uploadDocFail("Timeout"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (response) {
|
||||
if (response.data == null) {
|
||||
yield put(updateDocFail(response.error));
|
||||
yield put(uploadDocFail(response.error));
|
||||
} else {
|
||||
const updDoc = response.data;
|
||||
yield put(updateDocSuccess(updDoc));
|
||||
yield put(uploadDocSuccess(updDoc));
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
yield put(updateDocFail("Internal error"));
|
||||
yield put(uploadDocFail("Internal error"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -162,6 +162,6 @@ export function* docsSaga() {
|
||||
takeLatest(DocsTypes.DOCS_FETCH_START, docsFetchStart),
|
||||
takeLatest(DocsTypes.DOC_NEW_START, docNewStart),
|
||||
takeEvery(DocsTypes.DOC_DELETE_START, docDeleteStart),
|
||||
takeLatest(DocsTypes.DOC_UPDATE_START, docUpdateStart),
|
||||
takeLatest(DocsTypes.DOC_UPLOAD_START, docUploadStart),
|
||||
]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user