Skip to content

Commit

Permalink
feat: filter button
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviaseds committed Feb 29, 2024
1 parent 5cb2b67 commit f088c0a
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 59 deletions.
6 changes: 5 additions & 1 deletion client/babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ module.exports = function (api) {

return {
presets: ['babel-preset-expo'],
plugins: ['react-native-paper/babel', 'nativewind/babel']
plugins: [
'react-native-paper/babel',
'nativewind/babel',
'react-native-reanimated/plugin'
]
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import React from 'react';
import { useNavigation } from '@react-navigation/native';
import { IconButton } from 'react-native-paper';

import BackArrow from '../assets/back-arrow.svg';
import { AppStackNavigation } from '../navigation/AppNavigation';
import BackArrow from '../../assets/back-arrow.svg';
import { AppStackNavigation } from '../../navigation/AppNavigation';

export function BackButton() {
const navigation = useNavigation<AppStackNavigation>();
Expand Down
5 changes: 4 additions & 1 deletion client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
},
"dependencies": {
"@firebase/auth": "^1.5.1",
"@gorhom/bottom-sheet": "^4.6.1",
"@react-native-async-storage/async-storage": "1.21.0",
"@react-navigation/bottom-tabs": "^6.5.11",
"@react-navigation/native": "^6.1.9",
Expand All @@ -35,7 +36,9 @@
"react-native-paper": "^5.12.3",
"react-native-safe-area-context": "4.8.2",
"react-native-screens": "~3.29.0",
"react-native-svg-transformer": "^1.3.0"
"react-native-svg-transformer": "^1.3.0",
"react-native-reanimated": "~3.6.2",
"react-native-gesture-handler": "~2.14.0"
},
"devDependencies": {
"@babel/core": "^7.20.0",
Expand Down
161 changes: 106 additions & 55 deletions client/screens/TaskType.tsx
Original file line number Diff line number Diff line change
@@ -1,79 +1,130 @@
import React, { useState } from 'react';
import React, {
useCallback,
useEffect,
useMemo,
useRef,
useState
} from 'react';
import { ScrollView, View } from 'react-native';

import BottomSheet, { BottomSheetBackdrop } from '@gorhom/bottom-sheet';
import { BottomSheetDefaultBackdropProps } from '@gorhom/bottom-sheet/lib/typescript/components/bottomSheetBackdrop/types';
import { useNavigation } from '@react-navigation/native';
import DropDownPicker from 'react-native-dropdown-picker';
import { GestureHandlerRootView } from 'react-native-gesture-handler';
import { Button, Text } from 'react-native-paper';
import { SafeAreaView } from 'react-native-safe-area-context';

import { BackButton } from '../components/BackButton';
import { BackButton } from '../components/TaskType/BackButton';
import { AppStackNavigation } from '../navigation/AppNavigation';
import { TypeOfTask } from '../types/type';
import { Category, categoryToTypeMap, TypeOfTask } from '../types/type';

export function TaskType() {
const navigation = useNavigation<AppStackNavigation>();

// const [open, setOpen] = useState(false);
// const [selectedCategory, setSelectedCategory] = useState<null | Category>(
// null
// );
const [selectedTypes] = useState<TypeOfTask[]>(Object.values(TypeOfTask));
const [open, setOpen] = useState(false);
const [selectedCategory, setSelectedCategory] = useState<null | Category>(
null
);
const [selectedTypes, setSelectedTypes] = useState<TypeOfTask[]>(
Object.values(TypeOfTask)
);

// useEffect(() => {
// setSelectedTypes(
// selectedCategory
// ? categoryToTypeMap[selectedCategory]
// : Object.values(TypeOfTask)
// );
// }, [selectedCategory]);
useEffect(() => {
setSelectedTypes(
selectedCategory
? categoryToTypeMap[selectedCategory]
: Object.values(TypeOfTask)
);
}, [selectedCategory]);

// const filters = Object.values(Category).map((filter) => ({
// label: filter,
// value: filter
// }));
const filters = Object.values(Category).map((filter) => ({
label: filter,
value: filter
}));

return (
<SafeAreaView>
<View className="my-0 flex w-full flex-row items-center justify-center">
<View className="mr-[95px]">
<BackButton />
</View>
<Text className="mr-auto self-center text-center text-carewallet-gray">
Step 1 of 2
</Text>
</View>
const snapPoints = useMemo(() => ['50%'], []);

<Text className="text-center text-2xl font-bold">Type of Task</Text>
<View className="mr-2 flex flex-row justify-end">
<Button
className="h-[40px] items-center justify-center rounded-xl text-sm"
textColor="black"
mode="outlined"
>
Filter
</Button>
</View>
const bottomSheetRef = useRef<BottomSheet>(null);

const snapToIndex = (index: number) =>
bottomSheetRef.current?.snapToIndex(index);
const renderBackdrop = useCallback(
(props: BottomSheetDefaultBackdropProps) => (
<BottomSheetBackdrop
appearsOnIndex={0}
disappearsOnIndex={-1}
{...props}
/>
),
[]
);

{/* <DropDownPicker
open={open}
value={selectedCategory}
items={filters}
setOpen={setOpen}
setValue={setSelectedCategory}
/> */}
return (
<GestureHandlerRootView>
<SafeAreaView>
<View className="flex w-full flex-row items-center justify-center">
<View className="mr-[95px]">
<BackButton />
</View>
<Text className="mr-auto self-center text-center text-carewallet-gray">
Step 1 of 2
</Text>
</View>

<ScrollView style={{ marginTop: 10, marginBottom: 150 }}>
{selectedTypes.map((type) => (
<Text className="text-center text-2xl font-bold">Type of Task</Text>
<View className="mr-2 flex flex-row justify-end">
<Button
className="m-2 h-[50px] items-center justify-center rounded-xl"
className="h-[40px] items-center justify-center rounded-xl text-sm"
textColor="black"
key={type}
mode="outlined"
onPress={() => navigation.navigate('New ' + type)} // TODO other screens should have this name
onPress={() => snapToIndex(0)}
>
{type}
Filter
</Button>
))}
</ScrollView>
</SafeAreaView>
</View>

<ScrollView style={{ height: 850 }}>
{selectedTypes.map((type) => (
<Button
className="m-2 h-[50px] items-center justify-center rounded-xl"
textColor="black"
key={type}
mode="outlined"
onPress={() => navigation.navigate('New ' + type)} // TODO other screens should have this name
>
{type}
</Button>
))}
</ScrollView>
<BottomSheet
ref={bottomSheetRef}
index={0}
snapPoints={snapPoints}
enablePanDownToClose={true}
backdropComponent={renderBackdrop}
>
<View>
<Text className="m-5 text-2xl font-bold">Filter</Text>
<DropDownPicker
open={open}
value={selectedCategory}
items={filters}
setOpen={setOpen}
setValue={setSelectedCategory}
placeholder="Category"
style={{
width: '95%',
marginLeft: 'auto',
marginRight: 'auto',
borderRadius: 0,
borderColor: 'transparent',
borderBottomColor: 'black'
}}
/>
</View>
</BottomSheet>
</SafeAreaView>
</GestureHandlerRootView>
);
}

0 comments on commit f088c0a

Please sign in to comment.