You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
memos/web/src/components/SearchBar.tsx

61 lines
2.1 KiB
TypeScript

import { useTranslation } from "react-i18next";
4 years ago
import { locationService } from "../services";
import { useAppSelector } from "../store";
4 years ago
import { memoSpecialTypes } from "../helpers/filter";
import Icon from "./Icon";
import "../less/search-bar.less";
4 years ago
const SearchBar = () => {
const { t } = useTranslation();
const memoType = useAppSelector((state) => state.location.query?.type);
4 years ago
const handleMemoTypeItemClick = (type: MemoSpecType | undefined) => {
const { type: prevType } = locationService.getState().query ?? {};
4 years ago
if (type === prevType) {
type = undefined;
4 years ago
}
locationService.setMemoTypeQuery(type);
};
const handleTextQueryInput = (event: React.FormEvent<HTMLInputElement>) => {
const text = event.currentTarget.value;
locationService.setTextQuery(text);
};
return (
<div className="search-bar-container">
<div className="search-bar-inputer">
<Icon.Search className="icon-img" />
4 years ago
<input className="text-input" type="text" placeholder="" onChange={handleTextQueryInput} />
</div>
<div className="quickly-action-wrapper">
<div className="quickly-action-container">
<p className="title-text">{t("search.quickly-filter").toUpperCase()}</p>
4 years ago
<div className="section-container types-container">
<span className="section-text">{t("common.type").toUpperCase()}:</span>
4 years ago
<div className="values-container">
{memoSpecialTypes.map((type, idx) => {
4 years ago
return (
<div key={type.value}>
4 years ago
<span
className={`type-item ${memoType === type.value ? "selected" : ""}`}
4 years ago
onClick={() => {
handleMemoTypeItemClick(type.value as MemoSpecType);
4 years ago
}}
>
{t(type.text)}
4 years ago
</span>
{idx + 1 < memoSpecialTypes.length ? <span className="split-text">/</span> : null}
</div>
);
})}
</div>
</div>
</div>
</div>
</div>
);
};
export default SearchBar;