-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add release list filters (None, on watch list, downloaded)
- Loading branch information
1 parent
0f2326c
commit f2dd6b1
Showing
4 changed files
with
143 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,123 @@ | ||
import * as React from 'react'; | ||
import {View, Keyboard, useWindowDimensions} from 'react-native'; | ||
import {Appbar, Button, Searchbar} from 'react-native-paper'; | ||
import {Appbar, Button, Dialog, Portal, Searchbar} from 'react-native-paper'; | ||
import Icon from 'react-native-vector-icons/MaterialCommunityIcons'; | ||
import {RadioButton} from 'react-native-paper'; | ||
import AsyncStorage from '@react-native-async-storage/async-storage'; | ||
|
||
interface ReleaseTabHeaderProps { | ||
onSearchChanged: (query: string) => void; | ||
onSearchCancelled: () => void; | ||
onFilterChanged: (filter: ShowFilter) => void; | ||
} | ||
export const ReleaseTabHeader = (props: ReleaseTabHeaderProps) => { | ||
const {onSearchChanged, onSearchCancelled} = props; | ||
|
||
export enum ShowFilter { | ||
None = '0', | ||
Downloaded = '1', | ||
Watching = '2', | ||
} | ||
|
||
export const ReleaseTabHeader = ({ | ||
onSearchChanged, | ||
onSearchCancelled, | ||
onFilterChanged, | ||
}: ReleaseTabHeaderProps) => { | ||
const {width} = useWindowDimensions(); | ||
const [searchQuery, setSearchQuery] = React.useState(''); | ||
const [filterPanelShown, setFilterPanelShown] = React.useState(false); | ||
const [checked, setChecked] = React.useState(ShowFilter.None); | ||
|
||
const onChangeText = (query: string) => { | ||
onSearchChanged(query); | ||
setSearchQuery(query); | ||
}; | ||
|
||
const onBackButtonPressed = () => { | ||
const onBackButtonPressed = async () => { | ||
onSearchCancelled(); | ||
setSearchQuery(''); | ||
Keyboard.dismiss(); | ||
const lastFilter = (await AsyncStorage.getItem( | ||
'headerFilter', | ||
)) as ShowFilter | null; | ||
if (lastFilter) { | ||
setChecked(lastFilter); | ||
onFilterChanged(lastFilter); | ||
} | ||
}; | ||
|
||
const onFilterPressed = async (filterValue: ShowFilter) => { | ||
setChecked(filterValue); | ||
onFilterChanged(filterValue); | ||
await AsyncStorage.setItem('headerFilter', filterValue); | ||
}; | ||
|
||
const toggleFilterPanel = () => { | ||
setFilterPanelShown(!filterPanelShown); | ||
}; | ||
|
||
React.useEffect(() => { | ||
(async () => { | ||
const lastFilter = (await AsyncStorage.getItem( | ||
'headerFilter', | ||
)) as ShowFilter | null; | ||
if (lastFilter) { | ||
setChecked(lastFilter); | ||
onFilterChanged(lastFilter); | ||
} | ||
})(); | ||
}, [onFilterChanged]); | ||
|
||
return ( | ||
<Appbar.Header statusBarHeight={1}> | ||
<View style={{display: 'flex', flexDirection: 'row'}}> | ||
<Button | ||
mode="text" | ||
compact | ||
contentStyle={{flexDirection: 'row-reverse'}} | ||
style={{paddingTop: 5}} | ||
onPress={onBackButtonPressed}> | ||
<Icon name="arrow-left" size={24} color="#fff" /> | ||
</Button> | ||
<Searchbar | ||
placeholder="Search" | ||
onChangeText={onChangeText} | ||
value={searchQuery} | ||
style={{flexGrow: 1, width: width - 50}} | ||
/> | ||
</View> | ||
</Appbar.Header> | ||
<> | ||
<Appbar.Header statusBarHeight={1}> | ||
<View style={{display: 'flex', flexDirection: 'row'}}> | ||
<Button | ||
mode="text" | ||
compact | ||
contentStyle={{flexDirection: 'row-reverse'}} | ||
style={{paddingTop: 5}} | ||
onPress={onBackButtonPressed}> | ||
<Icon name="arrow-left" size={24} color="#fff" /> | ||
</Button> | ||
<Searchbar | ||
placeholder="Search" | ||
onChangeText={onChangeText} | ||
value={searchQuery} | ||
style={{flexGrow: 1, width: width - 100}} | ||
/> | ||
<Button | ||
mode="text" | ||
compact | ||
contentStyle={{flexDirection: 'row-reverse'}} | ||
style={{paddingTop: 5}} | ||
onPress={toggleFilterPanel}> | ||
<Icon name="filter-variant" size={24} color="#fff" /> | ||
</Button> | ||
</View> | ||
</Appbar.Header> | ||
<Portal> | ||
<Dialog visible={filterPanelShown} onDismiss={toggleFilterPanel}> | ||
<Dialog.Title>Filter</Dialog.Title> | ||
<Dialog.Content> | ||
<RadioButton.Group | ||
onValueChange={value => onFilterPressed(value as ShowFilter)} | ||
value={checked}> | ||
<RadioButton.Item label="No filter" value={ShowFilter.None} /> | ||
<RadioButton.Item | ||
label="Watching shows" | ||
value={ShowFilter.Watching} | ||
/> | ||
<RadioButton.Item | ||
label="Downloaded shows" | ||
value={ShowFilter.Downloaded} | ||
/> | ||
</RadioButton.Group> | ||
</Dialog.Content> | ||
<Dialog.Actions> | ||
<Button onPress={toggleFilterPanel}>Done</Button> | ||
</Dialog.Actions> | ||
</Dialog> | ||
</Portal> | ||
</> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters