synapse-react-client
Version:
[](https://badge.fury.io/js/synapse-react-client) [](https://github.com/prettier/prettie
151 lines (150 loc) • 4.27 kB
JavaScript
import { jsxs as r, jsx as e, Fragment as m } from "react/jsx-runtime";
import j from "../../assets/icons/NoSearchResults.js";
import { useGetEntity as F } from "../../synapse-queries/entity/useEntity.js";
import { useSearchForumInfinite as k } from "../../synapse-queries/forum/useForum.js";
import A from "@mui/icons-material/Search";
import { TextField as C, InputAdornment as x, IconButton as P, Typography as s, Button as B, Box as D } from "@mui/material";
import { useState as u, useEffect as S } from "react";
import E from "../Forum/DiscussionSearchResult.js";
import L from "../IconSvg/IconSvg.js";
import { displayToast as $ } from "../ToastMessage/ToastMessage.js";
const q = () => /* @__PURE__ */ r(
D,
{
sx: {
textAlign: "center"
},
children: [
/* @__PURE__ */ e(j, { height: "181px", sx: { pt: "40px", pb: "10px" } }),
/* @__PURE__ */ e(s, { variant: "body1", children: "No results with this query" }),
/* @__PURE__ */ e(s, { variant: "body1Italic", children: "Search the full text of posts, replies, and titles" })
]
}
), W = (n) => {
const { onSearchResultsVisible: a } = n, [i, p] = u(""), [o, g] = u(""), [c, f] = u(!1), { data: l } = F(n.projectId, void 0, {
enabled: !!n.projectId
}), {
data: y,
isLoading: v,
hasNextPage: R,
isFetchingNextPage: N,
fetchNextPage: b,
error: d
} = k(
n.forumId,
{ searchString: o },
{ enabled: !!o }
);
S(() => {
d && $(d.reason, "danger");
}, [d]);
const h = y?.pages.flatMap((t) => t.matches ?? []) ?? [], I = !v && o && h.length == 0, w = () => {
f(!1), p("");
};
function T() {
g(i), f(!0);
}
return S(() => {
a && a(c);
}, [c, a]), /* @__PURE__ */ r("div", { className: "ForumSearch", children: [
/* @__PURE__ */ e("div", { children: /* @__PURE__ */ e(
C,
{
sx: (t) => ({
[t.breakpoints.down("md")]: {
width: "100%"
}
}),
type: "search",
placeholder: "Search discussions",
value: i,
onChange: (t) => {
p(t.target.value);
},
onKeyDown: (t) => {
t.key === "Enter" && T();
},
slotProps: {
input: {
startAdornment: /* @__PURE__ */ e(x, { position: "start", children: /* @__PURE__ */ e(A, {}) }),
endAdornment: i && /* @__PURE__ */ e(x, { position: "end", children: /* @__PURE__ */ e(
P,
{
size: "small",
onClick: () => {
w();
},
children: /* @__PURE__ */ e(L, { icon: "clear", wrap: !1 })
}
) })
}
}
}
) }),
c && /* @__PURE__ */ r(m, { children: [
I && /* @__PURE__ */ r(m, { children: [
n.projectId && l && /* @__PURE__ */ r(s, { variant: "body1Italic", className: "NoResultsText", children: [
'No results for "',
o,
'" in ',
l?.name
] }),
/* @__PURE__ */ e(q, {})
] }),
h && /* @__PURE__ */ r(m, { children: [
n.projectId && !I && /* @__PURE__ */ r(
s,
{
variant: "body1Italic",
className: "ResultsText",
sx: {
my: 2,
mx: 1
},
children: [
'Results for "',
o,
'" in ',
l?.name,
":"
]
}
),
h.map((t) => /* @__PURE__ */ e(
"div",
{
children: /* @__PURE__ */ e(
E,
{
threadId: t.threadId,
replyId: t.replyId
}
)
},
`${t.forumId}-${t.threadId}-${t.replyId}`
))
] }),
R && /* @__PURE__ */ e(
B,
{
variant: "contained",
color: "primary",
disabled: N,
onClick: () => {
b();
},
sx: {
mx: 1,
mt: 2
},
children: "Load more"
}
)
] })
] });
};
export {
W as ForumSearch,
W as default
};
//# sourceMappingURL=ForumSearch.js.map