Skip to content

Commit

Permalink
Merge pull request #19 from Gabi1M/maint/add-search-in-top-bar
Browse files Browse the repository at this point in the history
Move name filter into header
  • Loading branch information
Gabi1M authored May 20, 2023
2 parents 3471378 + 2c064e9 commit 51eb27d
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 22 deletions.
4 changes: 3 additions & 1 deletion src/meridian/generic/drawerPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ import { ColorSchemeToggle } from './colorSchemeToggle';
interface Props {
children: React.ReactNode;
drawerContent?: React.ReactNode;
headerLeftContent?: React.ReactNode;
headerRightContent?: React.ReactNode;
}

const DrawerPage = ({ children, drawerContent, headerRightContent }: Props) => {
const DrawerPage = ({ children, drawerContent, headerLeftContent, headerRightContent }: Props) => {
const styles = useStyles();
const [opened, setOpened] = useState(false);

Expand All @@ -35,6 +36,7 @@ const DrawerPage = ({ children, drawerContent, headerRightContent }: Props) => {
<ActionIcon onClick={() => setOpened(true)}>
<Menu2 />
</ActionIcon>
{headerLeftContent}
<Box className={styles.classes.space} />
<ColorSchemeToggle />
{headerRightContent}
Expand Down
18 changes: 1 addition & 17 deletions src/meridian/home/drawerContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,7 @@ import { useDispatch, useSelector } from 'react-redux';

import { t } from '@lingui/macro';

import {
Box,
LoadingOverlay,
MultiSelect,
Text,
TextInput,
Title,
createStyles,
} from '@mantine/core';
import { Box, LoadingOverlay, MultiSelect, Text, Title, createStyles } from '@mantine/core';

import { selectMainData } from 'meridian/mainData';
import { TorrentFilters, TorrentStateDescription } from 'meridian/models';
Expand Down Expand Up @@ -40,8 +32,6 @@ const DrawerContent = () => {
);

const handlers = {
name: (value: React.ChangeEvent<HTMLInputElement>) =>
onTorrentFilterChanged('name', value.target.value),
states: (value: string[]) => onTorrentFilterChanged('states', value),
categories: (value: string[]) => onTorrentFilterChanged('categories', value),
tags: (value: string[]) => onTorrentFilterChanged('tags', value),
Expand All @@ -62,12 +52,6 @@ const DrawerContent = () => {
<Text size='xl'>{text}</Text>
</Box>
<Title order={4} align='center'>{t`Filters`}</Title>
<TextInput
label={t`Name`}
placeholder={t`Enter a name`}
value={torrentFilters.name}
onChange={handlers['name']}
/>
<MultiSelect
label={t`States`}
placeholder={t`All`}
Expand Down
43 changes: 39 additions & 4 deletions src/meridian/home/homePage.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import React from 'react';
import { useSelector } from 'react-redux';
import React, { useCallback } from 'react';
import { useDispatch, useSelector } from 'react-redux';

import { Box, Pagination, createStyles } from '@mantine/core';
import { t } from '@lingui/macro';

import { Box, Pagination, TextInput, createStyles } from '@mantine/core';

import { DrawerPage, ScrollToTopAffix } from 'meridian/generic';
import { selectSettings } from 'meridian/settings';
import { TorrentCard } from 'meridian/torrent';
import { createSetTorrentFiltersAction, selectTorrentFilters } from 'meridian/torrentFilters';

import DrawerContent from './drawerContent';
import HeaderContent from './headerContent';
Expand Down Expand Up @@ -38,6 +41,34 @@ const PaginationContainer = ({
);
};

const HeaderLeftContent = () => {
const dispatch = useDispatch();
const torrentFilters = useSelector(selectTorrentFilters);

const onNameChanged = useCallback(
(value: React.ChangeEvent<HTMLInputElement>) => {
dispatch(
createSetTorrentFiltersAction({
...torrentFilters,
name: value.target.value,
}),
);
},
[dispatch, torrentFilters],
);

return (
<Box>
<TextInput
ml='xl'
placeholder={t`Enter a name`}
value={torrentFilters.name}
onChange={onNameChanged}
/>
</Box>
);
};

const HomePage = () => {
const styles = useStyles();
const torrents = useFilteredTorrents();
Expand All @@ -52,7 +83,11 @@ const HomePage = () => {
useManageSelection();

return (
<DrawerPage headerRightContent={<HeaderContent />} drawerContent={<DrawerContent />}>
<DrawerPage
headerLeftContent={<HeaderLeftContent />}
headerRightContent={<HeaderContent />}
drawerContent={<DrawerContent />}
>
<Box className={styles.classes.root}>
{currentItems.map((torrent) => (
<TorrentCard
Expand Down

0 comments on commit 51eb27d

Please sign in to comment.