Skip to content

Commit

Permalink
Merge branch 'develop' into Feat/#3-HomeScreen
Browse files Browse the repository at this point in the history
  • Loading branch information
ChoeunKim committed Oct 1, 2024
2 parents 9160d4f + 9c49757 commit a5a2c71
Show file tree
Hide file tree
Showing 25 changed files with 1,222 additions and 64 deletions.
27 changes: 23 additions & 4 deletions app/(tabs)/Favorites.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,29 @@
import { View, Text } from "react-native";
import React from "react";
import { createNativeStackNavigator } from "@react-navigation/native-stack";
import FavoritesPage from "../favorites/FavoritesPage";
import FavoritesNoticePage from "../favorites/FavoritesNoticePage";
import FavoritesSchedulePage from "../favorites/FavoritesSchedulePage";

const FavoriteStack = createNativeStackNavigator();

export default function Favorites() {
return (
<View>
<Text>Favorites</Text>
</View>
<FavoriteStack.Navigator>
<FavoriteStack.Screen
name="Favorites"
component={FavoritesPage}
options={{ headerShown: false }}
/>
<FavoriteStack.Screen
name="FavoritesSchedule"
component={FavoritesSchedulePage}
options={{ headerShown: false }}
/>
<FavoriteStack.Screen
name="FavoritesNotice"
component={FavoritesNoticePage}
options={{ headerShown: false }}
/>
</FavoriteStack.Navigator>
);
}
6 changes: 3 additions & 3 deletions app/Category/CategoryListPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { initialCategory } from "@/assets/data/initialCategory";

