mirror of
https://github.com/stoatchat/for-legacy-web.git
synced 2026-03-08 01:45:28 +00:00
Add search sorting.
This commit is contained in:
2
external/lang
vendored
2
external/lang
vendored
Submodule external/lang updated: 1c24f933c9...b70b4f395c
@@ -23,6 +23,7 @@ import {
|
|||||||
} from "../../../context/revoltjs/hooks";
|
} from "../../../context/revoltjs/hooks";
|
||||||
|
|
||||||
import CollapsibleSection from "../../common/CollapsibleSection";
|
import CollapsibleSection from "../../common/CollapsibleSection";
|
||||||
|
import Button from "../../ui/Button";
|
||||||
import Category from "../../ui/Category";
|
import Category from "../../ui/Category";
|
||||||
import InputBox from "../../ui/InputBox";
|
import InputBox from "../../ui/InputBox";
|
||||||
import Preloader from "../../ui/Preloader";
|
import Preloader from "../../ui/Preloader";
|
||||||
@@ -284,13 +285,16 @@ function Search({ channel }: { channel: string }) {
|
|||||||
if (!getState().experiments.enabled?.includes("search")) return null;
|
if (!getState().experiments.enabled?.includes("search")) return null;
|
||||||
|
|
||||||
const client = useContext(AppContext);
|
const client = useContext(AppContext);
|
||||||
|
type Sort = "Relevance" | "Latest" | "Oldest";
|
||||||
|
const [sort, setSort] = useState<Sort>("Relevance");
|
||||||
|
|
||||||
const [query, setV] = useState("");
|
const [query, setV] = useState("");
|
||||||
const [results, setResults] = useState<Message[]>([]);
|
const [results, setResults] = useState<Message[]>([]);
|
||||||
|
|
||||||
async function search() {
|
async function search() {
|
||||||
const data = await client.channels.searchWithUsers(
|
const data = await client.channels.searchWithUsers(
|
||||||
channel,
|
channel,
|
||||||
{ query, sort: "Relevance" },
|
{ query, sort },
|
||||||
true,
|
true,
|
||||||
);
|
);
|
||||||
setResults(data.messages);
|
setResults(data.messages);
|
||||||
@@ -301,7 +305,24 @@ function Search({ channel }: { channel: string }) {
|
|||||||
sticky
|
sticky
|
||||||
id="search"
|
id="search"
|
||||||
defaultValue={false}
|
defaultValue={false}
|
||||||
summary={"Search (BETA)"}>
|
summary={
|
||||||
|
<>
|
||||||
|
<Text id="app.main.channel.search.title" /> (BETA)
|
||||||
|
</>
|
||||||
|
}>
|
||||||
|
<div style={{ display: "flex" }}>
|
||||||
|
{["Relevance", "Latest", "Oldest"].map((key) => (
|
||||||
|
<Button
|
||||||
|
style={{ flex: 1, minWidth: 0 }}
|
||||||
|
compact
|
||||||
|
error={sort === key}
|
||||||
|
onClick={() => setSort(key as Sort)}>
|
||||||
|
<Text
|
||||||
|
id={`app.main.channel.search.sort.${key.toLowerCase()}`}
|
||||||
|
/>
|
||||||
|
</Button>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
<InputBox
|
<InputBox
|
||||||
style={{ width: "100%" }}
|
style={{ width: "100%" }}
|
||||||
onKeyDown={(e) => e.key === "Enter" && search()}
|
onKeyDown={(e) => e.key === "Enter" && search()}
|
||||||
|
|||||||
Reference in New Issue
Block a user