Skip to content
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
22 changes: 19 additions & 3 deletions app/(team)/alarm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ import {
} from "@/shared/ui";
import NemoText from "@/shared/ui/atoms/NemoText";
import Tab from "@/shared/ui/atoms/Tab";
import { getAlertNavigationTarget } from "@/shared/utils/alertNavigation";
import { AntDesign } from "@expo/vector-icons";
import { useRouter } from "expo-router";
import type { Href } from "expo-router";
import { useMemo, useState } from "react";
import { FlatList, Pressable, StyleSheet, View } from "react-native";
import { SafeAreaView } from "react-native-safe-area-context";
Expand Down Expand Up @@ -60,9 +62,18 @@ const AlarmScreen = ({}: AlarmScreenProps) => {
};

const handlePressAlert =
(alertId: number, teamId: number, read: boolean) => () => {
(alertId: number, type: string, teamId: number, read: boolean) => () => {
if (!read) markAsRead.mutate(alertId);
route.push(`/${teamId}/calendar`);

const target = getAlertNavigationTarget({ type, teamId });
if (!target) return;

if (target.method === "replace") {
route.replace(target.href as Href);
return;
}

route.push(target.href as Href);
};
return (
<SafeAreaView style={[filteredAlarms.length == 0 && styles.container]}>
Expand Down Expand Up @@ -98,7 +109,12 @@ const AlarmScreen = ({}: AlarmScreenProps) => {
renderItem={({ item }) => (
<Pressable
style={styles.alarmContainer}
onPress={handlePressAlert(item.id, item.teamId, item.isRead)}
onPress={handlePressAlert(
item.id,
item.type,
item.teamId,
item.isRead
)}
>
<NemoText
level="body2"
Expand Down
20 changes: 12 additions & 8 deletions app/_layout.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { globalGray50 } from "@/shared/ui";
import { getAlertNavigationTarget } from "@/shared/utils/alertNavigation";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import {
addNotificationResponseReceivedListener,
useLastNotificationResponse,
} from "expo-notifications";
import { Stack, useRouter } from "expo-router";
import type { Href } from "expo-router";
import { useEffect } from "react";
import { SafeAreaProvider } from "react-native-safe-area-context";
const queryClient = new QueryClient();
Expand All @@ -13,16 +15,18 @@ export default function RootLayout() {
const lastNotificationResponse = useLastNotificationResponse();

const handleRouting = (data: any) => {
if (!data?.type) return;
const target = getAlertNavigationTarget({
type: data?.type,
teamId: data?.teamId,
});
if (!target) return;

switch (data.type) {
case "SCHEDULE_ASSIGNEE_ADDED":
router.push(`/${data.teamId}`);
break;

default:
break;
if (target.method === "replace") {
router.replace(target.href as Href);
return;
}

router.push(target.href as Href);
};

// 🔹 앱이 종료 상태였다가 켜진 경우 처리
Expand Down
4 changes: 3 additions & 1 deletion features/notifications/types/alert.model.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import type { AlertType } from "@/shared/utils/alertNavigation";

export interface AlertResponse {
id: number;
type: string;
type: AlertType;
teamId: number;
teamName: string;
content: string;
Expand Down
6 changes: 3 additions & 3 deletions shared/ui/molecules/CalendarWeek.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ const CalendarWeek = ({
}

const { selectedDate } = calendarContext;
const MAX_LANES = height > 1200 ? 6 : 4;
const MAX_LANES = height > 1200 ? maxLanes + 2 : maxLanes;
const totalHeight = DATES_HEIGHT + MAX_LANES * (LANE_HEIGHT + LANE_GAP);

const handleWeekPress = (event: GestureResponderEvent) => {
Expand Down Expand Up @@ -125,7 +125,7 @@ const CalendarWeekDates = ({
const { width, height } = useWindowDimensions();
const WEEK_WIDTH = width - 40;
const DAY_WIDTH = WEEK_WIDTH / 7;
const MAX_LANES = height > 1200 ? 6 : 4; // Replace 600 with the appropriate threshold value
const MAX_LANES = height > 1200 ? maxLanes + 2 : maxLanes; // Replace 600 with the appropriate threshold value

const totalHeight = DATES_HEIGHT + MAX_LANES * (LANE_HEIGHT + LANE_GAP);
return (
Expand Down Expand Up @@ -172,7 +172,7 @@ const CalendarWeekSchedules = ({
);
}
const { width, height } = useWindowDimensions();
const MAX_LANES = height > 1200 ? 6 : 4; // Replace 600 with the appropriate threshold value
const MAX_LANES = height > 1200 ? maxLanes + 2 : maxLanes; // Replace 600 with the appropriate threshold value

const weekSchedules = getWeekSchedules(dates, schedules); // maxVisible 쓰면 여기서 자르세요

Expand Down
5 changes: 3 additions & 2 deletions shared/ui/templates/CalendarDetailModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,9 @@ const CalendarDetailModal = ({
<View style={styles.row}>
<View
style={{
backgroundColor: data.representativeColorHex,
width: 1,
backgroundColor: data.representativeColorHex ?? "#BDBDBD",
width: 3,
borderRadius: 2,
marginRight: 4,
}}
/>
Expand Down
3 changes: 3 additions & 0 deletions shared/ui/templates/ScheduleListModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -434,9 +434,12 @@ const styles = StyleSheet.create({
flexDirection: "row",
gap: 4,
marginVertical: 8,
justifyContent: "center",
alignItems: "center",
},
border: {
width: 3,
height: 16,
borderRadius: 2,
},
});
Expand Down
51 changes: 51 additions & 0 deletions shared/utils/alertNavigation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
export type AlertType =
| "SCHEDULE_ASSIGNEE_ADDED"
| "SCHEDULE_POSITION_ADDED"
| "NOTICE_UPDATED"
| "TODO_DUE_TODAY"
| "TEAM_MEMBER_JOINED"
| "TEAM_DISSOLVED";

type AlertNavigationTarget = {
href: string;
method: "push" | "replace";
};

const toTeamId = (teamId: number | string | null | undefined) => {
if (teamId == null) return null;
const parsed = Number(teamId);
if (Number.isNaN(parsed)) return null;
return parsed;
};

export const getAlertNavigationTarget = (params: {
type?: string | null;
teamId?: number | string | null;
}): AlertNavigationTarget | null => {
const { type, teamId } = params;
if (!type) return null;

const parsedTeamId = toTeamId(teamId);

switch (type as AlertType) {
case "SCHEDULE_ASSIGNEE_ADDED":
case "SCHEDULE_POSITION_ADDED":
case "NOTICE_UPDATED":
if (parsedTeamId == null) return null;
return { href: `/${parsedTeamId}/calendar`, method: "push" };

case "TODO_DUE_TODAY":
if (parsedTeamId == null) return null;
return { href: `/${parsedTeamId}/calendar/todos`, method: "push" };

case "TEAM_MEMBER_JOINED":
if (parsedTeamId == null) return null;
return { href: `/(team)/members?teamId=${parsedTeamId}`, method: "push" };

case "TEAM_DISSOLVED":
return { href: "/teams/check", method: "replace" };

default:
return null;
}
};