Skip to content
This repository was archived by the owner on May 30, 2023. It is now read-only.

Commit 4b1d352

Browse files
author
Lộc Phạm
authored
Merge pull request #245 from daita-technologies/update/thumbnail-for-images
update: load thumbnail instead of full image on image list at project detail
2 parents 25374e9 + 06d1fc0 commit 4b1d352

17 files changed

Lines changed: 396 additions & 274 deletions

File tree

src/components/CreateProjectModal/index.tsx

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ const CreateProjectDatasetTypeControl = function (
6565
setPrebuildDataset,
6666
listPrebuildDataset,
6767
isLoadingPrebuildDataset,
68+
isCreatingProject,
6869
} = props;
6970

7071
const onChangeNumberOfDatasetImagesSlider = (
@@ -98,7 +99,7 @@ const CreateProjectDatasetTypeControl = function (
9899
<Box>
99100
<FormControlLabel
100101
value={value}
101-
control={<Radio />}
102+
control={<Radio disabled={isCreatingProject} />}
102103
label={label}
103104
onClick={() => setDatasetProjectType(value)}
104105
/>
@@ -114,6 +115,7 @@ const CreateProjectDatasetTypeControl = function (
114115
value={prebuildDataset}
115116
disablePortal
116117
loading={isLoadingPrebuildDataset}
118+
disabled={isCreatingProject}
117119
options={listPrebuildDataset}
118120
getOptionLabel={(option) => option.name}
119121
onChange={(_, selectedPrebuildDataset) => {
@@ -150,6 +152,7 @@ const CreateProjectDatasetTypeControl = function (
150152
prebuildDataset?.totalImage ||
151153
MIN_DATASET_IMAGES_CREATE_PROJECT
152154
}
155+
disabled={isCreatingProject}
153156
/>
154157
<Input
155158
value={numberOfDatasetImages}
@@ -164,6 +167,7 @@ const CreateProjectDatasetTypeControl = function (
164167
type: "number",
165168
"aria-labelledby": "input-number-of-dataset-images-slider",
166169
}}
170+
disabled={isCreatingProject}
167171
/>
168172
</Box>
169173
</Box>
@@ -179,6 +183,7 @@ const CreateProjectModal = function (props: CreateProjectModalProps) {
179183
register,
180184
handleSubmit,
181185
formState: { errors },
186+
reset,
182187
} = useForm<CreateProjectFields>({
183188
mode: "onChange",
184189
defaultValues: {
@@ -229,6 +234,13 @@ const CreateProjectModal = function (props: CreateProjectModalProps) {
229234
(state: RootState) => state.projectReducer.isCreatingProject
230235
);
231236

237+
const resetFormData = () => {
238+
reset();
239+
setPrebuildDataset(null);
240+
setDatasetProjectType(EMPTY_DATASET_CREATE_PROJECT_DATASET_TYPE_VALUE);
241+
setNumberOfDatasetImages(1);
242+
};
243+
232244
const onSubmitCreateProject = (fields: CreateProjectFields) => {
233245
if (
234246
datasetProjectType === EXISTING_DATASET_CREATE_PROJECT_DATASET_TYPE_VALUE
@@ -239,24 +251,34 @@ const CreateProjectModal = function (props: CreateProjectModalProps) {
239251
numberRadom: numberOfDatasetImages,
240252
};
241253
} else {
242-
toast.error("Please select one prebuild dataset");
254+
toast.error("Please select one prebuild dataset.");
243255
return;
244256
}
245257
}
246258

247259
dispatch({ type: CREATE_PROJECT.REQUESTED, payload: fields });
260+
resetFormData();
261+
};
262+
263+
const onCloseModal = () => {
264+
if (!isLoading) {
265+
if (handleClose) {
266+
handleClose();
267+
}
268+
resetFormData();
269+
}
248270
};
249271

250272
return (
251273
<Modal
252274
open={isOpen}
253-
onClose={!isLoading ? handleClose : undefined}
275+
onClose={!isLoading ? onCloseModal : undefined}
254276
disableEscapeKeyDown
255277
>
256278
<Box sx={{ ...modalStyle, width: 700 }}>
257279
<IconButton
258280
sx={modalCloseStyle}
259-
onClick={!isLoading ? handleClose : undefined}
281+
onClick={!isLoading ? onCloseModal : undefined}
260282
>
261283
<CancelIcon fontSize="large" />
262284
</IconButton>
@@ -343,6 +365,7 @@ const CreateProjectModal = function (props: CreateProjectModalProps) {
343365
setPrebuildDataset={setPrebuildDataset}
344366
listPrebuildDataset={listPrebuildDataset}
345367
isLoadingPrebuildDataset={isLoadingPrebuildDataset}
368+
isCreatingProject={isLoading}
346369
/>
347370
</Box>
348371
);

src/components/CreateProjectModal/type.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export interface CreateProjectDatasetTypeControlProps
3939
setPrebuildDataset: (value: PrebuildDataset) => void;
4040
listPrebuildDataset: PrebuildDataset[];
4141
isLoadingPrebuildDataset: boolean;
42+
isCreatingProject: boolean;
4243
}
4344

4445
export interface CreateProjectPreBuildFields {

src/reduxes/album/reducer.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,10 @@ const albumReducer = (state = inititalState, action: any): AlbumReducer => {
100100
[payload.filename]: {
101101
...state.images[payload.filename],
102102
blob: payload.blob,
103-
url: payload.url,
103+
thumbnailUrl: payload.thumbnailUrl
104+
? payload.thumbnailUrl
105+
: state.images[payload.filename].thumbnailUrl,
106+
url: payload.url ? payload.url : state.images[payload.filename].url,
104107
size: payload.size,
105108
},
106109
},

src/reduxes/album/type.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,14 @@ export type ImageSourceType =
2929
export interface ImageApiFields {
3030
filename: string;
3131
s3_key: string;
32+
thumbnail: string;
3233
photoKey: string;
3334
typeOfImage: ImageSourceType;
3435
gen_id?: string[] | string;
3536
classtype?: string;
3637
blob?: Blob;
3738
url?: string;
39+
thumbnailUrl?: string;
3840
size?: number;
3941
}
4042

@@ -104,12 +106,13 @@ export interface LoadImageContentPayload {
104106
isFetchToDownload?: boolean;
105107
isSelectedDownload?: boolean;
106108
blob?: Blob;
109+
isThumbnailImage?: boolean;
107110
}
108111

109112
export interface LoadImageContentSucceedPayload {
110113
projectId: string;
111114
filename: string;
112115
blob: Blob;
113-
url: string;
116+
thumbnailUrl: string;
114117
size: number;
115118
}

src/reduxes/project/reducer.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,6 @@ const projectReducer = (
371371
...(payload as CreateSampleSucceedPayload),
372372
groups: null,
373373
ls_task: [],
374-
is_sample: true,
375374
description: "",
376375
},
377376
],
@@ -437,10 +436,10 @@ const projectReducer = (
437436
}
438437
case LOAD_PROJECT_THUMBNAIL_IMAGE.SUCCEEDED:
439438
case LOAD_PROJECT_THUMBNAIL_IMAGE.FAILED: {
440-
const { projectId, thumbnailUrl } =
439+
const { projectId, projectThumbnailUrl } =
441440
payload as LoadProjectThumbnailImageSucceedPayload;
442441
const newThumbnails = { ...state.thumbnails };
443-
newThumbnails[projectId] = thumbnailUrl;
442+
newThumbnails[projectId] = projectThumbnailUrl;
444443
return { ...state, thumbnails: newThumbnails };
445444
}
446445
case SET_IS_OPEN_UPDATE_PROJECT_INFO: {

src/reduxes/project/type.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ export interface ProjectInfo {
5858
times_generated: number;
5959
groups: GroupProjectInfo;
6060
ls_task: Array<TaskInfo>;
61-
is_sample: boolean;
6261
gen_status: GENERATE_PROJECT_STATUS_TYPE;
6362
aug_parameters: AugmentParameterApiField;
6463
}
@@ -69,7 +68,6 @@ export interface ApiListProjectsItem {
6968
s3_prefix: string;
7069
ls_task: Array<TaskInfo>;
7170
groups: GroupProjectInfo;
72-
is_sample: boolean;
7371
gen_status: GENERATE_PROJECT_STATUS_TYPE;
7472
thum_key: string;
7573
description: string;
@@ -169,7 +167,6 @@ export interface CreateSampleSucceedPayload {
169167
project_id: string;
170168
project_name: string;
171169
s3_prefix: string;
172-
is_sample: boolean;
173170
gen_status: GENERATE_PROJECT_STATUS_TYPE;
174171
thum_key: string;
175172
}
@@ -224,7 +221,7 @@ export interface LoadProjectThumbnailImagePayload {
224221
}
225222

226223
export interface LoadProjectThumbnailImageSucceedPayload {
227-
thumbnailUrl: string;
224+
projectThumbnailUrl: string;
228225
projectId: string;
229226
}
230227
export interface UpdateProjectInfo {
@@ -248,7 +245,6 @@ export interface SetIsOpenUpdateProjectInfoPayload {
248245
export interface ApiUpdateProjectsInfo {
249246
project_id: string;
250247
s3_prefix: string;
251-
is_sample: boolean;
252248
gen_status: GENERATE_PROJECT_STATUS_TYPE;
253249
project_name: string;
254250
description: string;

src/routes/DashboardPage/index.tsx

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,17 @@ const EmptyDashboardMessage = function ({
4242
return (
4343
<Box mt={projectCount <= 0 ? 12 : 4} textAlign="center">
4444
{projectCount <= 0 && (
45-
<Typography variant="h4" component="h1">
46-
👋 Welcome to DAITA, let's get started.
47-
</Typography>
45+
<>
46+
<Typography variant="h4" component="h1">
47+
👋 Welcome to DAITA, let's get started.
48+
</Typography>
49+
50+
<Typography sx={{ mt: 2 }}>
51+
👉 If you just want to play, you can create project with existing
52+
dataset. You don't have to upload any data!
53+
</Typography>
54+
</>
4855
)}
49-
<Typography sx={{ mt: 2 }}>
50-
👉 If you just want to play, you can create project with existing
51-
dataset. You don't have to upload any data!
52-
</Typography>
5356
{/* <Typography sx={{ mt: 2 }}>
5457
👉 If you just want to play, you can create a sandbox project{" "}
5558
<Box

0 commit comments

Comments
 (0)