-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ExportProject actions/reducer/state (#812)
* Sort reducers and states; * Remove unnecessary layer from MergeDup reducer; * Add action, reducer, state for ExportProject; * Split export function into 2 on frontend (works as is, but needs to be modified when backend process is split);
- Loading branch information
1 parent
528e7a7
commit d1cd125
Showing
19 changed files
with
270 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
src/components/ProjectSettings/ProjectExport/ExportProjectActions.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { ThunkDispatch } from "redux-thunk"; | ||
|
||
import { downloadLift, exportLift } from "../../../backend"; | ||
import { StoreState } from "../../../types"; | ||
|
||
export enum ExportStatus { | ||
Default = "DEFAULT", | ||
InProgress = "IN_PROGRESS", | ||
Success = "SUCCESS", | ||
Failure = "FAILURE", | ||
} | ||
|
||
export interface ExportProjectAction { | ||
type: ExportStatus; | ||
projectId?: string; | ||
} | ||
|
||
export function asyncExportProject(projectId?: string) { | ||
return async ( | ||
dispatch: ThunkDispatch<StoreState, any, ExportProjectAction> | ||
) => { | ||
dispatch(inProgress(projectId)); | ||
exportLift(projectId).catch(() => { | ||
dispatch(failure(projectId)); | ||
}); | ||
}; | ||
} | ||
|
||
export function asyncDownloadExport(projectId?: string) { | ||
return async ( | ||
dispatch: ThunkDispatch<StoreState, any, ExportProjectAction> | ||
) => { | ||
return downloadLift(projectId) | ||
.then((fileString) => { | ||
return fetch(fileString) | ||
.then((file) => { | ||
dispatch(success(projectId)); | ||
return file.blob(); | ||
}) | ||
.catch(() => { | ||
dispatch(failure(projectId)); | ||
}); | ||
}) | ||
.catch(() => { | ||
dispatch(failure(projectId)); | ||
}); | ||
}; | ||
} | ||
|
||
export function inProgress(projectId?: string): ExportProjectAction { | ||
return { | ||
type: ExportStatus.InProgress, | ||
projectId, | ||
}; | ||
} | ||
|
||
export function success(projectId?: string): ExportProjectAction { | ||
return { | ||
type: ExportStatus.Success, | ||
projectId, | ||
}; | ||
} | ||
|
||
export function failure(projectId?: string): ExportProjectAction { | ||
return { | ||
type: ExportStatus.Failure, | ||
projectId, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
src/components/ProjectSettings/ProjectExport/ExportProjectReducer.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { StoreAction, StoreActions } from "../../../rootActions"; | ||
import { ExportProjectAction, ExportStatus } from "./ExportProjectActions"; | ||
|
||
export interface ExportProjectState { | ||
projectId: string; | ||
status: ExportStatus; | ||
} | ||
|
||
export const defaultState: ExportProjectState = { | ||
projectId: "", | ||
status: ExportStatus.Default, | ||
}; | ||
|
||
export const exportProjectReducer = ( | ||
state: ExportProjectState = defaultState, | ||
action: StoreAction | ExportProjectAction | ||
): ExportProjectState => { | ||
switch (action.type) { | ||
case ExportStatus.InProgress: | ||
return { | ||
...defaultState, | ||
projectId: action.projectId ?? "", | ||
status: action.type, | ||
}; | ||
case ExportStatus.Success: | ||
return { | ||
...defaultState, | ||
projectId: action.projectId ?? "", | ||
status: action.type, | ||
}; | ||
case ExportStatus.Failure: | ||
return { | ||
...defaultState, | ||
projectId: action.projectId ?? "", | ||
status: action.type, | ||
}; | ||
case StoreActions.RESET: | ||
return defaultState; | ||
default: | ||
return state; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { connect } from "react-redux"; | ||
import { ThunkDispatch } from "redux-thunk"; | ||
|
||
import { StoreState } from "../../../types"; | ||
import { | ||
asyncDownloadExport, | ||
asyncExportProject, | ||
ExportProjectAction, | ||
} from "./ExportProjectActions"; | ||
import ExportProjectButton from "./ExportProjectButton"; | ||
|
||
function mapStateToProps(state: StoreState) { | ||
return { | ||
exportResult: state.exportProjectState, | ||
}; | ||
} | ||
|
||
function mapDispatchToProps( | ||
dispatch: ThunkDispatch<StoreState, any, ExportProjectAction> | ||
) { | ||
return { | ||
exportProject: (projectId?: string) => { | ||
dispatch(asyncExportProject(projectId)); | ||
}, | ||
downloadLift: (projectId?: string) => { | ||
return dispatch(asyncDownloadExport(projectId)); | ||
}, | ||
}; | ||
} | ||
|
||
export default connect( | ||
mapStateToProps, | ||
mapDispatchToProps | ||
)(ExportProjectButton); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.