From 243c1a8c58578ab5e065eb0d6983ca6c2f157c9a Mon Sep 17 00:00:00 2001
From: lingdocs <71590811+lingdocs@users.noreply.github.com>
Date: Thu, 10 Feb 2022 11:34:15 +0400
Subject: [PATCH] language select working
---
components/BookInfoInput.tsx | 7 ++-----
components/LanguageSelect.tsx | 5 +++--
pages/index.tsx | 8 ++++++++
3 files changed, 13 insertions(+), 7 deletions(-)
diff --git a/components/BookInfoInput.tsx b/components/BookInfoInput.tsx
index befb9fe..394e5eb 100644
--- a/components/BookInfoInput.tsx
+++ b/components/BookInfoInput.tsx
@@ -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
diff --git a/components/LanguageSelect.tsx b/components/LanguageSelect.tsx
index 56146da..9a12d9b 100644
--- a/components/LanguageSelect.tsx
+++ b/components/LanguageSelect.tsx
@@ -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(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}
diff --git a/pages/index.tsx b/pages/index.tsx
index 63959cb..37d6caa 100644
--- a/pages/index.tsx
+++ b/pages/index.tsx
@@ -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,