I am making Learn Reminder App for that I am mapping a static array of weeks and inside that map i am mapping another array(reminderData) which i am fetching it from database to compare both array and if the weekDay matches with the Parent Map that is weeks array than I am just showing the time. But due to my turnary Operator condition my data is mixed with Set Time and data present in database. How do I optimize my code to show time for that particular week if present in db or show set time instead.
const weeks = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"];
<View style={{ flex: 1, borderWidth: 1, borderRadius: 10, marginTop: "3%", height: "50%" }}>
{
weeks.length > 0 &&
weeks.map((week, index) => (
<View key={index}>
<View style={{ flexDirection: 'row', marginHorizontal: "5%", flexDirection: 'row' }}>
<Text style={{ flex: 1, paddingTop: 13, color: 'black', fontSize: 18, fontWeight: 'bold' }} >{week}</Text>
{
reminderData.map((data, index2) => (
<React.Fragment key={index2}>
{
(data.WeekDay == week) ?
<Pressable onPress={() => updateTimePicker(data, index)}>
<Text onPress={() => updateTimePicker(data, index)} key={index} style={{ justifyContent: 'flex-end', paddingTop: 13, color: 'black', fontSize: 18, }}>{moment(data.Time).format('hh:mm A')}</Text>
</Pressable> :
<Pressable onPress={() => openTimePicker(week, index)}>
<Text onPress={() => openTimePicker(week, index)} key={index} style={{ justifyContent: 'flex-end', paddingTop: 13, color: 'black', fontSize: 18, }}>Set Time</Text>
</Pressable>
}
</React.Fragment>
))
}
</View>
<View
style={{
marginTop: 8,
borderBottomColor: 'black',
borderBottomWidth: StyleSheet.hairlineWidth,
}}
/>
</View>
))
}
</View>
