sendou.ink/app/components/layout/SearchInput.tsx
Kalle 185295d54e
User page initial with SQLite3 (#822)
* Clean away prisma migrations

* Way to migrate WIP

* SQLite3 seeding script initial

* Fetch tournament data in loader

* CheckinActions new loader data model

* Virtual banner text color columns

* Logged in user

* Count teams

* ownTeam

* Map pool tab fully working

* Teams tab

* Fix timestamp default

* Register page

* Manage team page

* Camel case checkedInTimestamp

* Clean slate

* Add .nvmrc

* Add favicon

* Package lock file version 2

* Update tsconfig

* Add Tailwind

* Add StrictMode

* Add background color

* Auth without DB

* Revert "Add Tailwind"

This reverts commit 204713c602.

* Auth with DB

* Switch back to tilde absolute import

* Import layout

* Camel case for database columns

* Move auth routes to folder

* User popover links working

* Import linters

* User page initial

* User edit page with country

* Script to delete db files before migration in dev

* Remove "youtubeName" column

* Correct avatar size on desktop

* Fix SubNav not spanning the whole page

* Remove duplicate files

* Update README
2022-05-16 17:52:54 +03:00

82 lines
1.9 KiB
TypeScript

import clsx from "clsx";
import * as React from "react";
export function SearchInput() {
if (process.env.NODE_ENV !== "development") return <div />;
return <SearchInputDev />;
}
export function SearchInputDev() {
const [inputValue, setInputValue] = React.useState("");
const handleEnter = () => {
const [action, value] = inputValue.split(":");
if (!action) return;
let fetchUrl = "";
switch (action) {
case "liu": {
if (!value) return;
fetchUrl = `/mock-auth?username=${encodeURIComponent(value)}`;
break;
}
case "lit": {
if (!value) return;
fetchUrl = `/mock-auth?team=${encodeURIComponent(value)}`;
break;
}
case "seed": {
if (!value) fetchUrl = "/seed";
else fetchUrl = `/seed?variation=${encodeURIComponent(value)}`;
break;
}
default: {
console.error("invalid action");
return;
}
}
return fetch(fetchUrl, { method: "post" }).then((res) => {
if (res.status === 200) location.reload();
else {
console.error(`http error when trying an admin action: ${res.status}`);
}
});
};
return (
<DumbSearchInput
value={inputValue}
setValue={setInputValue}
handleEnter={handleEnter}
/>
);
}
export function DumbSearchInput({
value,
setValue,
handleEnter,
}: {
value: string;
setValue: (newValue: string) => void;
handleEnter: () => Promise<void> | undefined;
}) {
return (
<div className={"layout__search-input__container"}>
<input
className={clsx("plain", "layout__search-input")}
type="text"
placeholder="Admin command"
value={value}
onChange={(e) => setValue(e.target.value)}
onKeyDown={(event) => {
if (event.key === "Enter") {
void handleEnter();
}
}}
/>
</div>
);
}