language select working
This commit is contained in:
parent
e7701f4b7d
commit
243c1a8c58
|
@ -58,9 +58,8 @@ function BookInfoInput({ handleSubmit }: { handleSubmit: (info: { frontmatter: F
|
|||
function handleLanguageChange(lang: string | null) {
|
||||
setState(s => {
|
||||
if (!lang) {
|
||||
delete s.lang;
|
||||
delete s.language;
|
||||
return s
|
||||
const { lang, language, ...rest } = s;
|
||||
return rest;
|
||||
}
|
||||
return {
|
||||
...s,
|
||||
|
@ -80,8 +79,6 @@ function BookInfoInput({ handleSubmit }: { handleSubmit: (info: { frontmatter: F
|
|||
cover,
|
||||
});
|
||||
}
|
||||
console.log(state);
|
||||
console.log("will render");
|
||||
return <div style={{ maxWidth: "500px" }}>
|
||||
<div className="my-3">
|
||||
<label htmlFor="cover-file" className="form-label">cover image <span className="text-muted">(.jpg or .png less than 5mb)</span></label>
|
||||
|
|
|
@ -13,13 +13,14 @@ const languageOptions = [
|
|||
];
|
||||
|
||||
function LanguageSelect({ value, onChange }: {
|
||||
value: string | null,
|
||||
value: string | undefined,
|
||||
onChange: (language: string | null) => void,
|
||||
}) {
|
||||
const [showingOther, setShowingOther] = useState<boolean>(false);
|
||||
function handleChange(o: { value: string, label: string }) {
|
||||
if (!o) {
|
||||
onChange(null);
|
||||
if (showingOther) setShowingOther(false);
|
||||
} else if (o.value === "other") {
|
||||
setShowingOther(true);
|
||||
onChange(null);
|
||||
|
@ -34,7 +35,7 @@ function LanguageSelect({ value, onChange }: {
|
|||
className="basic-single"
|
||||
classNamePrefix="select"
|
||||
isClearable={true}
|
||||
value={typeof value === "number" ? null : languageOptions.find(o => value === o.value)}
|
||||
value={languageOptions.find(o => value === o.value)}
|
||||
isSearchable
|
||||
// @ts-ignore
|
||||
onChange={handleChange}
|
||||
|
|
|
@ -20,6 +20,14 @@ const Home: NextPage = () => {
|
|||
}
|
||||
function handleSubmit(info: { frontmatter: Frontmatter, cover: File | undefined }) {
|
||||
const content = mdRef.current.value as string;
|
||||
if (!content) {
|
||||
alert("Please enter some content for the book");
|
||||
return;
|
||||
}
|
||||
if (!info.frontmatter.title) {
|
||||
alert("Please enter a title for the book");
|
||||
return;
|
||||
}
|
||||
bookRequest({
|
||||
...info,
|
||||
content,
|
||||
|
|
Loading…
Reference in New Issue