Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add join existing group section #11

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 deletions client/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
import React from "react";
import Logo from "./assets/flatini-logo.png";
import "./App.css";
import { Routes, Route } from "react-router-dom";
import { Landing } from "./Landing";
import styled from "styled-components";
import CreateGroup from "./CreateGroup";

const Header = styled.div``;

function App() {
return (
<>
<Header>
<img style={{ width: 110 }} src={Logo} />
</Header>
<Routes>
<Route path="/" element={<Landing />} />
<Route path="/CreateGroup" element={<CreateGroup />} />
</Routes>
<header>
<img style={{ width: 110 }} src={Logo} alt="flatini app" />
</header>
<main>
<Routes>
<Route path="/" element={<Landing />} />
<Route path="/CreateGroup" element={<CreateGroup />} />
</Routes>
</main>
</>
);
}
Expand Down
18 changes: 12 additions & 6 deletions client/src/Button.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import React, { MouseEventHandler } from "react";
import styled from "styled-components";

const Wrapper = styled.a`
const Wrapper = styled.a<{ $disabled?: boolean }>`
background-color: white;
color: #322848;
color: ${(props) => (props.$disabled ? "grey" : "#322848")};
padding: 20px;
border-radius: 10px;
font-size: 25px;
font-size: 20px;
width: 200px;
border: 0;
cursor: pointer;

cursor: ${(props) => (props.$disabled ? "not-allowed" : "pointer")};
&::-moz-focus-inner,
&::-moz-focus-inner {
border: 0;
Expand All @@ -21,11 +21,17 @@ type Props = {
onClick?: MouseEventHandler<HTMLAnchorElement> | undefined;
children?: React.ReactNode;
style?: React.CSSProperties | undefined;
$disabled?: boolean;
};

const Button = (props: Props) => {
return (
<Wrapper onClick={props.onClick} style={props.style} className="secondary">
<Wrapper
$disabled={props.$disabled}
onClick={props.onClick}
style={props.style}
className="secondary"
>
{props.children}
</Wrapper>
);
Expand Down
6 changes: 1 addition & 5 deletions client/src/CreateGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,7 @@ const CreateGroup = () => {
const [copiedToClipboard, setCopiedToClipboard] = useState(false);

function generateRandomId(): string {
let randomId = "";
for (let i = 0; i < 12; i++) {
randomId += Math.floor(Math.random() * 10).toString();
}
return randomId;
return Math.random().toString().substring(7); // still high collision chance, but good enough for now
}

return (
Expand Down
51 changes: 41 additions & 10 deletions client/src/Landing.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
import React, { useState } from "react";
import { SetStateAction, useState } from "react";
import styled from "styled-components";
import Button from "./Button";
import { Link } from "react-router-dom";
import { useNavigate } from "react-router-dom";

const Wrapper = styled.div`
position: fixed;
height: 100%;
width: 100%;
top: 0;
left: 0;
display: flex;
flex-direction: column;
gap: 10px;
`;

const Block = styled.div`
const Block = styled.div<{ $bgColor?: string; $gap?: string }>`
flex: 1;
display: flex;
flex-direction: column;
Expand All @@ -24,6 +23,21 @@ const Block = styled.div`
p {
max-width: 245px;
}
background-color: ${(props) => props.$bgColor || "transparent"};
gap: ${(props) => props.$gap || "10px"};
`;

const Input = styled.input<{ $topMargin?: string }>`
background-color: transparent;
border: 2px solid #ccc;
padding: 20px;
width: 200px;
border-radius: 10px;
margin-top: ${(props) => props.$topMargin || "0"};
&::placeholder {
text-align: center;
}
color: #ccc;
`;

enum ScreenTypes {
Expand All @@ -37,19 +51,36 @@ export const Landing = () => {
const [state, setState] = useState({
activeView: ScreenTypes.landing,
});
const navigate = useNavigate();
const handleOnClick = () => navigate("/CreateGroup");

const [inputValue, setInputValue] = useState("");

const handleInputChange = (e: {
target: { value: SetStateAction<string> };
}) => {
setInputValue(e.target.value);
};

return (
<Wrapper>
<Block>
<Block $gap="20px">
<p>
Create a group with your flatmates and start sharing links to find
your next flat.
</p>
<Link to="CreateGroup">
<Button style={{ marginTop: 30 }}>Create a new group</Button>
</Link>
<Button onClick={handleOnClick}>Create a new group</Button>
</Block>
<Block style={{ backgroundColor: "#322848" }}>
<Block $bgColor="#322848">
<p>Join an existing group one of your flatmates has already created</p>
<Input
$topMargin="10px"
type="text"
placeholder="Enter the group ID"
value={inputValue}
onChange={handleInputChange}
/>
<Button $disabled={inputValue === ""}>Join existing group</Button>
</Block>
</Wrapper>
);
Expand Down
Loading