From c4a8208d8a4264e4e663669ca4c9387a3f6e33ce Mon Sep 17 00:00:00 2001 From: Mikayla Dobson <93477693+innocuous-symmetry@users.noreply.github.com> Date: Thu, 8 Dec 2022 17:28:46 -0600 Subject: [PATCH] cleanup and refactoring --- client/src/components/pages/AddRecipe.tsx | 10 ++++----- client/src/components/pages/Login.tsx | 4 ++-- .../components/pages/Register/aboutyou.tsx | 22 +++++++++---------- client/src/components/ui/Form.tsx | 5 ++++- client/src/components/ui/index.ts | 3 +-- 5 files changed, 22 insertions(+), 22 deletions(-) diff --git a/client/src/components/pages/AddRecipe.tsx b/client/src/components/pages/AddRecipe.tsx index 0b5f1ab..9cd599b 100644 --- a/client/src/components/pages/AddRecipe.tsx +++ b/client/src/components/pages/AddRecipe.tsx @@ -6,7 +6,7 @@ import { Button, Divider, Form, Page, Panel } from "../ui" const AddRecipe = () => { const authContext = useAuthContext(); const [input, setInput] = useState({ name: '', preptime: '', description: '', authoruserid: '', ingredients: [] }) - const [form, setForm] = useState(); + const [form, setForm] = useState(); const getFormState = useCallback((data: IRecipe) => { setInput(data); @@ -33,9 +33,9 @@ const AddRecipe = () => { input.authoruserid && setForm( new Form({ parent: "AddRecipe", - keys: ["name", "preptime", "ingredients", "description"], - labels: ["Recipe Name:", "Prep Time:", "Ingredients:", "Description:"], - dataTypes: ['text', 'text', 'custom picker', 'TINYMCE'], + keys: ["name", "preptime", "course", "cuisine", "ingredients", "description"], + labels: ["Recipe Name:", "Prep Time:", "Course:", "Cuisine:", "Ingredients:", "Description:"], + dataTypes: ['text', 'text', 'custom picker', 'custom picker', 'custom picker', 'TINYMCE'], initialState: input, getState: getFormState, richTextInitialValue: "

Enter recipe details here!

" @@ -53,7 +53,7 @@ const AddRecipe = () => { - { form } + { form ||

Loading...

}
diff --git a/client/src/components/pages/Login.tsx b/client/src/components/pages/Login.tsx index 16969d3..313eaf0 100644 --- a/client/src/components/pages/Login.tsx +++ b/client/src/components/pages/Login.tsx @@ -9,7 +9,7 @@ export default function Login() { // setup and local state const authContext = useAuthContext(); const navigate = useNavigate(); - const [form, setForm] = useState(); + const [form, setForm] = useState(); const [input, setInput] = useState({ email: '', password: '' }); // retrieve and store state from form @@ -45,7 +45,7 @@ export default function Login() {

Hello! Nice to see you again.

- { form } + { form ||

Loading...

}
diff --git a/client/src/components/pages/Register/aboutyou.tsx b/client/src/components/pages/Register/aboutyou.tsx index b7a7ae3..3b6ad87 100644 --- a/client/src/components/pages/Register/aboutyou.tsx +++ b/client/src/components/pages/Register/aboutyou.tsx @@ -22,7 +22,7 @@ const blankUser: IUser = { const AboutYou: RegisterVariantType = ({ transitionDisplay }) => { const navigate = useNavigate(); const authContext = useAuthContext(); - const [form, setForm] = useState([

Loading content...

]); + const [form, setForm] = useState(

Loading content...

); const [input, setInput] = useState(blankUser); const [regSuccess, setRegSuccess] = useState(); @@ -34,15 +34,6 @@ const AboutYou: RegisterVariantType = ({ transitionDisplay }) => { if (authContext.user) navigate('/'); }, [authContext]); - const formConfig: FormConfig = { - parent: "register", - keys: ['firstname', 'lastname', 'handle', 'email', 'password'], - initialState: input, - labels: ['First Name', 'Last Name', 'Handle', 'Email', "Password"], - dataTypes: ['text', 'text', 'text', 'email', 'password'], - getState: getFormState - } - async function handleRegister() { const res = await attemptRegister(input); if (res.ok) { @@ -60,7 +51,14 @@ const AboutYou: RegisterVariantType = ({ transitionDisplay }) => { } useEffect(() => { - setForm(new Form(formConfig).mount()); + setForm(new Form({ + parent: "register", + keys: ['firstname', 'lastname', 'handle', 'email', 'password'], + initialState: input, + labels: ['First Name', 'Last Name', 'Handle', 'Email', "Password"], + dataTypes: ['text', 'text', 'text', 'email', 'password'], + getState: getFormState + }).mount()); }, []) useEffect(() => { @@ -76,7 +74,7 @@ const AboutYou: RegisterVariantType = ({ transitionDisplay }) => {

Tell us a bit about yourself:

- { form } + { form ||

Loading...

}
diff --git a/client/src/components/ui/Form.tsx b/client/src/components/ui/Form.tsx index 26aecec..2904f96 100644 --- a/client/src/components/ui/Form.tsx +++ b/client/src/components/ui/Form.tsx @@ -17,6 +17,7 @@ export interface FormConfig { labels?: string[] dataTypes?: string[] richTextInitialValue?: string + extraStyles?: string } export default class Form{ @@ -27,6 +28,7 @@ export default class Form{ private state: T; private getState: (received: T) => void private richTextInitialValue?: string; + private extraStyles?: string constructor(config: FormConfig){ this.parent = config.parent; @@ -36,6 +38,7 @@ export default class Form{ this.state = config.initialState; this.getState = config.getState; this.richTextInitialValue = config.richTextInitialValue; + this.extraStyles = config.extraStyles; } update(e: ChangeEvent, idx: number) { @@ -92,6 +95,6 @@ export default class Form{ output.push(input); } - return output; + return
{output}
; } } \ No newline at end of file diff --git a/client/src/components/ui/index.ts b/client/src/components/ui/index.ts index 2fc977c..a456fd8 100644 --- a/client/src/components/ui/index.ts +++ b/client/src/components/ui/index.ts @@ -6,11 +6,10 @@ import Form from "./Form"; import Navbar from "./Navbar"; import Page from "./Page"; import Panel from "./Panel"; -import Quill from "./Quill"; import TextField from "./TextField"; import Tooltip from "./Tooltip"; import UserCard from "./UserCard"; export { - Button, Card, Dropdown, Divider, Form, Navbar, Page, Panel, Quill, TextField, Tooltip, UserCard + Button, Card, Dropdown, Divider, Form, Navbar, Page, Panel, TextField, Tooltip, UserCard } \ No newline at end of file