From d8aae8593c9d93e6d7395b75fa2cd23162f84309 Mon Sep 17 00:00:00 2001 From: Mikayla Dobson <93477693+innocuous-symmetry@users.noreply.github.com> Date: Mon, 5 Dec 2022 18:16:15 -0600 Subject: [PATCH] continuing to build on ui, starting on add recipe --- client/src/App.tsx | 16 +++-- client/src/components/pages/AddRecipe.tsx | 61 +++++++++++++++++++ .../components/pages/CollectionBrowser.tsx | 11 ++++ client/src/components/pages/Welcome.tsx | 9 +-- client/src/components/ui/Dropdown.tsx | 15 +++++ client/src/components/ui/Form.tsx | 5 ++ .../ui/FormElements/CustomPicker.tsx | 5 ++ .../ui/FormElements/OptionFetcher.tsx | 20 ++++++ client/src/components/ui/Navbar/variants.tsx | 60 +++++++++++++++--- client/src/components/ui/Tooltip.tsx | 12 ++++ client/src/components/ui/index.ts | 6 +- client/src/sass/components/Dropdown.scss | 29 +++++++++ client/src/util/types.ts | 2 +- server/schemas/index.ts | 3 +- 14 files changed, 228 insertions(+), 26 deletions(-) create mode 100644 client/src/components/pages/CollectionBrowser.tsx create mode 100644 client/src/components/ui/FormElements/CustomPicker.tsx create mode 100644 client/src/components/ui/FormElements/OptionFetcher.tsx create mode 100644 client/src/sass/components/Dropdown.scss diff --git a/client/src/App.tsx b/client/src/App.tsx index 944dd05..fdadcf9 100644 --- a/client/src/App.tsx +++ b/client/src/App.tsx @@ -1,8 +1,11 @@ -import { BrowserRouter, Routes, Route } from 'react-router-dom'; +// framework tools and custom utils import { useCallback, useEffect, useState } from 'react'; +import { BrowserRouter, Routes, Route } from 'react-router-dom'; import { AuthContext, IAuthContext, useAuthContext } from './context/AuthContext'; +import { attemptLogout, checkCredientials } from './util/apiUtils'; import { IUser } from './schemas'; -import { checkCredientials } from './util/apiUtils'; + +// pages, ui, styles import Subscriptions from './components/pages/Subscriptions/Subscriptions'; import Browser from './components/pages/Browser'; import Collection from './components/pages/Collection'; @@ -11,8 +14,10 @@ import Profile from './components/pages/Profile'; import Recipe from './components/pages/Recipe'; import Register from './components/pages/Register'; import Welcome from './components/pages/Welcome'; -import './sass/App.scss' +import AddRecipe from './components/pages/AddRecipe'; +import CollectionBrowser from './components/pages/CollectionBrowser'; import { Navbar } from './components/ui'; +import './sass/App.scss' function App() { const [user, setUser] = useState({ user: undefined }); @@ -51,11 +56,14 @@ function App() { } /> } /> } /> - } /> + } /> + } /> } /> } /> } /> } /> + + } /> diff --git a/client/src/components/pages/AddRecipe.tsx b/client/src/components/pages/AddRecipe.tsx index e69de29..6e4af01 100644 --- a/client/src/components/pages/AddRecipe.tsx +++ b/client/src/components/pages/AddRecipe.tsx @@ -0,0 +1,61 @@ +import { useCallback, useEffect, useState } from "react"; +import { useAuthContext } from "../../context/AuthContext"; +import { IRecipe } from "../../schemas"; +import { Button, Divider, Form, Page, Panel } from "../ui" + +const AddRecipe = () => { + const { user } = useAuthContext(); + const [input, setInput] = useState({ name: '', preptime: '', description: '', authoruserid: user?.id || '', ingredients: [] }) + const [form, setForm] = useState(); + + const getFormState = useCallback((data: IRecipe) => { + setInput(data); + }, []) + + const handleCreate = () => { + for (let field of Object.keys(input)) { + if (!input[field as keyof IRecipe]) return; + } + + console.log('good to go!') + } + + useEffect(() => { + if (user) { + setInput((prev: IRecipe) => { + return { + ...prev, + authoruserid: user.id! + } + }) + } + }, [user]) + + useEffect(() => { + setForm( + new Form({ + parent: "AddRecipe", + keys: ["name", "preptime", "ingredients", "description"], + labels: ["Recipe Name:", "Prep Time:", "Ingredients:", "Description:"], + dataTypes: ['text', 'text', 'custom picker', 'text'], + initialState: input, + getState: getFormState + }).mount() + ) + }, []) + + + return ( + +

