Showing
3 changed files
with
0 additions
and
271 deletions
| 1 | -import React, { useState } from "react"; | ||
| 2 | -import { useMutation } from "@apollo/react-hooks"; | ||
| 3 | -import { withRouter } from "react-router-dom"; | ||
| 4 | -import RoomPresenter from "./RoomPresenter"; | ||
| 5 | -import { CREATE_ROOM } from "./RoomQueries"; | ||
| 6 | -import useInput from "../../Hooks/useInput"; | ||
| 7 | -import { toast } from "react-toastify"; | ||
| 8 | - | ||
| 9 | -export default withRouter(() => { | ||
| 10 | - const [action, setAction] = useState("showList"); | ||
| 11 | - | ||
| 12 | - const roomName = useInput(""); | ||
| 13 | - | ||
| 14 | - const [createRoom] = useMutation(CREATE_ROOM); | ||
| 15 | - | ||
| 16 | - let newRoomObj; | ||
| 17 | - | ||
| 18 | - const onSubmit = async (e) => { | ||
| 19 | - e.preventDefault(); | ||
| 20 | - if (roomName.value !== "") { | ||
| 21 | - try { | ||
| 22 | - newRoomObj = await createRoom({ variables: { name: roomName.value } }); | ||
| 23 | - if (!newRoomObj) { | ||
| 24 | - // when fail to create room | ||
| 25 | - toast.error("fail to create new room"); | ||
| 26 | - } else { | ||
| 27 | - // when success to make room | ||
| 28 | - toast.success("success to make new room !"); | ||
| 29 | - setAction("showList"); | ||
| 30 | - } | ||
| 31 | - } catch { | ||
| 32 | - toast.error("occur unexpected error"); | ||
| 33 | - } | ||
| 34 | - } else { | ||
| 35 | - toast.error("room name is required !"); | ||
| 36 | - } | ||
| 37 | - }; | ||
| 38 | - | ||
| 39 | - return ( | ||
| 40 | - <RoomPresenter | ||
| 41 | - action={action} | ||
| 42 | - setAction={setAction} | ||
| 43 | - onSubmit={onSubmit} | ||
| 44 | - roomName={roomName} | ||
| 45 | - /> | ||
| 46 | - ); | ||
| 47 | -}); |
| 1 | -import React from "react"; | ||
| 2 | -import styled from "styled-components"; | ||
| 3 | -import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; | ||
| 4 | -import { faArrowRight } from "@fortawesome/free-solid-svg-icons"; | ||
| 5 | -import { Link } from "react-router-dom"; | ||
| 6 | -import Input from "../../Components/Input"; | ||
| 7 | -import Button from "../../Components/Button"; | ||
| 8 | -import { useQuery } from "@apollo/react-hooks"; | ||
| 9 | -import { GET_ROOMS } from "./RoomQueries"; | ||
| 10 | - | ||
| 11 | -const Wrapper = styled.div` | ||
| 12 | - display: flex; | ||
| 13 | - flex-direction: column; | ||
| 14 | - width: 100%; | ||
| 15 | - justify-content: center; | ||
| 16 | - align-items: center; | ||
| 17 | - .Header { | ||
| 18 | - position: fixed; | ||
| 19 | - top: 0; | ||
| 20 | - } | ||
| 21 | -`; | ||
| 22 | - | ||
| 23 | -const HideWrapper = styled.div` | ||
| 24 | - display: flex; | ||
| 25 | - flex-direction: column; | ||
| 26 | - width: 100%; | ||
| 27 | - height: 100%; | ||
| 28 | - justify-content: center; | ||
| 29 | - align-items: center; | ||
| 30 | - background-color: #535c68; | ||
| 31 | - opacity: 0.6; | ||
| 32 | -`; | ||
| 33 | - | ||
| 34 | -const FormContainer = styled.div` | ||
| 35 | - display: flex; | ||
| 36 | - position: fixed; | ||
| 37 | - background-color: #f5f6fa; | ||
| 38 | - min-height: 10rem; | ||
| 39 | - min-width: 20rem; | ||
| 40 | - border-radius: 10px; | ||
| 41 | -`; | ||
| 42 | - | ||
| 43 | -const Form = styled.form` | ||
| 44 | - display: flex; | ||
| 45 | - flex-direction: column; | ||
| 46 | - align-items: center; | ||
| 47 | - justify-content: center; | ||
| 48 | - width: 100%; | ||
| 49 | - padding: 15px; | ||
| 50 | - span { | ||
| 51 | - margin-bottom: 15px; | ||
| 52 | - } | ||
| 53 | - input { | ||
| 54 | - margin-bottom: 15px; | ||
| 55 | - } | ||
| 56 | - button { | ||
| 57 | - background-color: #1e3799; | ||
| 58 | - width: 30%; | ||
| 59 | - color: white; | ||
| 60 | - border-radius: 10px; | ||
| 61 | - font-family: "Ubuntu", sans-serif; | ||
| 62 | - } | ||
| 63 | -`; | ||
| 64 | - | ||
| 65 | -const FormText = styled.span` | ||
| 66 | - font-size: 15px; | ||
| 67 | - font-family: "Ubuntu", sans-serif; | ||
| 68 | -`; | ||
| 69 | - | ||
| 70 | -const RoomWrapper = styled.div` | ||
| 71 | - display: flex; | ||
| 72 | - flex-direction: column; | ||
| 73 | - justify-content: center; | ||
| 74 | - align-items: center; | ||
| 75 | - background-color: #a5b1c2; | ||
| 76 | - border-radius: 10px; | ||
| 77 | - box-shadow: 1px 1px 10px #8395a7; | ||
| 78 | - min-width: 23.75rem; | ||
| 79 | - width: auto; | ||
| 80 | - max-height: none; | ||
| 81 | - padding: 0.5rem 0.7rem 0 1rem; | ||
| 82 | -`; | ||
| 83 | - | ||
| 84 | -const RoomContainer = styled.div` | ||
| 85 | - display: flex; | ||
| 86 | - flex-direction: column; | ||
| 87 | - width: 100%; | ||
| 88 | - overflow-y: scroll; | ||
| 89 | - max-height: 85px; | ||
| 90 | - justify-content: center; | ||
| 91 | - align-items: center; | ||
| 92 | - &::-webkit-scrollbar { | ||
| 93 | - width: 10px; | ||
| 94 | - } | ||
| 95 | - &::-webkit-scrollbar-track { | ||
| 96 | - background-color: transparent; | ||
| 97 | - } | ||
| 98 | - &::-webkit-scrollbar-thumb { | ||
| 99 | - border-radius: 3px; | ||
| 100 | - background-color: gray; | ||
| 101 | - } | ||
| 102 | - &::-webkit-scrollbar-button { | ||
| 103 | - width: 0; | ||
| 104 | - height: 0; | ||
| 105 | - } | ||
| 106 | -`; | ||
| 107 | - | ||
| 108 | -const RoomUL = styled.ul` | ||
| 109 | - width: 100%; | ||
| 110 | - display: flex; | ||
| 111 | - flex-direction: column; | ||
| 112 | - justify-content: space-between; | ||
| 113 | - svg { | ||
| 114 | - color: white; | ||
| 115 | - opacity: 0.7; | ||
| 116 | - } | ||
| 117 | -`; | ||
| 118 | - | ||
| 119 | -const RoomItem = styled.li` | ||
| 120 | - font-family: "Ubuntu", sans-serif; | ||
| 121 | -`; | ||
| 122 | - | ||
| 123 | -const CreateContainer = styled.div` | ||
| 124 | - padding-top: 1.9rem; | ||
| 125 | - padding-bottom: 1.7rem; | ||
| 126 | - box-shadow: 0 -4px 4px rgba(0, 0, 0, 0.04); | ||
| 127 | -`; | ||
| 128 | - | ||
| 129 | -const StyledLink = styled(Link)` | ||
| 130 | - width: 100%; | ||
| 131 | - display: flex; | ||
| 132 | - flex-direction: row; | ||
| 133 | - justify-content: space-between; | ||
| 134 | - align-items: center; | ||
| 135 | - text-decoration: none; | ||
| 136 | - cursor: pointer; | ||
| 137 | - color: #079992; | ||
| 138 | - &:not(:last-child) { | ||
| 139 | - margin-bottom: 10px; | ||
| 140 | - } | ||
| 141 | - svg { | ||
| 142 | - color: #079992; | ||
| 143 | - &:hover { | ||
| 144 | - border-bottom: 1px solid #079992; | ||
| 145 | - } | ||
| 146 | - } | ||
| 147 | - li { | ||
| 148 | - color: black; | ||
| 149 | - &:hover { | ||
| 150 | - color: #079992; | ||
| 151 | - } | ||
| 152 | - } | ||
| 153 | - span { | ||
| 154 | - &:hover { | ||
| 155 | - border-bottom: 1px solid #079992; | ||
| 156 | - } | ||
| 157 | - } | ||
| 158 | -`; | ||
| 159 | - | ||
| 160 | -export default ({ action, setAction, onSubmit, roomName }) => { | ||
| 161 | - const { data } = useQuery(GET_ROOMS); | ||
| 162 | - | ||
| 163 | - let roomArray; | ||
| 164 | - if (data !== undefined) { | ||
| 165 | - const { getRooms } = data; | ||
| 166 | - roomArray = getRooms; | ||
| 167 | - } | ||
| 168 | - | ||
| 169 | - return ( | ||
| 170 | - <Wrapper> | ||
| 171 | - {action === "showList" ? ( | ||
| 172 | - <> | ||
| 173 | - <RoomWrapper> | ||
| 174 | - <RoomContainer> | ||
| 175 | - <RoomUL> | ||
| 176 | - {roomArray && | ||
| 177 | - roomArray.map((e) => ( | ||
| 178 | - <StyledLink to={e.name} key={e.id}> | ||
| 179 | - <RoomItem>{e.name}</RoomItem> | ||
| 180 | - <FontAwesomeIcon icon={faArrowRight} /> | ||
| 181 | - </StyledLink> | ||
| 182 | - ))} | ||
| 183 | - </RoomUL> | ||
| 184 | - </RoomContainer> | ||
| 185 | - <CreateContainer> | ||
| 186 | - <StyledLink to="/" onClick={() => setAction("makeList")}> | ||
| 187 | - <span>Create New Room</span> | ||
| 188 | - </StyledLink> | ||
| 189 | - </CreateContainer> | ||
| 190 | - </RoomWrapper> | ||
| 191 | - </> | ||
| 192 | - ) : ( | ||
| 193 | - <HideWrapper className="hideWrapper"> | ||
| 194 | - <FormContainer> | ||
| 195 | - <Form onSubmit={onSubmit}> | ||
| 196 | - <FormText>Room Name</FormText> | ||
| 197 | - <Input placeholder="Enter new Room name" {...roomName} /> | ||
| 198 | - <Button text="Submit" /> | ||
| 199 | - </Form> | ||
| 200 | - </FormContainer> | ||
| 201 | - </HideWrapper> | ||
| 202 | - )} | ||
| 203 | - </Wrapper> | ||
| 204 | - ); | ||
| 205 | -}; |
front/src/Routes/Room/RoomQueries.js
deleted
100644 → 0
-
Please register or login to post a comment