From 38157ae14b558e320698909a36b231058e890c7c Mon Sep 17 00:00:00 2001 From: Paul <paulmakles@gmail.com> Date: Wed, 21 Jul 2021 18:27:05 +0100 Subject: [PATCH] Add search sorting. --- external/lang | 2 +- .../navigation/right/MemberSidebar.tsx | 25 +++++++++++++++++-- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/external/lang b/external/lang index 1c24f93..b70b4f3 160000 --- a/external/lang +++ b/external/lang @@ -1 +1 @@ -Subproject commit 1c24f933c97ee0f04fabe9b35a62719295af5cd5 +Subproject commit b70b4f395caf4dc4911c5ccbf7188de198875173 diff --git a/src/components/navigation/right/MemberSidebar.tsx b/src/components/navigation/right/MemberSidebar.tsx index cac65fe..0f70a03 100644 --- a/src/components/navigation/right/MemberSidebar.tsx +++ b/src/components/navigation/right/MemberSidebar.tsx @@ -23,6 +23,7 @@ import { } from "../../../context/revoltjs/hooks"; import CollapsibleSection from "../../common/CollapsibleSection"; +import Button from "../../ui/Button"; import Category from "../../ui/Category"; import InputBox from "../../ui/InputBox"; import Preloader from "../../ui/Preloader"; @@ -284,13 +285,16 @@ function Search({ channel }: { channel: string }) { if (!getState().experiments.enabled?.includes("search")) return null; const client = useContext(AppContext); + type Sort = "Relevance" | "Latest" | "Oldest"; + const [sort, setSort] = useState<Sort>("Relevance"); + const [query, setV] = useState(""); const [results, setResults] = useState<Message[]>([]); async function search() { const data = await client.channels.searchWithUsers( channel, - { query, sort: "Relevance" }, + { query, sort }, true, ); setResults(data.messages); @@ -301,7 +305,24 @@ function Search({ channel }: { channel: string }) { sticky id="search" 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 style={{ width: "100%" }} onKeyDown={(e) => e.key === "Enter" && search()} -- GitLab