Select Department

This commit is contained in:
mattdimegs 2024-10-02 12:31:16 -04:00
parent 92b06f6292
commit ee2383e88a

View file

@ -15,7 +15,7 @@ const typeMap = {
Rescue: 'Fire & EMS' Rescue: 'Fire & EMS'
} }
const deptList = [ const initList = [
{ {
deptId: 0, deptId: 0,
dept: 'Darien EMS', dept: 'Darien EMS',
@ -53,14 +53,33 @@ const deptList = [
export default function Landing() { export default function Landing() {
const actionSheetRef = useRef(null); const actionSheetRef = useRef(null);
const selectedDepartment = deptList?.find((dept) => { const [deptList, setDeptList] = useState(initList);
return dept?.selected; const [selectedDepartment, setSelectedDepartment] = useState(deptList?.find((dept) => {
}); return dept?.primary;
}));
const updateSelectedDepartment = (currentSelectedId, newSelectedId) => { const updateSelectedDepartment = (currentSelectedId, newSelectedId) => {
console.log('items: ', currentSelectedId, newSelectedId); if (currentSelectedId !== newSelectedId) {
setDeptList(deptList?.map((item) => {
if (item?.selected) {
item.selected = false;
}
if (item?.deptId === newSelectedId) {
item.selected = true;
}
return item;
}))
}
}; };
useEffect(() => {
if (deptList) {
setSelectedDepartment(deptList?.find((dept) => {
return dept?.selected;
}));
}
}, [deptList])
return ( return (
<React.Fragment> <React.Fragment>
<PageHeader> <PageHeader>
@ -102,10 +121,17 @@ export default function Landing() {
marginVertical: 6, marginVertical: 6,
padding: 10 padding: 10
}} }}
onPress={() => {return updateSelectedDepartment(selectedDepartment?.deptId, item?.deptId)}}
> >
<View style={{ flexDirection: 'row' }}> <View style={{ flexDirection: 'row', justifyContent: 'space-between' }}>
<Text style={{ color: 'black', fontWeight: 600, fontSize: '16px' }}>{item?.dept}</Text> <Text style={{ color: 'black', fontWeight: 600, fontSize: '16px' }}>{item?.dept}</Text>
{item?.primary ? <Text>*</Text> : null} {item?.primary ? <Ionicons name="star" size={16} color="yellow" style={{
paddingLeft: 20,
shadowColor: '#333',
shadowOffset: 1,
shadowOpacity: 1,
shadowRadius: 6
}} /> : null}
</View> </View>
<Text>{`${item?.deptAbv} - ${typeMap[item?.type]}`}</Text> <Text>{`${item?.deptAbv} - ${typeMap[item?.type]}`}</Text>
</TouchableOpacity> </TouchableOpacity>