Skip to content

Commit

Permalink
Move search bar inside the list page
Browse files Browse the repository at this point in the history
  • Loading branch information
belinde committed Apr 22, 2024
1 parent 19c1616 commit 050c709
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 84 deletions.
59 changes: 40 additions & 19 deletions src/components/ConcertList.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { FC, useCallback, useEffect, useState } from "react";
import { FlatList } from "react-native";
import { List } from "react-native-paper";
import { List, Searchbar } from "react-native-paper";
import { useDataContext } from "../hooks/useDataContext";
import { useEffectOnFocus } from "../hooks/useEffectOnFocus";
import { Concert } from "../types";
Expand All @@ -12,6 +12,7 @@ export const ConcertList: FC<{ onPress: (concert: Concert) => void }> = (
const data = useDataContext();
const [concerts, setConcerts] = useState<Concert[]>();
const [refreshing, setRefreshing] = useState(false);
const [text, setText] = useState(() => data.search);

const applyFilter = useCallback(
(s: Concert[]) => {
Expand Down Expand Up @@ -41,24 +42,44 @@ export const ConcertList: FC<{ onPress: (concert: Concert) => void }> = (
applyFilter(data.concerts.list());
}, [applyFilter, data.concerts]);

const search = useCallback(
(s: string) => {
setText(s);
data.setSearch(s);
},
[data]
);
const reset = useCallback(() => search(""), [search]);

return (
<FlatList
data={concerts}
refreshing={refreshing}
onRefresh={refresh}
renderItem={(row) => (
<List.Item
title={row.item.title}
description={row.item.description}
left={() => <List.Icon icon="account-music" />}
right={() => <List.Icon icon="chevron-right" />}
onPress={() => props.onPress(row.item)}
titleNumberOfLines={2}
descriptionNumberOfLines={1}
/>
)}
keyExtractor={(song) => song.id}
ListEmptyComponent={EmptySearchableListElement}
/>
<>
<Searchbar
value={text}
onChangeText={search}
onIconPress={reset}
onClearIconPress={reset}
placeholder="Cerca..."
searchAccessibilityLabel="Cerca..."
aria-label="Cerca..."
/>
<FlatList
data={concerts}
refreshing={refreshing}
onRefresh={refresh}
renderItem={(row) => (
<List.Item
title={row.item.title}
description={row.item.description}
left={() => <List.Icon icon="account-music" />}
right={() => <List.Icon icon="chevron-right" />}
onPress={() => props.onPress(row.item)}
titleNumberOfLines={2}
descriptionNumberOfLines={1}
/>
)}
keyExtractor={(song) => song.id}
ListEmptyComponent={EmptySearchableListElement}
/>
</>
);
};
60 changes: 0 additions & 60 deletions src/components/SearchMenu.tsx

This file was deleted.

3 changes: 1 addition & 2 deletions src/pages/Concert/ConcertStack.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { createNativeStackNavigator } from "@react-navigation/native-stack";
import { FC } from "react";
import { SearchMenu } from "../../components/SearchMenu";
import { useNativeStackNavigatorOptions } from "../../hooks/useNativeStackNavigatorOptions";
import { CreateConcert } from "./CreateConcert";
import { EditConcert } from "./EditConcert";
Expand Down Expand Up @@ -29,7 +28,7 @@ export const ConcertStack: FC = () => {
<Stack.Screen
name="List"
component={ListConcerts}
options={{ title: "Concerti", headerRight: SearchMenu }}
options={{ title: "Concerti" }}
/>
<Stack.Screen
name="Create"
Expand Down
3 changes: 1 addition & 2 deletions src/pages/Library/LibraryStack.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { createNativeStackNavigator } from "@react-navigation/native-stack";
import { FC } from "react";
import { SearchMenu } from "../../components/SearchMenu";
import { useNativeStackNavigatorOptions } from "../../hooks/useNativeStackNavigatorOptions";
import { CreateSong } from "./CreateSong";
import { EditSong } from "./EditSong";
Expand Down Expand Up @@ -32,7 +31,7 @@ export const LibraryStack: FC = () => {
<Stack.Screen
name="List"
component={ListSongs}
options={{ title: "Repertorio", headerRight: SearchMenu }}
options={{ title: "Repertorio" }}
/>
<Stack.Screen
name="Create"
Expand Down
22 changes: 21 additions & 1 deletion src/pages/Library/ListSongs.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FC, useCallback, useEffect, useState } from "react";
import { Button } from "react-native-paper";
import { Button, Searchbar } from "react-native-paper";
import { Page } from "../../components/Page";
import { SongList } from "../../components/SongList";
import { useDataContext } from "../../hooks/useDataContext";
Expand All @@ -9,6 +9,8 @@ import { LibraryTabScreenProps } from "../types";

export const ListSongs: FC<LibraryTabScreenProps<"List">> = (props) => {
const data = useDataContext();
const [text, setText] = useState(() => data.search);

const [songs, setSongs] = useState(() => data.songs.list());

const applyFilter = useCallback(
Expand All @@ -34,8 +36,26 @@ export const ListSongs: FC<LibraryTabScreenProps<"List">> = (props) => {
applyFilter(data.songs.list());
}, [applyFilter, data.songs]);

const search = useCallback(
(s: string) => {
setText(s);
data.setSearch(s);
},
[data]
);
const reset = useCallback(() => search(""), [search]);

return (
<Page accessibilityLabel="Repertorio">
<Searchbar
value={text}
onChangeText={search}
onIconPress={reset}
onClearIconPress={reset}
placeholder="Cerca..."
searchAccessibilityLabel="Cerca..."
aria-label="Cerca..."
/>
<SongList
songs={songs}
onRefresh={refresh}
Expand Down
12 changes: 12 additions & 0 deletions src/pages/Library/QRSong.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { FC, useCallback, useState } from "react";
import { View, useWindowDimensions } from "react-native";
import { Text } from "react-native-paper";
import QRCode from "react-qr-code";
import { Page } from "../../components/Page";
import { useDataContext } from "../../hooks/useDataContext";
Expand Down Expand Up @@ -36,6 +37,17 @@ export const QRSong: FC<LibraryTabScreenProps<"QRView">> = (props) => {
>
<QRCode size={width - 40} value={serializeSong(currentSong)} />
</View>
<Text>
Usa questo QR Code per copiare rapidamente "{currentSong.title}" su un
altro dispositivo.
</Text>
{currentSong.image ? (
<Text>
Attenzione: la fotografia dello spartito non è inclusa. Per trasferire
tutte le informazioni devi utilizzare la funzione di esportazione
della libreria.
</Text>
) : null}
</Page>
);
};

0 comments on commit 050c709

Please sign in to comment.