Add a New Recipe

+ + + + { form } + + +
+ ) +} + +export default AddRecipe; \ No newline at end of file diff --git a/client/src/components/pages/CollectionBrowser.tsx b/client/src/components/pages/CollectionBrowser.tsx new file mode 100644 index 0000000..d9b6644 --- /dev/null +++ b/client/src/components/pages/CollectionBrowser.tsx @@ -0,0 +1,11 @@ +import { Page } from "../ui"; + +const CollectionBrowser = () => { + return ( + +

Browsing your {2} collections:

+
+ ) +} + +export default CollectionBrowser; \ No newline at end of file diff --git a/client/src/components/pages/Welcome.tsx b/client/src/components/pages/Welcome.tsx index 6522d8d..3eadcd7 100644 --- a/client/src/components/pages/Welcome.tsx +++ b/client/src/components/pages/Welcome.tsx @@ -21,21 +21,14 @@ const Welcome = () => {

Ready to get started?

+
) - const unwrap = async () => { - const result = await checkCredientials(); - console.log(result); - } - return (

Welcome to Recipin

- - -
diff --git a/client/src/components/ui/Dropdown.tsx b/client/src/components/ui/Dropdown.tsx index e69de29..dd3f3be 100644 --- a/client/src/components/ui/Dropdown.tsx +++ b/client/src/components/ui/Dropdown.tsx @@ -0,0 +1,15 @@ +import { FC } from "react"; +import { Panel } from "."; +import { PortalBase } from "../../util/types"; +import "/src/sass/components/Dropdown.scss"; + +// expects to receive buttons as children +const Dropdown: FC = ({ children, extraStyles = null }) => { + return ( + + { children } + + ) +} + +export default Dropdown; \ No newline at end of file diff --git a/client/src/components/ui/Form.tsx b/client/src/components/ui/Form.tsx index 3a72e84..75b8e29 100644 --- a/client/src/components/ui/Form.tsx +++ b/client/src/components/ui/Form.tsx @@ -54,6 +54,11 @@ export default class Form{ let output = new Array(); for (let i = 0; i < this.keys.length; i++) { + if (this.dataTypes[i] == 'custom picker') { + console.log('noted!'); + this.dataTypes[i] = 'text'; + } + output.push(
diff --git a/client/src/components/ui/FormElements/CustomPicker.tsx b/client/src/components/ui/FormElements/CustomPicker.tsx new file mode 100644 index 0000000..cf82bad --- /dev/null +++ b/client/src/components/ui/FormElements/CustomPicker.tsx @@ -0,0 +1,5 @@ +const CustomPicker = () => { + +} + +export default CustomPicker; \ No newline at end of file diff --git a/client/src/components/ui/FormElements/OptionFetcher.tsx b/client/src/components/ui/FormElements/OptionFetcher.tsx new file mode 100644 index 0000000..a7bc3d1 --- /dev/null +++ b/client/src/components/ui/FormElements/OptionFetcher.tsx @@ -0,0 +1,20 @@ +import { FC } from "react"; +import { PortalBase } from "../../../util/types"; + +interface FetcherParams extends PortalBase { + fetchTarget: string +} + +const OptionFetcher: FC = ({ children, fetchTarget }) => { + const fetchOptions = async () => { + console.log(fetchTarget); + } + + return ( +
+ { children } +
+ ) +} + +export default OptionFetcher; \ No newline at end of file diff --git a/client/src/components/ui/Navbar/variants.tsx b/client/src/components/ui/Navbar/variants.tsx index 8105222..a9fa831 100644 --- a/client/src/components/ui/Navbar/variants.tsx +++ b/client/src/components/ui/Navbar/variants.tsx @@ -1,25 +1,65 @@ import { attemptLogout } from "../../../util/apiUtils"; import { NavbarType } from "../../../util/types"; -import Button from "../Button"; +import { Button, Dropdown } from '../.' +import { useState } from "react"; const LoggedIn: NavbarType = ({ received, liftChange, navigate }) => { + const [dropdownActive, setDropdownActive] = useState(false); + const [searchActive, setSearchActive] = useState(false); + const handleLogout = async () => { const success = await attemptLogout(); if (success) liftChange!(undefined); navigate('/'); } + const handleUIChange = (target: string) => { + if (target == "SEARCH") { + setSearchActive(!searchActive); + setDropdownActive(false); + } else { + setSearchActive(false); + setDropdownActive(!dropdownActive); + } + } + + const handleOptionSelect = (payload: string) => { + setSearchActive(false); + setDropdownActive(false); + navigate(payload); + } + return ( -