Skip to content

Commit

Permalink
fix: loading ui when router push
Browse files Browse the repository at this point in the history
  • Loading branch information
kcwww committed Nov 21, 2024
1 parent d3193fe commit f1b0abc
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 24 deletions.
4 changes: 2 additions & 2 deletions app/(protected)/make/_components/MakeSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ const MakeSection = ({ userData }: { userData: User }) => {
if (typeof window !== 'undefined') {
const isDecorated = sessionStorage.getItem('isDecorated');
if (isDecorated) {
router.replace('/main');
router.replace(ROUTES.MAIN);
return;
}

const stepParam = searchParams.get('step');
const step = stepParam ? parseInt(stepParam) : STEP.MAIN_DECORATION;

if (isNaN(step) || step < STEP.MAIN_DECORATION || step > STEP.MAX) {
router.replace('/make?step=1');
router.replace(ROUTES.MAKE);
return;
}

Expand Down
2 changes: 1 addition & 1 deletion app/(protected)/make/_components/TitleForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ const TitleForm = ({ userData }: { userData: User }) => {
});

if (response.ok) {
router.replace(ROUTES.MAIN);
router.push(ROUTES.MAIN);
sessionStorage.setItem('isDecorated', 'true');
router.refresh();
}
Expand Down
21 changes: 1 addition & 20 deletions app/api/crystal/message/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ type MessageReq = {
};

export const POST = async (req: NextRequest) => {
console.log('POST');
const {
user_id,
crystal_id,
Expand All @@ -91,25 +90,11 @@ export const POST = async (req: NextRequest) => {
is_deleted,
is_opend,
} = (await req.json()) as MessageReq;
console.log(
'POST',
user_id,
crystal_id,
decoration_id,
decoration_color,
content,
sender,
letter_color,
is_deleted,
is_opend
);

await connectToMongoDB();
console.log('POST', 'connected to mongoDB');

const sessionDB = await mongoose.startSession();
sessionDB.startTransaction();

console.log('POST', 'sessionDB started');
try {
// MongoDB에 연결

Expand All @@ -131,7 +116,6 @@ export const POST = async (req: NextRequest) => {
{ session: sessionDB }
);

console.log('POST', 'message created', message);
if (!message) throw new Error('Failed to create message');

const message_id = message[0]._id;
Expand All @@ -148,10 +132,8 @@ export const POST = async (req: NextRequest) => {
},
{ new: true, session: sessionDB }
);
console.log('POST', 'crystal updated');
await sessionDB.commitTransaction();

console.log('POST', 'sessionDB committed');
return NextResponse.json({
message: 'Message created',
message_id,
Expand All @@ -161,7 +143,6 @@ export const POST = async (req: NextRequest) => {
console.error('Error creating message : ', error);

await sessionDB.abortTransaction();
console.log('POST', 'sessionDB aborted');
return NextResponse.json(
{ error: 'Failed to create message ' + error },
{ status: 500 }
Expand Down
2 changes: 1 addition & 1 deletion shared/components/modals/MessageSubmitModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const MessageSubmitModal = () => {
});

if (response.ok) {
router.replace(`/visit/${data.uuid}`);
router.push(`/visit/${data.uuid}`);
sessionStorage.setItem('messageIsDecorated', 'true');
sessionStorage.setItem('visitToast', 'true');
router.refresh();
Expand Down
Empty file.

0 comments on commit f1b0abc

Please sign in to comment.