diff --git a/package.json b/package.json index c926ce5c4..d6bfd339e 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,8 @@ "scripts": { "start": "node index.js", "watch": "nodemon index.js", - "build": "rm -rf build && cd react-ui && npm run build && mv build ../build" + "build": "rm -rf build && cd react-ui && npm run build && mv build ../build", + "testbuild": "rmdir /s /q build && cd react-ui && npm run build && move build ../build" }, "author": "Sendou", "license": "ISC", diff --git a/react-ui/src/components/root/App.test.js b/react-ui/src/components/root/App.test.js deleted file mode 100644 index a754b201b..000000000 --- a/react-ui/src/components/root/App.test.js +++ /dev/null @@ -1,9 +0,0 @@ -import React from 'react'; -import ReactDOM from 'react-dom'; -import App from './App'; - -it('renders without crashing', () => { - const div = document.createElement('div'); - ReactDOM.render(, div); - ReactDOM.unmountComponentAtNode(div); -}); diff --git a/react-ui/src/components/root/MainMenu.js b/react-ui/src/components/root/MainMenu.js index 6b5d1ef82..bde09479b 100644 --- a/react-ui/src/components/root/MainMenu.js +++ b/react-ui/src/components/root/MainMenu.js @@ -1,6 +1,8 @@ import React from "react" import { Menu, Container, Image, Dropdown, Icon } from "semantic-ui-react" -import { Link, NavLink } from "react-router-dom" +import { Link, NavLink, useHistory } from "react-router-dom" +import { userLean } from "../../graphql/queries/userLean" +import { useQuery } from "@apollo/react-hooks" import sink_logo from "../../assets/sink_logo.png" const dropdownStyle = { @@ -10,6 +12,61 @@ const dropdownStyle = { } const MainMenu = () => { + const { data, error, loading } = useQuery(userLean) + const history = useHistory() + + const logInOrAva = () => { + if (loading) { + return null + } + + if (!data || !data.user || error) { + return ( + + + Log in via Discord + + ) + } + + const user = data.user + + const userMenuOptions = [ + { + key: "user", + text: "User Page", + icon: "user", + onClick: () => history.push(`/u/${user.discord_id}`) + }, + { + key: "sign-out", + text: "Sign Out", + icon: "sign out", + onClick: () => window.location.assign("/logout") + } + ] + + const userMenuTrigger = ( + + {user.username} + {" "} + + ) + + return ( + + + + ) + } return ( @@ -60,10 +117,7 @@ const MainMenu = () => { - - - Log in via Discord - + {logInOrAva()} ) diff --git a/react-ui/src/components/user/AddBuildForm.js b/react-ui/src/components/user/AddBuildForm.js index e3ed078fb..2514d6612 100644 --- a/react-ui/src/components/user/AddBuildForm.js +++ b/react-ui/src/components/user/AddBuildForm.js @@ -58,11 +58,15 @@ const AddBuildForm = ({ shoesItem } - const submit = async e => { + const submit = async (e, func) => { e.preventDefault() let buildToAdd = { ...build } if (buildToAdd.title === "") delete buildToAdd.title + if (buildToAdd.description === "") delete buildToAdd.description + if (buildToAdd.headgearItem === "") delete buildToAdd.headgearItem + if (buildToAdd.clothingItem === "") delete buildToAdd.clothingItem + if (buildToAdd.shoesItem === "") delete buildToAdd.shoesItem await addBuild({ variables: { ...buildToAdd } @@ -70,7 +74,11 @@ const AddBuildForm = ({ setWeapon("") setTitle("") + setDescription("") setAbilities([["", "", "", ""], ["", "", "", ""], ["", "", "", ""]]) + setHeadgear("") + setClothing("") + setShoes("") setSuccessMsg("New build succesfully added!") setTimeout(() => { setSuccessMsg(null) @@ -155,7 +163,6 @@ const AddBuildForm = ({ onClick={() => { editBuildFunction(build) setShowEdit(false) - window.scrollTo(0, 0) }} > Edit build diff --git a/react-ui/src/components/user/UserPage.js b/react-ui/src/components/user/UserPage.js index ee7badae2..713221c73 100644 --- a/react-ui/src/components/user/UserPage.js +++ b/react-ui/src/components/user/UserPage.js @@ -19,6 +19,7 @@ const UserPage = () => { useEffect(() => { if (loading) return + console.log("data", data) document.title = `${data.searchForUser.username} - sendou.ink` }, [loading, data]) diff --git a/react-ui/src/graphql/mutations/addBuild.js b/react-ui/src/graphql/mutations/addBuild.js index 50438e88f..4d0ccafc9 100644 --- a/react-ui/src/graphql/mutations/addBuild.js +++ b/react-ui/src/graphql/mutations/addBuild.js @@ -1,21 +1,39 @@ -import { gql } from 'apollo-boost' +import { gql } from "apollo-boost" export const addBuild = gql` -mutation addBuild ($weapon: String!, $title: String, $headgear: [Ability!]!, $clothing: [Ability!]!, $shoes: [Ability!]!) { - addBuild( - weapon: $weapon, - title: $title, - headgear: $headgear, - clothing: $clothing, - shoes: $shoes - ) { - id - weapon - title - headgear - clothing - shoes - updatedAt - } -} -` \ No newline at end of file + mutation addBuild( + $weapon: String! + $title: String + $description: String + $headgear: [Ability!]! + $headgearItem: String + $clothing: [Ability!]! + $clothingItem: String + $shoes: [Ability!]! + $shoesItem: String + ) { + addBuild( + weapon: $weapon + title: $title + description: $description + headgear: $headgear + headgearItem: $headgearItem + clothing: $clothing + clothingItem: $clothingItem + shoes: $shoes + shoesItem: $shoesItem + ) { + id + weapon + title + description + headgear + headgearItem + clothing + clothingItem + shoes + shoesItem + updatedAt + } + } +` diff --git a/react-ui/src/graphql/mutations/updateBuild.js b/react-ui/src/graphql/mutations/updateBuild.js index f2e07a9fa..310e61c63 100644 --- a/react-ui/src/graphql/mutations/updateBuild.js +++ b/react-ui/src/graphql/mutations/updateBuild.js @@ -1,14 +1,28 @@ -import { gql } from 'apollo-boost' +import { gql } from "apollo-boost" export const updateBuild = gql` -mutation updateBuild ($id: ID!, $weapon: String!, $title: String, $headgear: [Ability!]!, $clothing: [Ability!]!, $shoes: [Ability!]!) { - updateBuild( - id: $id, - weapon: $weapon, - title: $title, - headgear: $headgear, - clothing: $clothing, - shoes: $shoes - ) -} -` \ No newline at end of file + mutation updateBuild( + $id: ID! + $title: String + $description: String + $headgear: [Ability!]! + $headgearItem: String + $clothing: [Ability!]! + $clothingItem: String + $shoes: [Ability!]! + $shoesItem: String + ) { + updateBuild( + id: $id + weapon: $weapon + title: $title + description: $description + headgear: $headgear + headgearItem: $headgearItem + clothing: $clothing + clothingItem: $clothingItem + shoes: $shoes + shoesItem: $shoesItem + ) + } +` diff --git a/react-ui/src/graphql/queries/searchForBuilds.js b/react-ui/src/graphql/queries/searchForBuilds.js index 42349de59..5e9b22d15 100644 --- a/react-ui/src/graphql/queries/searchForBuilds.js +++ b/react-ui/src/graphql/queries/searchForBuilds.js @@ -1,16 +1,20 @@ -import { gql } from 'apollo-boost' +import { gql } from "apollo-boost" export const searchForBuilds = gql` -query searchForBuilds($discord_id: String!) { - searchForBuilds(discord_id: $discord_id) { - id - weapon - title - headgear - clothing - shoes - updatedAt - top + query searchForBuilds($discord_id: String!) { + searchForBuilds(discord_id: $discord_id) { + id + weapon + title + description + headgear + headgearItem + clothing + clothingItem + shoes + shoesItem + updatedAt + top + } } -} -` \ No newline at end of file +` diff --git a/react-ui/src/index.js b/react-ui/src/index.js index c0dd40471..2963a97e0 100644 --- a/react-ui/src/index.js +++ b/react-ui/src/index.js @@ -8,11 +8,12 @@ import { BrowserRouter as Router } from "react-router-dom" import "semantic-ui-css/semantic.min.css" import "./index.css" +//TODO: figure out how to do this well const client = new ApolloClient({ uri: - process.env.REACT_APP_APOLLO_URI === "local" - ? "http://localhost:3001/graphql" - : "https://www.sendou.ink/graphql" + process.env.NODE_ENV === "production" + ? "/graphql" + : "http://localhost:3001/graphql" }) ReactDOM.render( diff --git a/schemas/build.js b/schemas/build.js index 0c515735b..76361e82e 100644 --- a/schemas/build.js +++ b/schemas/build.js @@ -152,7 +152,7 @@ const resolvers = { invalidArgs: args }) - const items = gear.map(brand => { + const items = gear.flatMap(brand => { const headItems = brand.head ? brand.head : [] const clothesItems = brand.clothes ? brand.clothes : [] const shoesItems = brand.shoes ? brand.shoes : [] @@ -237,7 +237,7 @@ const resolvers = { invalidArgs: args }) - const items = gear.map(brand => { + const items = gear.flatMap(brand => { const headItems = brand.head ? brand.head : [] const clothesItems = brand.clothes ? brand.clothes : [] const shoesItems = brand.shoes ? brand.shoes : []