Skip to content

Commit

Permalink
Merge pull request #119 from daodaoedu/feat/group
Browse files Browse the repository at this point in the history
feat: assign random cover image for group
  • Loading branch information
JohnsonMao authored Nov 5, 2024
2 parents 5954152 + ec236f2 commit a26de8a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
25 changes: 18 additions & 7 deletions components/Group/Form/Fields/Upload.jsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import { useEffect, useRef, useState } from 'react';
import { GiPerspectiveDiceSixFacesThree } from 'react-icons/gi';
import Box from '@mui/material/Box';
import Button from '@mui/material/Button';
import DeleteSvg from '@/public/assets/icons/delete.svg';
import Image from '@/shared/components/Image';
import { StyledUpload } from '../Form.styled';
import UploadSvg from './UploadSvg';

export default function Upload({ name, value, control }) {
const [preview, setPreview] = useState(value || '');
const [preview, setPreview] = useState(value);
const [error, setError] = useState('');
const inputRef = useRef();
const isLoading = useRef(false);

const changeHandler = (file) => {
const event = {
Expand Down Expand Up @@ -66,15 +67,25 @@ export default function Upload({ name, value, control }) {
if (files?.[0]) handleFile(files[0]);
};

const handleClear = () => {
const handleRandom = () => {
setPreview('');
setError('');
inputRef.current.value = '';
changeHandler('');
};

useEffect(() => {
if (typeof value === 'string') setPreview(value);
if (typeof value === 'string' && value) {
setPreview(value);
} else if (!isLoading.current && !value) {
isLoading.current = true;
fetch('https://picsum.photos/436/244')
.then((res) => res.blob())
.then(handleFile)
.then(() => {
isLoading.current = false;
});
}
}, [value]);

return (
Expand All @@ -92,10 +103,10 @@ export default function Upload({ name, value, control }) {
marginTop: 0.25,
},
}}
onClick={handleClear}
onClick={handleRandom}
>
<img src={DeleteSvg.src} alt="delete icon" />
<span>清除</span>
<GiPerspectiveDiceSixFacesThree size={20} />
<span>隨機圖片</span>
</Button>
)}
<StyledUpload
Expand Down
5 changes: 3 additions & 2 deletions redux/sagas/user/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,11 @@ function* updateUserProfile(action) {
});

yield put({ type: 'UPDATE_USER_PROFILE_SUCCESS', payload: result.data });
yield new Promise((res) => setTimeout(res, 300));
yield put({ type: 'UPDATE_USER_PROFILE_API_STATE_RESET' });
} catch (error) {
yield put({ type: 'UPDATE_USER_PROFILE_FAILURE' });
} finally {
yield new Promise((res) => setTimeout(res, 300));
yield put({ type: 'UPDATE_USER_PROFILE_API_STATE_RESET' });
}
}

Expand Down
2 changes: 1 addition & 1 deletion shared/components/InfoCompletionGuard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default function InfoCompletionGuard({ children }) {
<>
{cloneElement(
children,
user?.isComplete ? {} : { onClick: handleClickProxy },
user?._id && !user?.isComplete ? { onClick: handleClickProxy } : {},
)}
<CompleteInfoReminderDialog isOpen={isOpen} onClose={handleClose} />
</>
Expand Down

0 comments on commit a26de8a

Please sign in to comment.