diff --git a/src/App.jsx b/src/App.jsx index c902699..86192c3 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -1,8 +1,9 @@ import { useState } from 'react' - import initialEmails from './data/emails' - import './styles/App.css' +import Emails from './Components/Emails' +import EmailView from './Components/EmailView' +import Header from './Components/Header' const getReadEmails = emails => emails.filter(email => !email.read) @@ -12,10 +13,22 @@ function App() { const [emails, setEmails] = useState(initialEmails) const [hideRead, setHideRead] = useState(false) const [currentTab, setCurrentTab] = useState('inbox') + const [openedEmail, setOpenedEmail] = useState(null) + const [searchTerm, setSearchTerm] = useState('') const unreadEmails = emails.filter(email => !email.read) const starredEmails = emails.filter(email => email.starred) + const openEmail = (email) => { + if (!email.read) { + setEmails(emails => + emails.map(e => + e.id === email.id ? { ...e, read: true } : e + ) + ) + } + setOpenedEmail(email) + } const toggleStar = targetEmail => { const updatedEmails = emails => emails.map(email => @@ -40,25 +53,14 @@ function App() { if (currentTab === 'starred') filteredEmails = getStarredEmails(filteredEmails) - + if (searchTerm) { + filteredEmails = filteredEmails.filter(email => + email.title.toLowerCase().includes(searchTerm.toLowerCase()) + ) + } return (
-
-
- - - - - gmail logo -
- -
- -
-
+
-
    - {filteredEmails.map((email, index) => ( -
  • -
    - toggleRead(email)} - /> -
    -
    - toggleStar(email)} - /> -
    -
    {email.sender}
    -
    {email.title}
    -
  • - ))} -
+ {openedEmail ? ( + setOpenedEmail(null)} /> + ) : ( + + )}
) diff --git a/src/Components/Email.jsx b/src/Components/Email.jsx new file mode 100644 index 0000000..1e7ba50 --- /dev/null +++ b/src/Components/Email.jsx @@ -0,0 +1,31 @@ + +function Email({ email, toggleRead, toggleStar, openEmail }) { + return ( +
  • openEmail(email)} + style={{ cursor: 'pointer' }} + > +
    + toggleRead(email)} + /> +
    +
    + toggleStar(email)} + /> +
    +
    {email.sender}
    +
    {email.title}
    +
  • + ) +} + +export default Email \ No newline at end of file diff --git a/src/Components/EmailView.jsx b/src/Components/EmailView.jsx new file mode 100644 index 0000000..c048cff --- /dev/null +++ b/src/Components/EmailView.jsx @@ -0,0 +1,14 @@ +import '../styles/EmailView.css' + +function EmailView({ email, onClose }) { + return ( +
    + +

    {email.title}

    +

    From: {email.sender}

    +

    {email.description}

    +
    + ) +} + +export default EmailView \ No newline at end of file diff --git a/src/Components/Emails.jsx b/src/Components/Emails.jsx new file mode 100644 index 0000000..882e612 --- /dev/null +++ b/src/Components/Emails.jsx @@ -0,0 +1,20 @@ + +import Email from './Email' + +function Emails({ emails, toggleRead, toggleStar, openEmail }) { + return ( + + ) +} + +export default Emails \ No newline at end of file diff --git a/src/Components/Header.jsx b/src/Components/Header.jsx new file mode 100644 index 0000000..c3a4ee9 --- /dev/null +++ b/src/Components/Header.jsx @@ -0,0 +1,25 @@ +function Header({ searchTerm, setSearchTerm }) { + return ( +
    +
    + + + + gmail logo +
    +
    + setSearchTerm(e.target.value)} + /> +
    +
    + ) +} + +export default Header \ No newline at end of file diff --git a/src/data/emails.js b/src/data/emails.js index 68fb1fc..ec3a7b8 100644 --- a/src/data/emails.js +++ b/src/data/emails.js @@ -3,6 +3,7 @@ export default [ id: 1, sender: `Zoom`, title: `Cloud Recording - Nicolas Marcora's Personal Meeting Room is now available`, + description: `Your cloud recording for Nicolas Marcora's Personal Meeting Room is now available. Click the link to view or download your recording.`, starred: false, read: true }, @@ -10,6 +11,7 @@ export default [ id: 2, sender: `Zoom`, title: `Sean Davison has joined your Personal Meeting Room`, + description: `Sean Davison has just joined your Zoom Personal Meeting Room. You can now start your meeting.`, starred: false, read: false }, @@ -17,6 +19,7 @@ export default [ id: 3, sender: `Notion`, title: `1 update in Boolean`, + description: `There is 1 new update in your Boolean workspace on Notion. Check it out to stay up to date.`, starred: true, read: true }, @@ -24,6 +27,7 @@ export default [ id: 4, sender: `The Calendly Team`, title: `Use more than one calendar?`, + description: `Calendly now supports connecting multiple calendars. Manage your events more efficiently by linking all your calendars.`, starred: false, read: false }, @@ -31,7 +35,8 @@ export default [ id: 5, sender: `Patrick`, title: `Updated invitation: Coding chat with Nico`, + description: `Patrick has updated the invitation for your coding chat with Nico. Please review the new details and confirm your attendance.`, starred: true, read: false } -] +] \ No newline at end of file diff --git a/src/styles/Emailview.css b/src/styles/Emailview.css new file mode 100644 index 0000000..c13a9b8 --- /dev/null +++ b/src/styles/Emailview.css @@ -0,0 +1,28 @@ +.email-view { + background: #fff; + border-radius: 8px; + box-shadow: 0 2px 8px #0001; + padding: 1.5rem 2rem; + max-width: 90%; + margin: 2rem auto; +} + +.email-view button { + background: #f5f5f5; + border: none; + border-radius: 4px; + padding: 0.4rem 1rem; + margin-bottom: 1rem; +} + +.email-view h4 { + margin: 0 0 1rem 0; + color: #555; + font-weight: 400; +} + +.email-view p { + font-size: 1rem; + color: #222; + line-height: 1.5; +} \ No newline at end of file