diff --git a/src/App.jsx b/src/App.jsx index c902699..ff82bb9 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -12,6 +12,8 @@ function App() { const [emails, setEmails] = useState(initialEmails) const [hideRead, setHideRead] = useState(false) const [currentTab, setCurrentTab] = useState('inbox') + const [currentEmail, setCurrentEmail] = useState(null) + const [searchReq, setSearchReq] = useState(null) const unreadEmails = emails.filter(email => !email.read) const starredEmails = emails.filter(email => email.starred) @@ -34,6 +36,11 @@ function App() { setEmails(updatedEmails) } + const openMail = mail => { + setCurrentEmail(mail); + toggleRead(mail); + } + let filteredEmails = emails if (hideRead) filteredEmails = getReadEmails(filteredEmails) @@ -41,6 +48,57 @@ function App() { if (currentTab === 'starred') filteredEmails = getStarredEmails(filteredEmails) + + if (typeof(searchReq) =="string" && searchReq.trim() !== "") { + filteredEmails = filteredEmails.filter(email => + email.title.toLowerCase().includes(searchReq.toLowerCase()) + ); + } + + const OneEmail = ({email}) => { + return (
+ +

{email.title}

+
{email.sender}
+
) + } + + const Email = ({email, index}) => { + return (
  • +
    + toggleRead(email)} + /> +
    +
    + toggleStar(email)} + /> +
    +
    { setCurrentEmail(email)}} >{email.sender}
    +
    { openMail(email)}} >{email.title}
    +
  • ) + } + + const Emails = ({emailsList}) => { + return (
    + +
    ) + } + return (
    @@ -56,7 +114,7 @@ function App() {
    - + setSearchReq(e.target.value)} />
    -
    - -
    + {currentEmail == null ? () :( ) } ) }