Refactor validation

Signed-off-by: Nikolaos Karaolidis <nick@karaolidis.com>
This commit is contained in:
2023-07-21 16:34:44 +03:00
parent b7dd1c77af
commit 3c303e0304
17 changed files with 256 additions and 151 deletions

View File

@@ -12,7 +12,7 @@ import {
} from 'react-native-paper';
import { useDispatch, useSelector } from 'react-redux';
import styles from '../styles';
import { MEME_SORT, SORT_DIRECTION } from '../types';
import { MEME_SORT, SORT_DIRECTION, memesSortQuery } from '../types';
import { getSortIcon, getViewIcon } from '../utilities';
import {
RootState,
@@ -72,7 +72,27 @@ const Memes = () => {
};
const [search, setSearch] = useState('');
const memes = useQuery<Meme>(Meme.schema.name);
const memes = useQuery<Meme>(
Meme.schema.name,
collectionIn => {
let collection = collectionIn;
if (favoritesOnly) collection = collection.filtered('isFavorite == true');
if (filter) collection = collection.filtered('type == $0', filter);
if (search) {
collection = collection.filtered('title CONTAINS[c] $0', search);
}
collection = collection.sorted(
memesSortQuery(sort),
sortDirection === SORT_DIRECTION.DESCENDING,
);
return collection;
},
[sort, sortDirection, favoritesOnly, filter, search],
);
return (
<View