mirror of
https://github.com/aykhans/slash-e.git
synced 2025-04-16 12:23:12 +00:00
feat: add search input
This commit is contained in:
parent
709118464b
commit
11205566ac
@ -1,4 +1,4 @@
|
||||
import { Button, Tab, TabList, Tabs } from "@mui/joy";
|
||||
import { Button, Input, Tab, TabList, Tabs } from "@mui/joy";
|
||||
import { useEffect, useState } from "react";
|
||||
import { shortcutService } from "../services";
|
||||
import { useAppSelector } from "../stores";
|
||||
@ -43,8 +43,20 @@ const Home: React.FC = () => {
|
||||
return (
|
||||
<>
|
||||
<div className="mx-auto max-w-4xl w-full px-3 py-6 flex flex-col justify-start items-start">
|
||||
<div className="w-full flex flex-row justify-start items-center mb-4">
|
||||
<div className="w-full flex flex-row justify-between items-center mb-4">
|
||||
<span className="font-mono text-gray-400 mr-2">Shortcuts</span>
|
||||
<Input
|
||||
className="w-32"
|
||||
type="text"
|
||||
size="sm"
|
||||
placeholder="Search"
|
||||
startDecorator={<Icon.Search className="w-4 h-auto" />}
|
||||
endDecorator={
|
||||
filter.search !== "" && <Icon.X className="w-4 h-auto cursor-pointer" onClick={() => viewStore.setFilter({ search: "" })} />
|
||||
}
|
||||
value={filter.search}
|
||||
onChange={(e) => viewStore.setFilter({ search: e.target.value })}
|
||||
/>
|
||||
</div>
|
||||
<div className="w-full flex flex-row justify-between items-center mb-4">
|
||||
<div className="flex flex-row justify-start items-center">
|
||||
|
@ -5,6 +5,7 @@ export interface Filter {
|
||||
tag?: string;
|
||||
mineOnly?: boolean;
|
||||
visibility?: Visibility;
|
||||
search?: string;
|
||||
}
|
||||
|
||||
export interface Order {
|
||||
@ -48,7 +49,7 @@ const useViewStore = create<ViewState>()(
|
||||
);
|
||||
|
||||
export const getFilteredShortcutList = (shortcutList: Shortcut[], filter: Filter, currentUser: User) => {
|
||||
const { tag, mineOnly, visibility } = filter;
|
||||
const { tag, mineOnly, visibility, search } = filter;
|
||||
const filteredShortcutList = shortcutList.filter((shortcut) => {
|
||||
if (tag) {
|
||||
if (!shortcut.tags.includes(tag)) {
|
||||
@ -65,6 +66,16 @@ export const getFilteredShortcutList = (shortcutList: Shortcut[], filter: Filter
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (search) {
|
||||
if (
|
||||
!shortcut.name.toLowerCase().includes(search.toLowerCase()) &&
|
||||
!shortcut.description.toLowerCase().includes(search.toLowerCase()) &&
|
||||
!shortcut.tags.some((tag) => tag.toLowerCase().includes(search.toLowerCase())) &&
|
||||
!shortcut.link.toLowerCase().includes(search.toLowerCase())
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
});
|
||||
return filteredShortcutList;
|
||||
|
Loading…
x
Reference in New Issue
Block a user