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

Issue 65/add styling and button to modal #69

Merged
merged 3 commits into from
Nov 1, 2023
Merged
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
4 changes: 2 additions & 2 deletions src/app/components/Main.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import SearchBar from './SearchBar';
import Card from './Card';
import Modal from './Modal';
import WelcomeModal from './WelcomeModal';

export default function Main() {
return (
<div>
<Modal />
<WelcomeModal />
<br />
<SearchBar />
<div className="flex flex-wrap justify-center mb-12">
Expand Down
37 changes: 0 additions & 37 deletions src/app/components/Modal.js

This file was deleted.

66 changes: 66 additions & 0 deletions src/app/components/WelcomeModal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
'use client';
import React, { useEffect, useState } from 'react';

export default function WelcomeModal() {
const [modalDisplayed, setModalDisplayed] = useState(false);

useEffect(() => {
// Check if the modal has already been displayed
const hasModalBeenDisplayed = localStorage.getItem('modalDisplayed');

if (!hasModalBeenDisplayed) {
const modal = document.getElementById('my_modal_5');
if (modal) {
modal.showModal();
setModalDisplayed(true);

// Store in local storage to prevent further displays
// localStorage.setItem('modalDisplayed', 'true');
}
}
}, []);

const date = new Date();
const hours = date.getHours();
let timeOfDay;

if (hours >= 5 && hours < 12) {
timeOfDay = 'Good morning!';
} else if (hours >= 12 && hours < 17) {
timeOfDay = 'Good afternoon!';
} else if (hours >= 17 && hours < 20) {
timeOfDay = 'Good evening!';
} else {
timeOfDay = 'Time for a late night snack?';
}

return (
<>
<div className="flex justify-center m-4">
<button
className="btn"
onClick={() => document.getElementById('my_modal_5').showModal()}
>
Click to Test Modal
</button>
</div>
<dialog id="my_modal_5" className="modal modal-bottom sm:modal-middle">
<div className="modal-box rounded bg-white p-6 shadow-lg">
<h3 className="font-bold text-lg text-center">{timeOfDay}</h3>
<p className="py-4 text-center text-gray-700">
Welcome to our recipe hub! Type in an ingredient and discover a
universe of cooking possibilities at your fingertips.
</p>
<div className="modal-action">
<form method="dialog">
{/* if there is a button in form, it will close the modal */}
<button className="btn bg-blue-500 text-white py-2 px-4 rounded hover:bg-blue-600">
Let&apos;s Cook !
</button>
</form>
</div>
</div>
</dialog>
</>
);
}
Loading