Skip to content

Commit

Permalink
Add reset from clicking at navbar title
Browse files Browse the repository at this point in the history
  • Loading branch information
albin-karlsson committed Mar 28, 2024
1 parent 8f50d5c commit 49b7b8c
Show file tree
Hide file tree
Showing 9 changed files with 117 additions and 58 deletions.
1 change: 1 addition & 0 deletions client/src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ h4 {
.link {
color: white;
text-decoration: none;
cursor: pointer;
}

.italic {
Expand Down
16 changes: 11 additions & 5 deletions client/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,17 @@ function App() {
setCurrentView(pages[nextIndex]);
}

function changeSettings(topic) {
// TODO: Restart discussion
setTopic(topic);
function reset(topic) {
setTopic(topic ?? "");
setFoods([]);
setIsActiveOverlay(true);
setCurrentView("foods");

if (!topic) {
setHumanName("");
setCurrentView("landing");
} else {
setCurrentView("foods");
}
}

return (
Expand All @@ -77,7 +83,7 @@ function App() {
humanName,
topic,
foods,
onChangeSettings: changeSettings,
onReset: reset,
}}
/>
)}
Expand Down
22 changes: 16 additions & 6 deletions client/src/components/Council.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import About from "./About";
import Topics from "./Topics";
import Contact from "./Contact";
import Share from "./Share";
import ResetWarning from "./ResetWarning";
import Navbar from "./Navbar";
import TextOutput from "./TextOutput";
import useWindowSize from "../hooks/useWindowSize";

function Council({ options }) {
Expand All @@ -24,6 +26,10 @@ function Council({ options }) {
alignItems: "center",
};

function displayResetWarning() {
setActiveOverlay("reset");
}

// Function to handle overlay content based on navbar clicks
const displayOverlay = (section) => {
setActiveOverlay(section); // Update state to control overlay content
Expand All @@ -42,14 +48,21 @@ function Council({ options }) {
return (
<Topics
currentTopic={options.topic}
onChangeSettings={options.onChangeSettings}
onReset={options.onReset}
onCancel={removeOverlay}
/>
);
case "contact":
return <Contact />;
case "share":
return <Share />;
case "reset":
return (
<ResetWarning
onReset={() => options.onReset()}
onCancel={removeOverlay}
/>
);
default:
return null; // No overlay content if no section is active
}
Expand All @@ -60,11 +73,7 @@ function Council({ options }) {
<div className="wrapper">
{activeOverlay === "" && (
<div className="text-container" style={{ justifyContent: "end" }}>
<h2>
Lorem ipsum dolor sit.
<br />
Lorem ipsum dolor sit amet.
</h2>
<TextOutput />
</div>
)}
<div style={foodsContainerStyle}>
Expand All @@ -86,6 +95,7 @@ function Council({ options }) {
activeOverlay={activeOverlay}
onDisplayOverlay={displayOverlay}
onRemoveOverlay={removeOverlay}
onDisplayResetWarning={displayResetWarning}
/>
</div>
</div>
Expand Down
16 changes: 14 additions & 2 deletions client/src/components/Navbar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ import { capitalizeFirstLetter } from "../utils";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { faXmark } from "@fortawesome/free-solid-svg-icons";

function Navbar({ topic, activeOverlay, onDisplayOverlay, onRemoveOverlay }) {
function Navbar({
topic,
activeOverlay,
onDisplayOverlay,
onRemoveOverlay,
onDisplayResetWarning,
}) {
const navbarStyle = {
paddingTop: "10px",
display: "flex",
Expand All @@ -26,7 +32,13 @@ function Navbar({ topic, activeOverlay, onDisplayOverlay, onRemoveOverlay }) {
<nav style={navbarStyle} role="navigation">
<div>
<h3 style={{ margin: "0", padding: "0" }}>
<a className="link" href="/">
<a
className="link"
onClick={(e) => {
e.preventDefault();
onDisplayResetWarning();
}}
>
COUNCIL OF FOODS
</a>
</h3>
Expand Down
35 changes: 35 additions & 0 deletions client/src/components/ResetWarning.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import React from "react";
import { capitalizeFirstLetter } from "../utils";

function ResetWarning({ message, onReset, onCancel }) {
return (
<div className="wrapper">
<div className="text-container" style={{ justifyContent: "center" }}>
<h4>
{message
? capitalizeFirstLetter(message)
: capitalizeFirstLetter("this")}{" "}
will restart the discussion
</h4>
<div>
<button
className="outline-button"
onClick={onReset}
style={{ marginRight: "9px" }}
>
I understand
</button>
<button
className="outline-button"
onClick={onCancel}
style={{ marginLeft: "9px" }}
>
Cancel
</button>
</div>
</div>
</div>
);
}

export default ResetWarning;
25 changes: 0 additions & 25 deletions client/src/components/SettingsWarning.jsx

This file was deleted.

19 changes: 19 additions & 0 deletions client/src/components/TextOutput.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import React from "react";

function TextOutput() {
const textOutputStyle = {
fontFamily: "Arial, sans-serif",
};

return (
<div>
<h2 style={textOutputStyle}>
Lorem ipsum dolor sit.
<br />
Lorem ipsum dolor sit amet.
</h2>
</div>
);
}

export default TextOutput;
35 changes: 16 additions & 19 deletions client/src/components/Topics.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useState, useRef, useEffect } from "react";
import SettingsWarning from "./SettingsWarning";
import ResetWarning from "./ResetWarning";
import { capitalizeFirstLetter } from "../utils";

function Topics(props) {
Expand Down Expand Up @@ -67,7 +67,7 @@ function Topics(props) {
// Function to proceed with the selected or custom topic
function onContinueForward() {
if (props.currentTopic) {
// TODO: Check if there is a current topic, in that case show the warning...
// Current topic exists which means we are changing settings
setDisplayWarning(true);
} else {
const topic = getTopic();
Expand All @@ -90,18 +90,16 @@ function Topics(props) {
!(selectedTopic.toLowerCase() === "choose your own" && !customTopic.trim());

return (
<div className="wrapper">
<div className="text-container">
{displayWarning ? (
<SettingsWarning
onChangeSettings={() => {
const topic = getTopic();
props.onChangeSettings(topic);
}}
onCancel={props.onCancel}
/>
) : (
<>
<>
{displayWarning ? (
<ResetWarning
message="changing settings"
onReset={() => props.onReset(getTopic())}
onCancel={props.onCancel}
/>
) : (
<div className="wrapper">
<div className="text-container">
<h1>THE ISSUE:</h1>
<div
style={{
Expand All @@ -128,7 +126,6 @@ function Topics(props) {
selectedTopic === "choose your own" ? "" : "hidden"
} text-input`}
rows="2"
cols="30"
value={customTopic}
placeholder="your topic"
onChange={handleInputTopic}
Expand All @@ -141,10 +138,10 @@ function Topics(props) {
>
Next
</button>
</>
)}
</div>
</div>
</div>
</div>
)}
</>
);
}

Expand Down
6 changes: 5 additions & 1 deletion client/src/utils.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
export function capitalizeFirstLetter(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
if (string && typeof string === "string") {
return string.charAt(0).toUpperCase() + string.slice(1);
}

return string || "";
}

0 comments on commit 49b7b8c

Please sign in to comment.