Skip to content

Commit

Permalink
fix: exception
Browse files Browse the repository at this point in the history
  • Loading branch information
kcwww committed Dec 12, 2023
1 parent a141e66 commit dc20c05
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
13 changes: 6 additions & 7 deletions front/src/pages/Main/LockModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,13 @@ const LockModal = (props: LockModalProps) => {
const { changePrivate, snowBallData } = useContext(SnowBallContext);
const privateFlag = snowBallData.is_message_private;

const setPrivate = () => {
const setPrivate = async () => {
props.set(false);
changePrivate().then(() => {
props.setToast(true);
setTimeout(() => {
props.setToast(false);
}, 1500);
});
await changePrivate()
props.setToast(true);
setTimeout(() => {
props.setToast(false);
}, 1500);
};

const stopEvent = (e: React.MouseEvent<HTMLDivElement>) => {
Expand Down
16 changes: 11 additions & 5 deletions front/src/pages/Visit/SnowBallProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { useState, createContext } from 'react';
import { axios } from '@utils';
import mockData from '@mock';
import { useNavigate } from 'react-router-dom';

interface SnowBallData {
id: number;
Expand Down Expand Up @@ -46,17 +47,22 @@ const SnowBallProvider: React.FC<{ children: React.ReactNode }> = ({
mockData.snowball_data as SnowBallData
);
const [userData, setUserData] = useState<UserData>(mockData.user_data);

const navigate = useNavigate();
const changePrivate = async () => {
const newData = {
title: snowBallData.title,
is_message_private: !snowBallData.is_message_private
};

const res = await axios.put(`/api/snowball/${snowBallData.id}`, newData);
const resData = Object.assign({}, snowBallData);
resData.is_message_private = res.data.is_message_private;
setSnowBallData(resData);
try {
const res = await axios.put(`/api/snowball/${snowBallData.id}`, newData);
const resData = Object.assign({}, snowBallData);
resData.is_message_private = res.data.is_message_private;
setSnowBallData(resData);
} catch (err) {
console.log(err);
navigate('*');
}
};

return (
Expand Down

0 comments on commit dc20c05

Please sign in to comment.