Add search sorting.

This commit is contained in:
Paul 2021-07-21 18:27:05 +01:00
parent f5e70afb35
commit 38157ae14b
2 changed files with 24 additions and 3 deletions

2
external/lang vendored

@ -1 +1 @@
Subproject commit 1c24f933c97ee0f04fabe9b35a62719295af5cd5 Subproject commit b70b4f395caf4dc4911c5ccbf7188de198875173

View file

@ -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()}