mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-02-03 00:33:49 +03:00
feat: adding button to clear selected filters
This commit is contained in:
parent
b28d34cf66
commit
f37b92261f
@ -5,9 +5,13 @@ const putDownloadSource = async (
|
|||||||
_event: Electron.IpcMainInvokeEvent,
|
_event: Electron.IpcMainInvokeEvent,
|
||||||
objectIds: string[]
|
objectIds: string[]
|
||||||
) => {
|
) => {
|
||||||
return HydraApi.put<{ fingerprint: string }>("/download-sources", {
|
return HydraApi.put<{ fingerprint: string }>(
|
||||||
|
"/download-sources",
|
||||||
|
{
|
||||||
objectIds,
|
objectIds,
|
||||||
});
|
},
|
||||||
|
{ needsAuth: false }
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
registerEvent("putDownloadSource", putDownloadSource);
|
registerEvent("putDownloadSource", putDownloadSource);
|
||||||
|
@ -305,6 +305,7 @@ export default function Catalogue() {
|
|||||||
<div style={{ display: "flex", flexDirection: "column", gap: 16 }}>
|
<div style={{ display: "flex", flexDirection: "column", gap: 16 }}>
|
||||||
<FilterSection
|
<FilterSection
|
||||||
title="Genres"
|
title="Genres"
|
||||||
|
onClear={() => dispatch(setSearch({ genres: [] }))}
|
||||||
color={filterCategoryColors.genres}
|
color={filterCategoryColors.genres}
|
||||||
onSelect={(value) => {
|
onSelect={(value) => {
|
||||||
if (filters.genres.includes(value)) {
|
if (filters.genres.includes(value)) {
|
||||||
@ -359,6 +360,7 @@ export default function Catalogue() {
|
|||||||
<FilterSection
|
<FilterSection
|
||||||
title="User tags"
|
title="User tags"
|
||||||
color={filterCategoryColors.tags}
|
color={filterCategoryColors.tags}
|
||||||
|
onClear={() => dispatch(setSearch({ tags: [] }))}
|
||||||
onSelect={(value) => {
|
onSelect={(value) => {
|
||||||
if (filters.tags.includes(value)) {
|
if (filters.tags.includes(value)) {
|
||||||
dispatch(
|
dispatch(
|
||||||
@ -382,6 +384,9 @@ export default function Catalogue() {
|
|||||||
<FilterSection
|
<FilterSection
|
||||||
title="Download sources"
|
title="Download sources"
|
||||||
color={filterCategoryColors.downloadSourceFingerprints}
|
color={filterCategoryColors.downloadSourceFingerprints}
|
||||||
|
onClear={() =>
|
||||||
|
dispatch(setSearch({ downloadSourceFingerprints: [] }))
|
||||||
|
}
|
||||||
onSelect={(value) => {
|
onSelect={(value) => {
|
||||||
if (filters.downloadSourceFingerprints.includes(value)) {
|
if (filters.downloadSourceFingerprints.includes(value)) {
|
||||||
dispatch(
|
dispatch(
|
||||||
@ -415,6 +420,7 @@ export default function Catalogue() {
|
|||||||
<FilterSection
|
<FilterSection
|
||||||
title="Developers"
|
title="Developers"
|
||||||
color={filterCategoryColors.developers}
|
color={filterCategoryColors.developers}
|
||||||
|
onClear={() => dispatch(setSearch({ developers: [] }))}
|
||||||
onSelect={(value) => {
|
onSelect={(value) => {
|
||||||
if (filters.developers.includes(value)) {
|
if (filters.developers.includes(value)) {
|
||||||
dispatch(
|
dispatch(
|
||||||
@ -440,6 +446,7 @@ export default function Catalogue() {
|
|||||||
<FilterSection
|
<FilterSection
|
||||||
title="Publishers"
|
title="Publishers"
|
||||||
color={filterCategoryColors.publishers}
|
color={filterCategoryColors.publishers}
|
||||||
|
onClear={() => dispatch(setSearch({ publishers: [] }))}
|
||||||
onSelect={(value) => {
|
onSelect={(value) => {
|
||||||
if (filters.publishers.includes(value)) {
|
if (filters.publishers.includes(value)) {
|
||||||
dispatch(
|
dispatch(
|
||||||
|
@ -13,6 +13,7 @@ export interface FilterSectionProps<T extends string | number> {
|
|||||||
}[];
|
}[];
|
||||||
onSelect: (value: T) => void;
|
onSelect: (value: T) => void;
|
||||||
color: string;
|
color: string;
|
||||||
|
onClear: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function FilterSection<T extends string | number>({
|
export function FilterSection<T extends string | number>({
|
||||||
@ -20,6 +21,7 @@ export function FilterSection<T extends string | number>({
|
|||||||
items,
|
items,
|
||||||
color,
|
color,
|
||||||
onSelect,
|
onSelect,
|
||||||
|
onClear,
|
||||||
}: FilterSectionProps<T>) {
|
}: FilterSectionProps<T>) {
|
||||||
const [search, setSearch] = useState("");
|
const [search, setSearch] = useState("");
|
||||||
|
|
||||||
@ -33,6 +35,10 @@ export function FilterSection<T extends string | number>({
|
|||||||
return items;
|
return items;
|
||||||
}, [items, search]);
|
}, [items, search]);
|
||||||
|
|
||||||
|
const selectedItemsCount = useMemo(() => {
|
||||||
|
return items.filter((item) => item.checked).length;
|
||||||
|
}, [items]);
|
||||||
|
|
||||||
const onSearch = useCallback((value: string) => {
|
const onSearch = useCallback((value: string) => {
|
||||||
setSearch(value);
|
setSearch(value);
|
||||||
}, []);
|
}, []);
|
||||||
@ -61,9 +67,26 @@ export function FilterSection<T extends string | number>({
|
|||||||
</h3>
|
</h3>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{selectedItemsCount > 0 ? (
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
style={{
|
||||||
|
fontSize: 12,
|
||||||
|
marginBottom: 12,
|
||||||
|
display: "block",
|
||||||
|
color: "#fff",
|
||||||
|
cursor: "pointer",
|
||||||
|
textDecoration: "underline",
|
||||||
|
}}
|
||||||
|
onClick={onClear}
|
||||||
|
>
|
||||||
|
Limpar {formatNumber(selectedItemsCount)} selecionados
|
||||||
|
</button>
|
||||||
|
) : (
|
||||||
<span style={{ fontSize: 12, marginBottom: 12, display: "block" }}>
|
<span style={{ fontSize: 12, marginBottom: 12, display: "block" }}>
|
||||||
{formatNumber(items.length)} disponíveis
|
{formatNumber(items.length)} disponíveis
|
||||||
</span>
|
</span>
|
||||||
|
)}
|
||||||
|
|
||||||
<TextField
|
<TextField
|
||||||
placeholder="Search..."
|
placeholder="Search..."
|
||||||
|
Loading…
Reference in New Issue
Block a user