diff --git a/src/App.jsx b/src/App.jsx index c902699..bbc0506 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -1,41 +1,31 @@ import { useState } from 'react' import initialEmails from './data/emails' +import EmailList from './components/EmailListComponent' +import EmailView from './components/EmailViewComponent' import './styles/App.css' const getReadEmails = emails => emails.filter(email => !email.read) - const getStarredEmails = emails => emails.filter(email => email.starred) function App() { + const [emails, setEmails] = useState(initialEmails) const [hideRead, setHideRead] = useState(false) const [currentTab, setCurrentTab] = useState('inbox') + const [search, setSearch] = useState('') + const [openEmail, setOpenEmail] = useState(null); const unreadEmails = emails.filter(email => !email.read) const starredEmails = emails.filter(email => email.starred) + let filteredEmails = emails - const toggleStar = targetEmail => { - const updatedEmails = emails => - emails.map(email => - email.id === targetEmail.id - ? { ...email, starred: !email.starred } - : email - ) - setEmails(updatedEmails) - } - - const toggleRead = targetEmail => { - const updatedEmails = emails => - emails.map(email => - email.id === targetEmail.id ? { ...email, read: !email.read } : email - ) - setEmails(updatedEmails) + if(search != ""){ + filteredEmails = emails.filter( email => email.title.toLocaleLowerCase() + .includes(search.toLocaleLowerCase())) } - let filteredEmails = emails - if (hideRead) filteredEmails = getReadEmails(filteredEmails) if (currentTab === 'starred') @@ -43,6 +33,8 @@ function App() { return (
+ + {/* Header */}
@@ -56,9 +48,11 @@ function App() {
- + setSearch(e.target.value)} value={search}/>
+ + {/* Menu */} -
- -
+ + {/* Email list */} + {openEmail == null ?() + + :( setOpenEmail(null)} >)} +
) } diff --git a/src/components/EmailComponent.jsx b/src/components/EmailComponent.jsx new file mode 100644 index 0000000..4743702 --- /dev/null +++ b/src/components/EmailComponent.jsx @@ -0,0 +1,40 @@ +function EmailItem(props){ + + let email = props.email ; + let index = props.index; + + return ( +
  • props.setOpenEmail(email)} + > +
    { + e.stopPropagation(); + props.toggleRead(email); + }}> + +
    +
    { + e.stopPropagation(); + props.toggleStar(email); + }}> + +
    +
    {email.sender}
    +
    {email.title}
    +
  • + ); +} + +export default EmailItem; \ No newline at end of file diff --git a/src/components/EmailListComponent.jsx b/src/components/EmailListComponent.jsx new file mode 100644 index 0000000..5fba7a4 --- /dev/null +++ b/src/components/EmailListComponent.jsx @@ -0,0 +1,40 @@ +import EmailItem from "./EmailComponent"; + +function EmailList(props){ + const filteredEmails = props.filteredEmails; + const setEmails = props.setEmails; + + function toggleStar(targetEmail) { + setEmails(currentEmails => { + return currentEmails.map(email => { + if (email.id === targetEmail.id) { + return { ...email, starred: !email.starred }; + } + return email; + }); + }); + } + + function toggleRead(targetEmail) { + setEmails(currentEmails => { + return currentEmails.map(email => { + if (email.id === targetEmail.id) { + return { ...email, read: !email.read }; + } + return email; + }); + }); + } + + return ( +
    + +
    + ); +} + +export default EmailList; \ No newline at end of file diff --git a/src/components/EmailViewComponent.jsx b/src/components/EmailViewComponent.jsx new file mode 100644 index 0000000..5219116 --- /dev/null +++ b/src/components/EmailViewComponent.jsx @@ -0,0 +1,25 @@ +function EmailView(props) +{ + return ( +
    +
    +
    +

    {props.openEmail.title}

    +
    +
    +
    +
    +

    {props.openEmail.sender}

    +
    +
    +
    +
    +
    +
    + +
    +
    +
    + ) +} +export default EmailView; \ No newline at end of file