feat: add visibility filter

This commit is contained in:
Steven
2023-07-10 23:19:03 +08:00
parent 0cceed51f8
commit 00c7abc38d
5 changed files with 32 additions and 9 deletions

View File

@ -2,7 +2,7 @@ import { Button, Tab, TabList, Tabs } from "@mui/joy";
import { useEffect, useState } from "react";
import { shortcutService } from "../services";
import { useAppSelector } from "../stores";
import useViewStore, { Filter } from "../stores/v1/filter";
import useViewStore, { Filter } from "../stores/v1/view";
import useUserStore from "../stores/v1/user";
import useLoading from "../hooks/useLoading";
import Icon from "../components/Icon";
@ -15,7 +15,7 @@ interface State {
}
const getFilteredShortcutList = (shortcutList: Shortcut[], filter: Filter, currentUser: User) => {
const { tag, mineOnly } = filter;
const { tag, mineOnly, visibility } = filter;
const filteredShortcutList = shortcutList.filter((shortcut) => {
if (tag) {
if (!shortcut.tags.includes(tag)) {
@ -27,6 +27,11 @@ const getFilteredShortcutList = (shortcutList: Shortcut[], filter: Filter, curre
return false;
}
}
if (visibility) {
if (shortcut.visibility !== visibility) {
return false;
}
}
return true;
});
return filteredShortcutList;