-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add keyword and instance filtering (#824)
- Loading branch information
Showing
10 changed files
with
504 additions
and
14 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
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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import React from "react"; | ||
import { useTranslation } from "react-i18next"; | ||
import { ScrollView, useTheme } from "native-base"; | ||
import { StyleSheet } from "react-native"; | ||
import { TableView } from "@gkasdorf/react-native-tableview-simple"; | ||
import { NativeStackNavigationProp } from "@react-navigation/native-stack"; | ||
import CSection from "../../../common/Table/CSection"; | ||
import CCell from "../../../common/Table/CCell"; | ||
|
||
interface IProps { | ||
navigation: NativeStackNavigationProp<any>; | ||
} | ||
|
||
function FiltersScreen({ navigation }: IProps) { | ||
const { t } = useTranslation(); | ||
const theme = useTheme(); | ||
|
||
return ( | ||
<ScrollView backgroundColor={theme.colors.app.bg} flex={1}> | ||
<TableView style={styles.table}> | ||
<CSection header={t("Haptics")}> | ||
<CCell | ||
cellStyle="RightDetail" | ||
title={t("Keywords")} | ||
backgroundColor={theme.colors.app.fg} | ||
titleTextColor={theme.colors.app.textPrimary} | ||
rightDetailColor={theme.colors.app.textSecondary} | ||
accessory="DisclosureIndicator" | ||
onPress={() => navigation.push("Keywords")} | ||
/> | ||
<CCell | ||
cellStyle="RightDetail" | ||
title={t("Instances")} | ||
backgroundColor={theme.colors.app.fg} | ||
titleTextColor={theme.colors.app.textPrimary} | ||
rightDetailColor={theme.colors.app.textSecondary} | ||
accessory="DisclosureIndicator" | ||
onPress={() => navigation.push("Instances")} | ||
/> | ||
</CSection> | ||
</TableView> | ||
</ScrollView> | ||
); | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
table: { | ||
marginHorizontal: 15, | ||
}, | ||
}); | ||
|
||
export default FiltersScreen; |
131 changes: 131 additions & 0 deletions
131
src/components/screens/Settings/Filters/InstancesScreen.tsx
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 |
---|---|---|
@@ -0,0 +1,131 @@ | ||
import React, { useEffect, useMemo } from "react"; | ||
import { useTranslation } from "react-i18next"; | ||
import { ScrollView, useTheme } from "native-base"; | ||
import { Alert, Button, StyleSheet } from "react-native"; | ||
import { TableView } from "@gkasdorf/react-native-tableview-simple"; | ||
import { NativeStackNavigationProp } from "@react-navigation/native-stack"; | ||
import CSection from "../../../common/Table/CSection"; | ||
import CCell from "../../../common/Table/CCell"; | ||
import { | ||
useFiltersStore, | ||
useInstancesFilter, | ||
} from "../../../../stores/filters/filtersStore"; | ||
import { getBaseUrl } from "../../../../helpers/LinkHelper"; | ||
|
||
interface IProps { | ||
navigation: NativeStackNavigationProp<any>; | ||
} | ||
|
||
function InstanceOption({ instance }: { instance: string }) { | ||
const filtersStore = useFiltersStore(); | ||
const theme = useTheme(); | ||
const { t } = useTranslation(); | ||
|
||
const onInstancePress = () => { | ||
Alert.alert( | ||
t("settings.filters.removeInstance"), | ||
t("settings.filters.areYouSureInstance"), | ||
[ | ||
{ | ||
text: t("Cancel"), | ||
style: "cancel", | ||
}, | ||
{ | ||
text: t("Remove"), | ||
style: "destructive", | ||
onPress: () => { | ||
filtersStore.removeInstance(instance); | ||
}, | ||
}, | ||
] | ||
); | ||
}; | ||
|
||
return ( | ||
<CCell | ||
cellStyle="RightDetail" | ||
title={instance} | ||
backgroundColor={theme.colors.app.fg} | ||
titleTextColor={theme.colors.app.textPrimary} | ||
rightDetailColor={theme.colors.app.textSecondary} | ||
accessory="DisclosureIndicator" | ||
onPress={onInstancePress} | ||
/> | ||
); | ||
} | ||
|
||
function InstancesScreen({ navigation }: IProps) { | ||
const { t } = useTranslation(); | ||
const theme = useTheme(); | ||
|
||
const filtersStore = useFiltersStore(); | ||
const instances = useInstancesFilter(); | ||
|
||
useEffect(() => { | ||
navigation.setOptions({ | ||
// eslint-disable-next-line react/no-unstable-nested-components | ||
headerRight: () => ( | ||
<Button | ||
title={t("Add")} | ||
onPress={onAddPress} | ||
color={theme.colors.app.accent} | ||
/> | ||
), | ||
}); | ||
}, []); | ||
|
||
const onAddPress = () => { | ||
Alert.prompt( | ||
t("settings.filters.addInstance"), | ||
t("settings.filters.enterAnInstance"), | ||
[ | ||
{ | ||
text: t("Cancel"), | ||
style: "cancel", | ||
}, | ||
{ | ||
text: t("Save"), | ||
style: "default", | ||
onPress: (value?: string) => { | ||
if (!value) return; | ||
|
||
filtersStore.addInstance(getBaseUrl(value)).then(); | ||
}, | ||
}, | ||
] | ||
); | ||
}; | ||
|
||
const instanceOptions = useMemo( | ||
() => instances.map((k) => <InstanceOption key={k} instance={k} />), | ||
[instances] | ||
); | ||
|
||
return ( | ||
<ScrollView backgroundColor={theme.colors.app.bg} flex={1}> | ||
<TableView style={styles.table}> | ||
<CSection header={t("Instances").toUpperCase()}> | ||
{instances.length < 1 ? ( | ||
<CCell | ||
cellStyle="RightDetail" | ||
title={t("settings.filters.noInstances")} | ||
backgroundColor={theme.colors.app.fg} | ||
titleTextColor={theme.colors.app.textPrimary} | ||
rightDetailColor={theme.colors.app.textSecondary} | ||
/> | ||
) : ( | ||
instanceOptions | ||
)} | ||
</CSection> | ||
</TableView> | ||
</ScrollView> | ||
); | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
table: { | ||
marginHorizontal: 15, | ||
}, | ||
}); | ||
|
||
export default InstancesScreen; |
130 changes: 130 additions & 0 deletions
130
src/components/screens/Settings/Filters/KeywordsScreen.tsx
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 |
---|---|---|
@@ -0,0 +1,130 @@ | ||
import React, { useEffect, useMemo } from "react"; | ||
import { useTranslation } from "react-i18next"; | ||
import { ScrollView, useTheme } from "native-base"; | ||
import { Alert, Button, StyleSheet } from "react-native"; | ||
import { TableView } from "@gkasdorf/react-native-tableview-simple"; | ||
import { NativeStackNavigationProp } from "@react-navigation/native-stack"; | ||
import CSection from "../../../common/Table/CSection"; | ||
import CCell from "../../../common/Table/CCell"; | ||
import { | ||
useFiltersStore, | ||
useKeywordFilter, | ||
} from "../../../../stores/filters/filtersStore"; | ||
|
||
interface IProps { | ||
navigation: NativeStackNavigationProp<any>; | ||
} | ||
|
||
function KeywordOption({ keyword }: { keyword: string }) { | ||
const filtersStore = useFiltersStore(); | ||
const theme = useTheme(); | ||
const { t } = useTranslation(); | ||
|
||
const onKeywordPress = () => { | ||
Alert.alert( | ||
t("settings.filters.removeKeyword"), | ||
t("settings.filters.areYouSureKeyword"), | ||
[ | ||
{ | ||
text: t("Cancel"), | ||
style: "cancel", | ||
}, | ||
{ | ||
text: t("Remove"), | ||
style: "destructive", | ||
onPress: () => { | ||
filtersStore.removeKeyword(keyword); | ||
}, | ||
}, | ||
] | ||
); | ||
}; | ||
|
||
return ( | ||
<CCell | ||
cellStyle="RightDetail" | ||
title={keyword} | ||
backgroundColor={theme.colors.app.fg} | ||
titleTextColor={theme.colors.app.textPrimary} | ||
rightDetailColor={theme.colors.app.textSecondary} | ||
accessory="DisclosureIndicator" | ||
onPress={onKeywordPress} | ||
/> | ||
); | ||
} | ||
|
||
function KeywordsScreen({ navigation }: IProps) { | ||
const { t } = useTranslation(); | ||
const theme = useTheme(); | ||
|
||
const filtersStore = useFiltersStore(); | ||
const keywords = useKeywordFilter(); | ||
|
||
useEffect(() => { | ||
navigation.setOptions({ | ||
// eslint-disable-next-line react/no-unstable-nested-components | ||
headerRight: () => ( | ||
<Button | ||
title={t("Add")} | ||
onPress={onAddPress} | ||
color={theme.colors.app.accent} | ||
/> | ||
), | ||
}); | ||
}, []); | ||
|
||
const onAddPress = () => { | ||
Alert.prompt( | ||
t("settings.filters.addKeyword"), | ||
t("settings.filters.enterAKeyword"), | ||
[ | ||
{ | ||
text: t("Cancel"), | ||
style: "cancel", | ||
}, | ||
{ | ||
text: t("Save"), | ||
style: "default", | ||
onPress: (value?: string) => { | ||
if (!value) return; | ||
|
||
filtersStore.addKeyword(value.toLowerCase()).then(); | ||
}, | ||
}, | ||
] | ||
); | ||
}; | ||
|
||
const keywordOptions = useMemo( | ||
() => keywords.map((k) => <KeywordOption key={k} keyword={k} />), | ||
[keywords] | ||
); | ||
|
||
return ( | ||
<ScrollView backgroundColor={theme.colors.app.bg} flex={1}> | ||
<TableView style={styles.table}> | ||
<CSection header={t("Keywords").toUpperCase()}> | ||
{keywords.length < 1 ? ( | ||
<CCell | ||
cellStyle="RightDetail" | ||
title={t("settings.filters.noKeywords")} | ||
backgroundColor={theme.colors.app.fg} | ||
titleTextColor={theme.colors.app.textPrimary} | ||
rightDetailColor={theme.colors.app.textSecondary} | ||
/> | ||
) : ( | ||
keywordOptions | ||
)} | ||
</CSection> | ||
</TableView> | ||
</ScrollView> | ||
); | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
table: { | ||
marginHorizontal: 15, | ||
}, | ||
}); | ||
|
||
export default KeywordsScreen; |
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
Oops, something went wrong.