Skip to content

Commit

Permalink
Merge branch 'main' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Palm authored Mar 4, 2024
2 parents ef15a06 + 746751c commit 1c24e85
Showing 1 changed file with 45 additions and 30 deletions.
75 changes: 45 additions & 30 deletions src/ui/settings/components/AddonPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,52 @@ import { CardWrapper } from "@ui/settings/components/Card";
import settings from "@lib/settings";

interface AddonPageProps<T> {
items: Record<string, T & { id: string }>;
safeModeMessage: string;
safeModeExtras?: JSX.Element | JSX.Element[];
card: React.ComponentType<CardWrapper<T>>;
keyGetter: (item: T) => (string | undefined)[]
items: Record<string, T & { id: string }>;
safeModeMessage: string;
safeModeExtras?: JSX.Element | JSX.Element[];
card: React.ComponentType<CardWrapper<T>>;
keyGetter: (item: T) => (string | undefined)[];
}

export default function AddonPage<T>({ items, safeModeMessage, safeModeExtras, card: CardComponent, keyGetter }: AddonPageProps<T>) {
useProxy(settings)
useProxy(items);
const [search, setSearch] = React.useState("");
export default function AddonPage<T>({
items,
safeModeMessage,
safeModeExtras,
card: CardComponent,
keyGetter,
}: AddonPageProps<T>) {
useProxy(settings);
useProxy(items);
const [search, setSearch] = React.useState("");

return (
<ErrorBoundary>
<RN.FlatList
ListHeaderComponent={<>
{settings.safeMode?.enabled && <RN.View style={{ marginBottom: 10 }}>
<HelpMessage messageType={0}>{safeModeMessage}</HelpMessage>
{safeModeExtras}
</RN.View>}
<Search
style={{ marginBottom: 10 }}
onChangeText={(v: string) => setSearch(v.toLowerCase())}
placeholder="Search"
/>
</>}
style={{ paddingHorizontal: 10, paddingTop: 10 }}
contentContainerStyle={{ paddingBottom: 20 }}
data={Object.values(items).filter(i => keyGetter(i).some(x => x?.toLowerCase().includes(search)))}
renderItem={({ item, index }) => <CardComponent item={item} index={index} highlight={search} />}
return (
<ErrorBoundary>
<RN.FlatList
ListHeaderComponent={
<>
{settings.safeMode?.enabled && (
<RN.View style={{ marginBottom: 10 }}>
<HelpMessage messageType={0}>{safeModeMessage}</HelpMessage>
{safeModeExtras}
</RN.View>
)}
<Search
style={{ marginBottom: 10 }}
onChangeText={(v: string) => setSearch(v.toLowerCase())}
placeholder="Search"
/>
</ErrorBoundary>
)
}
</>
}
ListFooterComponent={<RN.View style={{ height: 48 }} />}
style={{ paddingHorizontal: 10, paddingTop: 10 }}
contentContainerStyle={{ paddingBottom: 20 }}
data={Object.values(items).filter((i) =>
keyGetter(i).some((x) => x?.toLowerCase().includes(search))
)}
renderItem={({ item, index }) => (
<CardComponent item={item} index={index} highlight={search} />
)}
/>
</ErrorBoundary>
);
}

0 comments on commit 1c24e85

Please sign in to comment.