search clean page setup ready for just the results needed
This commit is contained in:
@@ -4,6 +4,7 @@ enum Routes {
|
|||||||
done = "/s#done",
|
done = "/s#done",
|
||||||
drawer = "/s#drawer",
|
drawer = "/s#drawer",
|
||||||
createConvo = "/s#createConversation",
|
createConvo = "/s#createConversation",
|
||||||
|
search = "/s#search",
|
||||||
}
|
}
|
||||||
|
|
||||||
export default Routes;
|
export default Routes;
|
||||||
|
|||||||
@@ -120,6 +120,8 @@ export default function CreateConversation() {
|
|||||||
>
|
>
|
||||||
<span>Create</span>
|
<span>Create</span>
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
|
{/* if it's a one on one, and i already have a conversation with them, then block creating a new one? */}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
// import Routes from "@nirvana/common/helpers/routes";
|
// import Routes from "@nirvana/common/helpers/routes";
|
||||||
|
import Routes from "@nirvana/common/helpers/routes";
|
||||||
import { Menu, Dropdown, Avatar } from "antd";
|
import { Menu, Dropdown, Avatar } from "antd";
|
||||||
import { useRouter } from "next/router";
|
import { useRouter } from "next/router";
|
||||||
import { useRef } from "react";
|
import { useRef, useState } from "react";
|
||||||
import { KeyMap, GlobalHotKeys } from "react-hotkeys";
|
import { KeyMap, GlobalHotKeys } from "react-hotkeys";
|
||||||
import {
|
import {
|
||||||
FaUser,
|
FaUser,
|
||||||
@@ -44,10 +45,29 @@ export default function Header() {
|
|||||||
);
|
);
|
||||||
|
|
||||||
const inputRef = useRef<HTMLInputElement | undefined>();
|
const inputRef = useRef<HTMLInputElement | undefined>();
|
||||||
|
|
||||||
|
const [searchInput, setSearchInput] = useState<string>("");
|
||||||
|
|
||||||
const selectSearch = () => {
|
const selectSearch = () => {
|
||||||
inputRef.current?.focus();
|
inputRef.current?.focus();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const updateInput = (e) => {
|
||||||
|
const newSearchInput = e.target.value;
|
||||||
|
setSearchInput(newSearchInput);
|
||||||
|
|
||||||
|
if (!newSearchInput) {
|
||||||
|
router.query.q = undefined;
|
||||||
|
} else {
|
||||||
|
// update url => initiates the search
|
||||||
|
router.query.q = encodeURI(newSearchInput);
|
||||||
|
}
|
||||||
|
|
||||||
|
router.push({
|
||||||
|
query: { q: encodeURI(newSearchInput) },
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
const keyMap: KeyMap = {
|
const keyMap: KeyMap = {
|
||||||
SELECT_SEARCH: {
|
SELECT_SEARCH: {
|
||||||
name: "select search to start searching",
|
name: "select search to start searching",
|
||||||
@@ -88,8 +108,10 @@ export default function Header() {
|
|||||||
<FaSearch className="text-lg text-slate-300" />
|
<FaSearch className="text-lg text-slate-300" />
|
||||||
<input
|
<input
|
||||||
placeholder="Type / to search"
|
placeholder="Type / to search"
|
||||||
className="bg-transparent placeholder-slate-300"
|
className="bg-transparent placeholder-slate-300 p-2 w-96"
|
||||||
ref={inputRef}
|
ref={inputRef}
|
||||||
|
onChange={updateInput}
|
||||||
|
value={searchInput}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
import { useRouter } from "next/router";
|
||||||
|
|
||||||
|
export default function SearchResults() {
|
||||||
|
const router = useRouter();
|
||||||
|
|
||||||
|
const q = router.query.q;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="mx-auto my-auto flex flex-col">
|
||||||
|
<span className="text-xs text-slate-400">0 results for {`"${q}"`}</span>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -17,6 +17,7 @@ import {
|
|||||||
import CreateConversation from "../../components/v2/CreateConversation";
|
import CreateConversation from "../../components/v2/CreateConversation";
|
||||||
import { FaArrowLeft } from "react-icons/fa";
|
import { FaArrowLeft } from "react-icons/fa";
|
||||||
import KeyboardShortcutHandler from "../../components/v2/KeyboardShortcutHandler";
|
import KeyboardShortcutHandler from "../../components/v2/KeyboardShortcutHandler";
|
||||||
|
import SearchResults from "../../components/v2/SearchResults";
|
||||||
|
|
||||||
export default function Me() {
|
export default function Me() {
|
||||||
// figure out what content to render from here
|
// figure out what content to render from here
|
||||||
@@ -61,6 +62,8 @@ export default function Me() {
|
|||||||
var fullCleanPageContent: ReactElement = undefined;
|
var fullCleanPageContent: ReactElement = undefined;
|
||||||
if (currRoute === Routes.createConvo) {
|
if (currRoute === Routes.createConvo) {
|
||||||
fullCleanPageContent = <CreateConversation />;
|
fullCleanPageContent = <CreateConversation />;
|
||||||
|
} else if (router.query.q) {
|
||||||
|
fullCleanPageContent = <SearchResults />;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fullCleanPageContent) {
|
if (fullCleanPageContent) {
|
||||||
@@ -82,6 +85,7 @@ export default function Me() {
|
|||||||
</span>
|
</span>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{fullCleanPageContent}
|
{fullCleanPageContent}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user