Skip to content

Commit

Permalink
fixing rendering errors
Browse files Browse the repository at this point in the history
  • Loading branch information
jue-henry committed Dec 18, 2024
1 parent 8d6da73 commit 9fbd62f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 20 deletions.
25 changes: 16 additions & 9 deletions src/features/cameras/DeleteCameraAlert.jsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import React, { useState, useEffect } from 'react';
import React, { useEffect } from 'react';
import { useSelector, useDispatch } from 'react-redux';
import { red } from '@radix-ui/colors';
import { styled } from '../../theme/stitches.config.js';
import Button from '../../components/Button.jsx';
import { ButtonRow } from '../../components/Form.jsx';
import { deleteCamera, fetchTask, selectDeleteCameraLoading } from '../tasks/tasksSlice.js';
import {
clearDeleteCameraTask,
deleteCamera,
fetchTask,
selectDeleteCameraLoading,
} from '../tasks/tasksSlice.js';
import { SimpleSpinner, SpinnerOverlay } from '../../components/Spinner.jsx';
import { selectSelectedCamera } from '../projects/projectsSlice.js';
import {
Expand All @@ -29,7 +34,6 @@ const BoldText = styled('span', {
});

const DeleteCameraAlert = () => {
const [queuedForClose, setQueuedForClose] = useState(false);
const deleteCameraLoading = useSelector(selectDeleteCameraLoading);
const selectedCamera = useSelector(selectSelectedCamera);
const imageCount = useSelector(selectCameraImageCount);
Expand All @@ -44,13 +48,16 @@ const DeleteCameraAlert = () => {
}, [imageCount, selectedCamera, dispatch]);

useEffect(() => {
if (queuedForClose && !deleteCameraLoading.isLoading)
dispatch(setDeleteCameraAlertStatus(false));
}, [deleteCameraLoading, queuedForClose]);
if (!deleteCameraLoading.isLoading) dispatch(setDeleteCameraAlertStatus(false));
}, [deleteCameraLoading]);

const handleDeleteCameraSubmit = () => {
dispatch(deleteCamera({ cameraId: selectedCamera }));
setQueuedForClose(true);
};

const handleCancelDelete = () => {
dispatch(setDeleteCameraAlertStatus(false));
dispatch(clearDeleteCameraTask());
};

// handle polling for task completion
Expand Down Expand Up @@ -83,7 +90,7 @@ const DeleteCameraAlert = () => {
{ASYNC_IMAGE_DELETE_BY_FILTER_LIMIT} before trying again. We apologize for the
inconvenience.
<ButtonRow>
<Button type="button" size="large" onClick={setQueuedForClose(true)}>
<Button type="button" size="large" onClick={handleCancelDelete}>
Cancel
</Button>
</ButtonRow>
Expand All @@ -95,7 +102,7 @@ const DeleteCameraAlert = () => {
it, and <BoldText>{imagesText}</BoldText> will be deleted.{' '}
<BoldText>This action cannot be undone.</BoldText>
<ButtonRow>
<Button type="button" size="large" onClick={setQueuedForClose(true)}>
<Button type="button" size="large" onClick={handleCancelDelete}>
Cancel
</Button>
<Button
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useState, useEffect } from 'react';
import * as Progress from '@radix-ui/react-progress';
import { green } from '@radix-ui/colors';
import { styled } from '../theme/stitches.config.js';
import { styled } from '../../theme/stitches.config.js';

const ProgressBar = styled('div', {
display: 'flex',
Expand Down Expand Up @@ -31,15 +31,18 @@ const ProgressIndicator = styled(Progress.Indicator, {
transition: 'transform 660ms cubic-bezier(0.65, 0, 0.35, 1)',
});

export const DeleteImagesProgressBar = ({ imageCount }) => {
const [estimatedTotalTime, setEstimatedTotalTime] = useState(null); // in seconds
const [elapsedTime, setElapsedTime] = useState(null);
// show progress bar if deleting more than 3000 images (approx wait time will be > 10 seconds)
const PROGRESS_BAR_IMAGE_COUNT_BREAKPOINT = 3000;

if (imageCount > 3000) {
// show progress bar if deleting more than 3000 images (approx wait time will be > 10 seconds)
setEstimatedTotalTime(imageCount * 0.0055); // estimated deletion time per image in seconds
setElapsedTime(0);
}
export const DeleteImagesProgressBar = ({ imageCount }) => {
const [estimatedTotalTime, setEstimatedTotalTime] = useState(
imageCount > PROGRESS_BAR_IMAGE_COUNT_BREAKPOINT
? imageCount * 0.0055 // estimated deletion time per image in seconds
: null,
); // in seconds
const [elapsedTime, setElapsedTime] = useState(
imageCount > PROGRESS_BAR_IMAGE_COUNT_BREAKPOINT ? 0 : null,
);

useEffect(() => {
if (estimatedTotalTime) {
Expand Down Expand Up @@ -70,5 +73,3 @@ export const DeleteImagesProgressBar = ({ imageCount }) => {
</ProgressBar>
);
};

// export default DeleteImagesProgressBar;
2 changes: 2 additions & 0 deletions src/features/tasks/tasksSlice.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
fetchImagesCount,
setDeleteImagesAlertStatus,
} from '../images/imagesSlice.js';
import { setDeleteCameraAlertStatus } from '../cameras/wirelessCamerasSlice.js';

const initialState = {
loadingStates: {
Expand Down Expand Up @@ -464,6 +465,7 @@ export const fetchTask = (taskId) => {
DeleteCamera: {
COMPLETE: () => {
dispatch(updateDeleteCameraSuccess());
dispatch(setDeleteCameraAlertStatus(false));
},
FAIL: (res) => dispatch(updateDeleteCameraFailure(res)),
},
Expand Down

0 comments on commit 9fbd62f

Please sign in to comment.