const CategoryListPage = ({ navigation }: { navigation: any }) => {
const [data, setData] = useState<{ key: string; text: string }[]>([]);
const [loading, setLoading] = useState(true);
const [isLoading, setIsLoading] = useState(true);
const storageKey = "@category_order";

useEffect(() => {
Expand All @@ -26,7 +26,7 @@ const CategoryListPage = ({ navigation }: { navigation: any }) => {
console.error(error);
setData(initialCategory);
} finally {
setLoading(false);
setIsLoading(false);
}
};

Expand Down Expand Up @@ -78,7 +78,7 @@ const CategoryListPage = ({ navigation }: { navigation: any }) => {
카테고리
</Text>
</View>
{loading ? (
{isLoading ? (
<ActivityIndicator
size="large"
color={Color.BLACK}
Expand Down
46 changes: 8 additions & 38 deletions app/Category/CategorySearchPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
dummyCategorySearch,
} from "@/assets/data/dummyCategory";
import CategoryBackButton from "@/components/category/CategoryBackButton";
import CategoryButton from "@/components/category/CategoryButton";
import CategoryItem from "@/components/category/CategoryItem";
import CategoryEmpty from "@/components/category/CategoryEmpty";
import DropdownMenu from "@/components/category/DropdownMenu";
import Pagination from "@/components/category/Pagination";
Expand All @@ -12,8 +12,7 @@ import { Color, Font } from "@/constants/Theme";
import { TCategoryKey, TCategoryList } from "@/types/category";
import { RouteProp, useRoute } from "@react-navigation/native";
import React, { useEffect, useState } from "react";
import { ScrollView, View, Text, Pressable } from "react-native";
import Toast from "react-native-toast-message";
import { ScrollView, View, Text } from "react-native";

type CategorySearchRouteProp = RouteProp<
{ CategorySearch: { categoryText: string; categoryKey: TCategoryKey } },
Expand All @@ -35,7 +34,7 @@ const CategorySearchPage = ({ navigation }: { navigation: any }) => {
const [isSearch, setIsSearch] = useState(false);
const [search, setSearch] = useState("");
const [searchText, setSearchText] = useState("");
const [isLoading, setIsLoading] = useState(false);
const [isLoading, setIsLoading] = useState(true);

useEffect(() => {
setList(dummyCategory.items);
Expand All @@ -44,11 +43,11 @@ const CategorySearchPage = ({ navigation }: { navigation: any }) => {
size: dummyCategory.size,
totalItems: dummyCategory.totalItems,
});
setIsLoading(true);
setIsLoading(false);
}, [page]);

useEffect(() => {
if (isLoading) {
if (!isLoading) {
setTotalSize(Math.ceil((pageInfo.totalItems - pageInfo.size) / 10));
}
}, [isLoading]);
Expand All @@ -65,35 +64,6 @@ const CategorySearchPage = ({ navigation }: { navigation: any }) => {
}
};

//즐겨찾기
const onMarkedPress = (id: number, marked: boolean) => {
if (marked) {
// 이미 즐겨찾기인 경우 삭제
removeFromFavorites(id);
} else {
// 즐겨찾기가 아닌 경우 추가
addToFavorites(id);
}
};

//즐겨찾기 추가
const addToFavorites = (id: number) => {
Toast.show({
type: "success",
text1: "즐겨찾기 되었습니다!",
position: "bottom",
visibilityTime: 1500,
autoHide: true,
});

updateList(id);
};

//즐겨찾기 삭제
const removeFromFavorites = (id: number) => {
updateList(id);
};

const updateList = (id: number) => {
setList((prevList) =>
prevList.map((item) =>
Expand Down Expand Up @@ -141,7 +111,7 @@ const CategorySearchPage = ({ navigation }: { navigation: any }) => {
>
<Text
style={{
...Font.Category[14],
...Font.Pretendard500[14],
color: Color.contents.contentSecondary,
}}
>
Expand Down Expand Up @@ -183,11 +153,11 @@ const CategorySearchPage = ({ navigation }: { navigation: any }) => {
)}
{list.map((item, index) => {
return (
<CategoryButton
<CategoryItem
key={index}
item={item}
categoryKey={categoryKey}
onMarkedPress={onMarkedPress}
updateList={updateList}
/>
);
})}
Expand Down
1 change: 1 addition & 0 deletions app/_layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export default function RootLayout() {
Pretendard600: require("../assets/fonts/Pretendard-SemiBold.otf"),
Pretendard500: require("../assets/fonts/Pretendard-Medium.otf"),
Pretendard400: require("../assets/fonts/Pretendard-Regular.otf"),
Pretendard300: require("../assets/fonts/Pretendard-Light.otf"),
});

useEffect(() => {
Expand Down
77 changes: 77 additions & 0 deletions app/favorites/FavoritesNoticePage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import { Color } from "@/constants/Theme";
import React, { useEffect, useState } from "react";
import { View, ScrollView } from "react-native";
import { TCategoryKey, TCategorySearch } from "@/types/category";
import CategoryItem from "@/components/category/CategoryItem";
import { dummyFavoritesNotice } from "@/assets/data/dummyFavorites";
import FavoritesNoticeHeader from "@/components/header/FavoritesNoticeHeader";

const FavoritesNoticePage = () => {
const [noticelist, setNoticeList] = useState<TCategorySearch>({}); //즐겨찾기한 공지사항 목록
const [categoryKeyList, setCategoryKeyList] = useState<TCategoryKey[]>([]); //카테고리 목록
const [selectedCategoryKey, setSelectedCategoryKey] =
useState<TCategoryKey | null>(null); //선택한 카테고리
const [isLoading, setIsLoading] = useState(true);

useEffect(() => {
setNoticeList(dummyFavoritesNotice);
const keys = Object.keys(dummyFavoritesNotice) as TCategoryKey[];
setCategoryKeyList(keys);

if (keys.length > 0) {
setSelectedCategoryKey(keys[0]);
}
setIsLoading(false);
}, []);

const updateList = (id: number) => {
setNoticeList((prevList) => {
if (!prevList || !selectedCategoryKey || !prevList[selectedCategoryKey])
return prevList;

const updatedCategoryItems = prevList[selectedCategoryKey].map((item) =>
item.id === id ? { ...item, marked: !item.marked } : item
);

return {
...prevList,
[selectedCategoryKey]: updatedCategoryItems,
};
});
};

return (
<View
style={{
flex: 1,
backgroundColor: Color.WHITE,
}}
>
{!isLoading && (
<>
<FavoritesNoticeHeader
categoryKeyList={categoryKeyList}
selectedCategoryKey={selectedCategoryKey}
setSelectedCategoryKey={setSelectedCategoryKey}
/>
<ScrollView showsVerticalScrollIndicator={false}>
<View style={{ paddingBottom: 100 }}>
{selectedCategoryKey &&
noticelist[selectedCategoryKey] &&
noticelist[selectedCategoryKey].map((item, index) => (
<CategoryItem
key={index}
item={item}
categoryKey={selectedCategoryKey}
updateList={updateList}
/>
))}
</View>
</ScrollView>
</>
)}
</View>
);
};

export default FavoritesNoticePage;
83 changes: 83 additions & 0 deletions app/favorites/FavoritesPage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import { Color } from "@/constants/Theme";
import React, { useEffect, useState } from "react";
import { View, ScrollView } from "react-native";
import {
dummyFavoritesRecentNotice,
dummyRecentFavorites,
} from "@/assets/data/dummyFavorites";
import { TFavoritesList, TFavoritesRecentNoticeList } from "@/types/favorites";
import FavoritesNoticeItem from "@/components/favorites/FavoritesNoticeItem";
import FavoritesHeader from "@/components/header/FavoritesHeader";
import FavoritesEmpty from "@/components/favorites/FavoritesEmpty";
import FavoritesHead from "@/components/favorites/FavoritesHead";
import FavoritesScheduleItem from "@/components/favorites/FavoritesScheduleItem";

const FavoritesPage = ({ navigation }: { navigation: any }) => {
const [scheduleList, setScheduleList] = useState<TFavoritesList[]>([]); //최근 즐겨찾기한 학사일정 목록
const [noticelist, setNoticeList] = useState<TFavoritesRecentNoticeList[]>(
[]
); //최근 즐겨찾기한 공지사항 목록

useEffect(() => {
const updatedFavorites = dummyRecentFavorites.map((item) => ({
...item,
marked: true,
}));

setScheduleList(updatedFavorites);
setNoticeList(dummyFavoritesRecentNotice);
}, []);

const updateList = (id: number) => {
setScheduleList((prevList) =>
prevList.map((item) =>
item.id === id ? { ...item, marked: !item.marked } : item
)
);
};

return (
<View
style={{
flex: 1,
backgroundColor: Color.WHITE,
}}
>
<FavoritesHeader navigation={navigation} />
<ScrollView showsVerticalScrollIndicator={false}>
<FavoritesHead
text="학사일정"
isDisabled={scheduleList.length === 0}
onPress={() => navigation.navigate("FavoritesSchedule")}
/>
{scheduleList.length > 0 ? (
scheduleList.map((item, index) => {
return (
<FavoritesScheduleItem
key={index}
item={item}
updateList={updateList}
/>
);
})
) : (
<FavoritesEmpty text="학사일정" />
)}
<FavoritesHead
text="공지사항"
isDisabled={noticelist.length === 0}
onPress={() => navigation.navigate("FavoritesNotice")}
/>
{noticelist.length > 0 ? (
noticelist.map((item, index) => {
return <FavoritesNoticeItem key={index} item={item} />;
})
) : (
<FavoritesEmpty text="공지사항" />
)}
</ScrollView>
</View>
);
};

export default FavoritesPage;
Loading

0 comments on commit a5a2c71

Please sign in to comment.