diff --git a/src/plays/daily-journa/DailyJournal.jsx b/src/plays/daily-journa/DailyJournal.jsx new file mode 100644 index 0000000000..525440883a --- /dev/null +++ b/src/plays/daily-journa/DailyJournal.jsx @@ -0,0 +1,68 @@ +import PlayHeader from 'common/playlists/PlayHeader'; +import './styles.css'; +import { useState, useEffect } from 'react'; +import JournalEntryForm from './components/JournalEntryForm'; +import EntryList from './components/EntryList'; +import EntryDetails from './components/EntryDetails'; + +// WARNING: Do not change the entry componenet name +function DailyJournal(props) { + // Your Code Start below. + const [entries, setEntries] = useState([]); + const [selectedEntry, setSelectedEntry] = useState(null); + + useEffect(() => { + const savedEntries = JSON.parse(localStorage.getItem('entries')) || []; + setEntries(savedEntries); + }, []); + + useEffect(() => { + localStorage.setItem('entries', JSON.stringify(entries)); + }, [entries]); + + const addEntry = (entry) => { + setEntries([...entries, entry]); + }; + + const viewEntry = (entry) => setSelectedEntry(entry); + + const goBack = () => setSelectedEntry(null); + + const onDelete = () => setEntries([]); + + return ( + <> +
+ +
+ {/* Your Code Starts Here */} +
+
+

Daily Journal

+

+ Your daily companion that you can share your thoughts and feelings with.{' '} +

+
+
+ +
+
+ {selectedEntry ? ( + + ) : ( + <> + + + )} +
+
+
+
+ {/* Your Code Ends Here */} +
+
+ + ); +} + +export default DailyJournal; diff --git a/src/plays/daily-journa/Readme.md b/src/plays/daily-journa/Readme.md new file mode 100644 index 0000000000..a1bfca02bc --- /dev/null +++ b/src/plays/daily-journa/Readme.md @@ -0,0 +1,27 @@ +# Daily journal + +This play is about writing daily entries, categorising them by mood or topic, and reviewing past entries. + +## Play Demographic + +- Language: js +- Level: Beginner + +## Creator Information + +- User: GhadaRV +- Gihub Link: https://github.com/GhadaRV +- Blog: +- Video: + +## Implementation Details + +Update your implementation idea and details here + +## Consideration + +Update all considerations(if any) + +## Resources + +Update external resources(if any) diff --git a/src/plays/daily-journa/components/EntryDetails.jsx b/src/plays/daily-journa/components/EntryDetails.jsx new file mode 100644 index 0000000000..68945b77d8 --- /dev/null +++ b/src/plays/daily-journa/components/EntryDetails.jsx @@ -0,0 +1,24 @@ +import React from 'react'; + +const EntryDetails = ({ entry, onBack }) => ( +
+

{entry.date}

+

+ Mood: {entry.mood} +

+

{entry.text}

+ {entry.tags.length > 0 && ( +

+ Tags: {entry.tags.join(', ')} +

+ )} + +
+); + +export default EntryDetails; diff --git a/src/plays/daily-journa/components/EntryList.jsx b/src/plays/daily-journa/components/EntryList.jsx new file mode 100644 index 0000000000..e2fcf891ba --- /dev/null +++ b/src/plays/daily-journa/components/EntryList.jsx @@ -0,0 +1,33 @@ +import React from 'react'; + +const EntryList = ({ entries, onSelect, onDelete }) => ( +
+

Past Entries

+ {entries.length > 0 ? ( + + ) : null} + {entries.length === 0 ?

No entries found

: null} + +
+); + +export default EntryList; diff --git a/src/plays/daily-journa/components/JournalEntryForm.jsx b/src/plays/daily-journa/components/JournalEntryForm.jsx new file mode 100644 index 0000000000..5f13e02f14 --- /dev/null +++ b/src/plays/daily-journa/components/JournalEntryForm.jsx @@ -0,0 +1,56 @@ +import { useState } from 'react'; + +const JournalEntryForm = ({ onSubmit }) => { + const [text, setText] = useState(''); + const [mood, setMood] = useState('Happy'); + const [tags, setTags] = useState(''); + + const handleSubmit = (e) => { + e.preventDefault(); + const newEntry = { + id: Date.now(), + text, + mood, + tags: tags.split(' ').map((tag) => tag.trim()), + date: new Date().toLocaleDateString() + }; + onSubmit(newEntry); + setText(''); + setMood('Happy'); + setTags(''); + }; + + return ( +
+