Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: 알림 클릭 시, 쌓여있는 알림들을 모두 읽음 처리로 로직 수정 #436

Merged
merged 1 commit into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 3 additions & 11 deletions app/api/notification/read/route.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
import { NextRequest, NextResponse } from 'next/server';
import { NextResponse } from 'next/server';

import { fetchData } from '@/apis/fetch-data';
import {
NotificationReadResponse,
NotificationType,
} from '@/features/notification';
import { NotificationReadResponse } from '@/features/notification';

export async function PATCH(request: NextRequest) {
const body = (await request.json()) as Promise<{
notificationId: number;
type: NotificationType;
}>;
export async function PATCH() {
const data = await fetchData<NotificationReadResponse>(
`/notification/read`,
'PATCH',
body,
);

return NextResponse.json(data);
Expand Down
7 changes: 1 addition & 6 deletions features/notification/apis/use-read-notification.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,14 @@

import { useMutation } from '@tanstack/react-query';

import { NotificationType } from '../types';
import { NotificationReadResponse } from './dto';

async function readNotification(data: {
notificationId: number;
type: NotificationType;
}): Promise<NotificationReadResponse> {
async function readNotification(): Promise<NotificationReadResponse> {
const res = await fetch('/api/notification/read', {
method: 'PATCH',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(data),
});

// eslint-disable-next-line @typescript-eslint/no-unsafe-return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@ import {
formatDateToKoreanExceptYear,
} from '@/utils';

import { useReadNotification } from '../../apis/use-read-notification';
import { layoutStyles, textStyles } from '../../styles';
import { CheerNotificationProps } from '../../types';
import { CheerUpIcon } from '../atoms';

export function CheerNotification({
notificationId,
type,
memoryId,
hasRead,
Expand All @@ -22,14 +20,8 @@ export function CheerNotification({
content,
createdAt,
}: CheerNotificationProps) {
const { mutate: readNotification } = useReadNotification();

const handleListElementClick = () => {
readNotification({ notificationId, type });
};

return (
<Link href={`record-detail/${memoryId}`} onClick={handleListElementClick}>
<Link href={`record-detail/${memoryId}`}>
<li className={css(layoutStyles.total.raw({ hasRead }))}>
<CheerUpIcon />
<div className={css(layoutStyles.text.raw({ type }))}>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
'use client';

import { useEffect } from 'react';
import { Virtuoso } from 'react-virtuoso';

import { LoadingArea } from '@/components/atoms';
import { css } from '@/styled-system/css';

import { useGetNotification } from '../../apis';
import { useGetNotification, useReadNotification } from '../../apis';
import { FollowNotification, NoNotification } from '../molecules';
import { CheerNotification } from '../molecules/cheer-notification';
import { NotificationListSkeleton } from './notification-list-skeleton';
Expand All @@ -17,6 +18,7 @@ export function NotificationList() {
isFetchingNextPage,
getByFarNotificationData,
} = useGetNotification();
const { mutate: readNotification } = useReadNotification();

const handleRangeChanged = (range: { endIndex: number }) => {
const currentContentsLastIndex = getByFarNotificationData.length - 1;
Expand All @@ -25,6 +27,11 @@ export function NotificationList() {
}
};

useEffect(() => {
readNotification();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

if (isLoading) return <NotificationListSkeleton />;
return (
<ol className={layoutStyles}>
Expand Down
Loading