Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allowing whitespace in create memo relation dialog #2950

Closed
wants to merge 5 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 22 additions & 12 deletions web/src/components/CreateMemoRelationDialog.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Autocomplete, AutocompleteOption, Button, Checkbox, Chip, IconButton } from "@mui/joy";
import React, { useState } from "react";
import React, { useState, useEffect } from "react";
import { toast } from "react-hot-toast";
import useDebounce from "react-use/lib/useDebounce";
import { memoServiceClient } from "@/grpcweb";
import { DEFAULT_MEMO_LIMIT } from "@/helpers/consts";
import { getDateTimeString } from "@/helpers/datetime";
Expand All @@ -20,19 +19,30 @@
const t = useTranslate();
const user = useCurrentUser();
const [searchText, setSearchText] = useState<string>("");
const [debouncedSearchText, setDebouncedSearchText] = useState<string>("");
const [isFetching, setIsFetching] = useState<boolean>(true);
const [fetchedMemos, setFetchedMemos] = useState<Memo[]>([]);
const [selectedMemos, setSelectedMemos] = useState<Memo[]>([]);
const [embedded, setEmbedded] = useState<boolean>(false);
const filteredMemos = fetchedMemos.filter((memo) => !selectedMemos.includes(memo));

useDebounce(
async () => {
useEffect(() => {
const handler = setTimeout(() => {
setDebouncedSearchText(searchText.trim());
}, 300);

return () => {
clearTimeout(handler);
};
}, [searchText]);

useEffect(() => {
const fetchMemos = async () => {
setIsFetching(true);
try {
const filters = [`creator == "${user.name}"`, `row_status == "NORMAL"`];
if (searchText) {
filters.push(`content_search == [${JSON.stringify(searchText)}]`);
if (debouncedSearchText) {
filters.push(`content_search == [${JSON.stringify(debouncedSearchText)}]`);
}
const { memos } = await memoServiceClient.listMemos({
pageSize: DEFAULT_MEMO_LIMIT,
Expand All @@ -44,10 +54,10 @@
toast.error(error.response.data.message);
}
setIsFetching(false);
},
300,
[searchText],
);
};

if (debouncedSearchText) fetchMemos();
}, [debouncedSearchText]);

const getHighlightedContent = (content: string) => {
const index = content.toLowerCase().indexOf(searchText.toLowerCase());
Expand Down Expand Up @@ -106,7 +116,7 @@
inputValue={searchText}
value={selectedMemos}
multiple
onInputChange={(_, value) => setSearchText(value.trim())}
onInputChange={(_, value) => setSearchText(value)}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can only remove .trim() that will fulfill your needs. The other changes don't seem too important.

getOptionKey={(option) => option.name}
getOptionLabel={(option) => option.content}
isOptionEqualToValue={(option, value) => option.id === value.id}
Expand Down Expand Up @@ -159,4 +169,4 @@
);
}

export default showCreateMemoRelationDialog;
export default showCreateMemoRelationDialog;

Check failure on line 172 in web/src/components/CreateMemoRelationDialog.tsx

View workflow job for this annotation

GitHub Actions / eslint-checks

Insert `␍⏎`