diff --git a/src/App.jsx b/src/App.jsx index c902699..f33b3e0 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -1,8 +1,10 @@ -import { useState } from 'react' +import { useState } from 'react'; -import initialEmails from './data/emails' +import initialEmails from './data/emails'; -import './styles/App.css' +import './styles/App.css'; + +import EmailsFunction from './Components/EmailsFunction'; const getReadEmails = emails => emails.filter(email => !email.read) @@ -34,12 +36,22 @@ function App() { setEmails(updatedEmails) } + let filteredEmails = emails - + if (hideRead) filteredEmails = getReadEmails(filteredEmails) - - if (currentTab === 'starred') - filteredEmails = getStarredEmails(filteredEmails) + + if (currentTab === 'starred') + filteredEmails = getStarredEmails(filteredEmails) + + const handleSearch = event => { + const query = event.target.value.toLowerCase(); + const filtered = initialEmails.filter(email => + email.title.toLowerCase().includes(query.toLowerCase())); + setEmails(filtered); + filteredEmails = filtered; + } + return (
@@ -56,7 +68,7 @@ function App() {
- +
- +
) diff --git a/src/Components/EmailFunction.jsx b/src/Components/EmailFunction.jsx new file mode 100644 index 0000000..281d26e --- /dev/null +++ b/src/Components/EmailFunction.jsx @@ -0,0 +1,32 @@ + + +function EmailFunction({ email, key, toggleRead, toggleStar}) { + return ( + <> +
  • +
    + toggleRead(email)} + /> +
    +
    + toggleStar(email)} + /> +
    +
    {email.sender}
    +
    {email.title}
    +
  • + + ); +} + +export default EmailFunction; diff --git a/src/Components/EmailsFunction.jsx b/src/Components/EmailsFunction.jsx new file mode 100644 index 0000000..70b427b --- /dev/null +++ b/src/Components/EmailsFunction.jsx @@ -0,0 +1,16 @@ + +import EmailFunction from './EmailFunction'; + +function EmailsFunction({ filteredEmails, toggleRead, toggleStar}) { + return ( + <> + + + ); +} + +export default EmailsFunction; \ No newline at end of file