Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[genre] Implement subgenre dropdowns for search #89

Merged
merged 12 commits into from
Apr 24, 2024
63 changes: 13 additions & 50 deletions src/app/(tabs)/genre/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import {
FlatList,
} from 'react-native';

import { Dropdown, MultiSelect } from 'react-native-element-dropdown';
import { Icon } from 'react-native-elements';
import { TouchableOpacity } from 'react-native-gesture-handler';
import { SafeAreaView } from 'react-native-safe-area-context';

Expand All @@ -21,6 +19,7 @@ import { fetchGenreStoryById } from '../../../queries/genres';
import { fetchStoryPreviewByIds } from '../../../queries/stories';
import { StoryPreview, GenreStories } from '../../../queries/types';
import globalStyles from '../../../styles/globalStyles';
import { FilterDropdown } from '../../../components/FilterDropdown/FilterDropdown';

function GenreScreen() {
const [genreStoryData, setGenreStoryData] = useState<GenreStories[]>();
Expand Down Expand Up @@ -217,42 +216,6 @@ function GenreScreen() {
);
};

const renderFilterDropdown = (
placeholder: string,
value: string[],
data: string[],
setter: React.Dispatch<React.SetStateAction<string[]>>,
) => {
return (
<MultiSelect
mode="default"
style={[styles.dropdown, styles.secondDropdown]}
value={value}
placeholderStyle={styles.placeholderStyle}
selectedTextStyle={globalStyles.body1}
inputSearchStyle={globalStyles.body1}
itemTextStyle={globalStyles.body1}
dropdownPosition="bottom"
itemContainerStyle={styles.itemContainer}
iconStyle={styles.iconStyle}
data={data.map(topic => {
return { label: topic, value: topic };
})}
renderSelectedItem={() => <View />}
maxHeight={400}
labelField="label"
valueField="value"
placeholder={placeholder}
renderRightIcon={() => <Icon name="arrow-drop-down" type="material" />}
onChange={item => {
if (item) {
setter(item);
}
}}
/>
);
};

const renderNoStoryText = () => {
return (
<View>
Expand Down Expand Up @@ -306,18 +269,18 @@ function GenreScreen() {
</View>

<View style={[styles.dropdownContainer, styles.firstDropdown]}>
{renderFilterDropdown(
'Tone',
selectedTonesForFiltering,
toneFilterOptions,
setSelectedTonesForFiltering,
)}
{renderFilterDropdown(
'Topic',
selectedTopicsForFiltering,
topicFilterOptions,
setSelectedTopicsForFiltering,
)}
<FilterDropdown
placeholder="Topic"
value={selectedTopicsForFiltering}
data={topicFilterOptions}
setter={setSelectedTopicsForFiltering}
/>
<FilterDropdown
placeholder="Tone"
value={selectedTonesForFiltering}
data={toneFilterOptions}
setter={setSelectedTonesForFiltering}
/>
</View>

{genreStoryIds.length === 0 && !isLoading ? (
Expand Down
Loading
Loading