Refactor validation
Signed-off-by: Nikolaos Karaolidis <nick@karaolidis.com>
This commit is contained in:
@@ -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
|
||||
|
Reference in New Issue
Block a user