Skip to content

Commit

Permalink
Merge pull request #44 from dsc-sookmyung/feature/search
Browse files Browse the repository at this point in the history
refactor: update types
  • Loading branch information
hee-suh authored Mar 23, 2022
2 parents e82a549 + f76e861 commit 1a6870c
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 142 deletions.
9 changes: 5 additions & 4 deletions react-native/components/SearchedNotice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ import { AntDesign } from '@expo/vector-icons';
import { theme } from '../core/theme';

interface SearchedNoticeProps {
id: number
date: string
summariedNotices: string[]
saved_titles: string[]
}

export default function SearchedNotice(props: SearchedNoticeProps) {
Expand All @@ -36,7 +37,7 @@ export default function SearchedNotice(props: SearchedNoticeProps) {

return (
<View style={[styles.container, {
height: componentOpened ? (80 + props.summariedNotices.length * 22): 60,
height: componentOpened ? (80 + props.saved_titles.length * 22): 60,
paddingBottom: componentOpened ? 20: 0
}]}>
<View style={styles.headerContainer}>
Expand All @@ -49,9 +50,9 @@ export default function SearchedNotice(props: SearchedNoticeProps) {
</TouchableHighlight>
</View>
{componentOpened && (
<TouchableHighlight onPress={() => navigation.navigate('SearchResult', {date: props.date})}>
<TouchableHighlight onPress={() => navigation.navigate('SearchResult', {id: props.id})}>
<View>
{props.summariedNotices.map((notice, index) =>
{props.saved_titles.map((notice, index) =>
<Text style={styles.notices}>{(index + 1) + ". " + notice}</Text>
)}
</View>
Expand Down
50 changes: 25 additions & 25 deletions react-native/screens/SearchResultScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,46 +14,46 @@ interface SearchResultScreenProps {
key: string,
name: string,
params: {
date: string
id: number
},
path: string | undefined,
}
}

export default function SearchResultScreen(props: SearchResultScreenProps) {
const [imageUri, setImageUri] = useState("../assets/images/calendar.png");
const [notice, setNotice] = useState<Notice>({cid: 2, date: "", notices: {total_results: [], notice_body: []}});
const [notice, setNotice] = useState<Notice>({id: 1, cid: 2, date: "", saved_titles: [], results: []});
const [showKorean, setShowKorean] = useState<boolean>(false);
const [isFullDrawer, setFullDrawer] = useState<boolean>(false);

useEffect(() => {
// TODO: Fetch API
// search/{props.route.params.id}
setNotice({
id: 1,
cid: 1,
date: "2022-02-10",
notices: {
total_results: [
"17th Graduation Ceremony",
"School Day"
saved_titles: [
"17th Graduation Ceremony",
"School Day"
],
results: [{
id: 1,
imageUri: '',
fullText: [
{id: 1, content: "1. Schedule of the closing ceremony and diploma presentation ceremony: Friday, January 4, 2019 at 9 o'clock for students to go to school.\n1) ", date: "", highlight: false, registered: false},
{id: 2, content: "Closing ceremony", date: "2022-01-04", highlight: true, registered: false}
],
notice_body: [{
id: 1,
title: "17th Graduation Ceremony",
fullText: [
{id: 1, content: "1. Schedule of the closing ceremony and diploma presentation ceremony: Friday, January 4, 2019 at 9 o'clock for students to go to school.\n1) ", date: "", highlight: false, registered: false},
{id: 2, content: "Closing ceremony", date: "2022-01-04", highlight: true, registered: false}
],
korean: "희망찬 새해를 맞이하여 학부모님의 가정에 건강과 행복이 함께 하시기를 기원합니다."
}, {
id: 2,
title: "School Day",
fullText: [
{id: 1, content: "1. Schedule of the closing ceremony and diploma presentation ceremony: Friday, January 4, 2019 at 9 o'clock for students to go to school.\n1) ", date: "", highlight: false, registered: false},
{id: 2, content: "Closing ceremony", date: "2022-01-04", highlight: true, registered: false}
],
korean: "개학일은 3월 2일이며, 개학식에 참여하고자 하는 학부모님께서는 10시까지 강당으로 오시기 바랍니다."
}]
}
korean: "희망찬 새해를 맞이하여 학부모님의 가정에 건강과 행복이 함께 하시기를 기원합니다."
}, {
id: 2,
imageUri: '',
fullText: [
{id: 1, content: "1. Schedule of the closing ceremony and diploma presentation ceremony: Friday, January 4, 2019 at 9 o'clock for students to go to school.\n1) ", date: "", highlight: false, registered: false},
{id: 2, content: "Closing ceremony", date: "2022-01-04", highlight: true, registered: false}
],
korean: "개학일은 3월 2일이며, 개학식에 참여하고자 하는 학부모님께서는 10시까지 강당으로 오시기 바랍니다."
}]
})
}, [])

Expand All @@ -64,7 +64,7 @@ export default function SearchResultScreen(props: SearchResultScreenProps) {
return (
<View style={styles.container}>
<Swiper>
{notice && notice.notices.notice_body.length > 0 && notice.notices.notice_body.map((notice, index) =>
{notice?.results && notice.results.length > 0 && notice.results.map((notice, index) =>
<ImageBackground style={styles.container} resizeMode="cover" imageStyle={{ opacity: 0.5 }} source={{ uri: imageUri }} key={"ib_" + index}>
<SwipeUpDown
itemMini={
Expand Down
145 changes: 41 additions & 104 deletions react-native/screens/SearchScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,112 +12,49 @@ export default function SearchScreen({ navigation }: Navigation) {
const auth = useAuth(); // TODO: get notices by send header(`auth.AuthData`) to server

const [search, setSearch] = useState<string>('');
const [filteredNotices, setFilteredNotices] = useState<Notice[]>([{
cid: 1,
date: "2022-02-19",
notices: {
total_results: [
"17th Graduation Ceremony",
"School Day"
],
notice_body: [{
const [filteredNotices, setFilteredNotices] = useState<Notice[]>(
[
{
id: 1,
title: "17th Graduation Ceremony",
fullText: [
{id: 1, content: "1. Schedule of the closing ceremony and diploma presentation ceremony: Friday, January 4, 2019 at 9 o'clock for students to go to school.\n1) ", date: "", highlight: false, registered: false},
{id: 2, content: "Closing ceremony", date: "2022-01-04", highlight: true, registered: false}
],
korean: "희망찬 새해를 맞이하여 학부모님의 가정에 건강과 행복이 함께 하시기를 기원합니다."
}, {
id: 2,
title: "School Day",
fullText: [
{id: 1, content: "1. Schedule of the closing ceremony and diploma presentation ceremony: Friday, January 4, 2019 at 9 o'clock for students to go to school.\n1) ", date: "", highlight: false, registered: false},
{id: 2, content: "Closing ceremony", date: "2022-01-04", highlight: true, registered: false}
],
korean: "개학일은 3월 2일이며, 개학식에 참여하고자 하는 학부모님께서는 10시까지 강당으로 오시기 바랍니다."
}]
}
}, {
cid: 1,
date: "2022-02-10",
notices: {
total_results: [
"17th Graduation Ceremony",
"School Day"
],
notice_body: [{
cid: 1,
date: "2022-02-19",
saved_titles: [
"17th Graduation Ceremony",
"School Day"
]
},
{
id: 1,
title: "17th Graduation Ceremony",
fullText: [
{id: 1, content: "1. Schedule of the closing ceremony and diploma presentation ceremony: Friday, January 4, 2019 at 9 o'clock for students to go to school.\n1) ", date: "", highlight: false, registered: false},
{id: 2, content: "Closing ceremony", date: "2022-01-04", highlight: true, registered: false}
],
korean: "희망찬 새해를 맞이하여 학부모님의 가정에 건강과 행복이 함께 하시기를 기원합니다."
}, {
id: 2,
title: "School Day",
fullText: [
{id: 1, content: "1. Schedule of the closing ceremony and diploma presentation ceremony: Friday, January 4, 2019 at 9 o'clock for students to go to school.\n1) ", date: "", highlight: false, registered: false},
{id: 2, content: "Closing ceremony", date: "2022-01-04", highlight: true, registered: false}
],
korean: "개학일은 3월 2일이며, 개학식에 참여하고자 하는 학부모님께서는 10시까지 강당으로 오시기 바랍니다."
}]
}
}]);
const [notices, setNotices] = useState<Notice[]>([{
cid: 1,
date: "2022-02-19",
notices: {
total_results: [
"17th Graduation Ceremony",
"School Day"
],
notice_body: [{
cid: 1,
date: "2022-02-10",
saved_titles: [
"17th Graduation Ceremony",
"School Day"
]
}
]
);
const [notices, setNotices] = useState<Notice[]>(
[
{
id: 1,
title: "17th Graduation Ceremony",
fullText: [
{id: 1, content: "1. Schedule of the closing ceremony and diploma presentation ceremony: Friday, January 4, 2019 at 9 o'clock for students to go to school.\n1) ", date: "", highlight: false, registered: false},
{id: 2, content: "Closing ceremony", date: "2022-01-04", highlight: true, registered: false}
],
korean: "희망찬 새해를 맞이하여 학부모님의 가정에 건강과 행복이 함께 하시기를 기원합니다."
}, {
id: 2,
title: "School Day",
fullText: [
{id: 1, content: "1. Schedule of the closing ceremony and diploma presentation ceremony: Friday, January 4, 2019 at 9 o'clock for students to go to school.\n1) ", date: "", highlight: false, registered: false},
{id: 2, content: "Closing ceremony", date: "2022-01-04", highlight: true, registered: false}
],
korean: "개학일은 3월 2일이며, 개학식에 참여하고자 하는 학부모님께서는 10시까지 강당으로 오시기 바랍니다."
}]
}
}, {
cid: 1,
date: "2022-02-10",
notices: {
total_results: [
"17th Graduation Ceremony",
"School Day"
],
notice_body: [{
cid: 1,
date: "2022-02-19",
saved_titles: [
"17th Graduation Ceremony",
"School Day"
]
},
{
id: 1,
title: "17th Graduation Ceremony",
fullText: [
{id: 1, content: "1. Schedule of the closing ceremony and diploma presentation ceremony: Friday, January 4, 2019 at 9 o'clock for students to go to school.\n1) ", date: "", highlight: false, registered: false},
{id: 2, content: "Closing ceremony", date: "2022-01-04", highlight: true, registered: false}
],
korean: "희망찬 새해를 맞이하여 학부모님의 가정에 건강과 행복이 함께 하시기를 기원합니다."
}, {
id: 2,
title: "School Day",
fullText: [
{id: 1, content: "1. Schedule of the closing ceremony and diploma presentation ceremony: Friday, January 4, 2019 at 9 o'clock for students to go to school.\n1) ", date: "", highlight: false, registered: false},
{id: 2, content: "Closing ceremony", date: "2022-01-04", highlight: true, registered: false}
],
korean: "개학일은 3월 2일이며, 개학식에 참여하고자 하는 학부모님께서는 10시까지 강당으로 오시기 바랍니다."
}]
}
}])
cid: 1,
date: "2022-02-10",
saved_titles: [
"17th Graduation Ceremony",
"School Day"
]
}
])
const [isDatePickerVisible, setDatePickerVisibility] = useState(false);
const [searchDate, setSearchDate] = useState<string>("Click calendar icon to select date.");

Expand Down Expand Up @@ -147,7 +84,7 @@ export default function SearchScreen({ navigation }: Navigation) {
const searchFilter = (text: string | void) => {
if (text) {
const newData = notices.filter((notice) => {
const noticeData = notice.notices.total_results.join().toUpperCase();
const noticeData = notice.saved_titles.join().toUpperCase();
const textData = text.toUpperCase();
return noticeData.indexOf(textData) > -1;
})
Expand Down Expand Up @@ -188,7 +125,7 @@ export default function SearchScreen({ navigation }: Navigation) {
<View style={styles.searchResults}>
<Text style={styles.smallDescription}>RESULTS</Text>
{filteredNotices?.map((notice, index) =>
<SearchedNotice date={notice.date} summariedNotices={notice.notices.total_results} key={"nt_" + index}/>
<SearchedNotice key={"nt_" + index} id={notice.id} date={notice.date} saved_titles={notice.saved_titles} />
)}
</View>
</View>
Expand Down
13 changes: 4 additions & 9 deletions react-native/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,22 +67,17 @@ interface Event {

interface Result {
id: number,
imageUri?: string,
fullText: Event[],
korean: string
}

interface Notice {
id: number,
cid: number,
date: string,
notices: {
total_results: string[],
notice_body: {
title: string,
id: number,
fullText: Event[],
korean: string,
}[]
}
saved_titles: string[],
results?: Result[]
}

interface BottomDrawerProps {
Expand Down

0 comments on commit 1a6870c

Please sign in to comment.