Skip to content

Commit

Permalink
pushing from wsl
Browse files Browse the repository at this point in the history
  • Loading branch information
MellowPhi committed Feb 17, 2024
1 parent 395d704 commit 94e1dcb
Show file tree
Hide file tree
Showing 12 changed files with 2,970 additions and 2,969 deletions.
48 changes: 24 additions & 24 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
255 changes: 128 additions & 127 deletions App.jsx
Original file line number Diff line number Diff line change
@@ -1,127 +1,128 @@
import React from "react"
import Sidebar from "./components/Sidebar"
import Editor from "./components/Editor"
import Split from "react-split"
import { addDoc, onSnapshot, doc, deleteDoc, setDoc } from "firebase/firestore"
import { notesCollection, db } from './firebase'

export default function App() {
// Setting up the state
const [notes, setNotes] = React.useState([])
const [currentNoteId, setCurrentNoteId] = React.useState("")
const [tempNoteText, setTempNoteText] = React.useState("")

const sortedNotes = notes.slice();
sortedNotes.sort((a, b) => b.updatedAt - a.updatedAt);

console.log(currentNoteId)
// yesy sdfdhfk test

const currentNote =
notes.find(note => note.id === currentNoteId)
|| notes[0]



React.useEffect(() => {
const unsubscribe = onSnapshot(notesCollection, function(snapshot) {
// Sync up our local notes array with the snapshot data
console.log("this are changing!")
const notesArr = snapshot.docs.map(doc => ({
...doc.data(),
id: doc.id
}))

setNotes(notesArr)
})
return unsubscribe
}, [])

// If notes array changes, check if there is no currentId
React.useEffect(() => {
if (!currentNoteId) {
setCurrentNoteId(notes[0]?.id)
}
}, [notes])

React.useEffect(() => {
if (currentNote) {
setTempNoteText(currentNote.body)
}
}, [currentNote])


React.useEffect(() => {
const timeoutId = setTimeout(() => {
updateNote(tempNoteText)
}, 500)
return () => clearTimeout(timeoutId)
}, [tempNoteText])


async function createNewNote() {
const newNote = {
body: "# Type your markdown note's title here",
createdAt: Date.now(),
updatedAt: Date.now()
}
// Pushing the notes to firestore
// addDoc returns promise
const newNoteRef = await addDoc(notesCollection, newNote)
// setNotes(prevNotes => [newNote, ...prevNotes])
setCurrentNoteId(newNoteRef.id)
}

async function updateNote(text) {
const docRef = doc(db, "notes", currentNoteId)
await setDoc(docRef,
{ body: text, updatedAt: Date.now() },
{ merge: true}
)
}

async function deleteNote(noteId) {
// Get a ref for the doc to be deleted
const docRef = doc(db, "notes", noteId)
await deleteDoc(docRef)
}

return (
<main>
{
notes.length > 0
?
<Split
sizes={[30, 70]}
direction="horizontal"
className="split"
>
<Sidebar
notes={sortedNotes}
currentNote={currentNote}
setCurrentNoteId={setCurrentNoteId}
newNote={createNewNote}
deleteNote={deleteNote}
/>
{
<Editor
tempNoteText={tempNoteText}
setTempNoteText={setTempNoteText}
/>
}
</Split>
:
<div className="no-notes">
<h1>You have no notes</h1>
<button
className="first-note"
onClick={createNewNote}
>
Create one now
</button>
</div>

}
</main>
)
}
import React from "react"
import Sidebar from "./components/Sidebar"
import Editor from "./components/Editor"
import Split from "react-split"
import { addDoc, onSnapshot, doc, deleteDoc, setDoc } from "firebase/firestore"
import { notesCollection, db } from './firebase'

export default function App() {
// Setting up the state
const [notes, setNotes] = React.useState([])
const [currentNoteId, setCurrentNoteId] = React.useState("")
const [tempNoteText, setTempNoteText] = React.useState("")

const sortedNotes = notes.slice();
sortedNotes.sort((a, b) => b.updatedAt - a.updatedAt);

console.log(currentNoteId)
// yesy sdfdhfk test
// Comment from WSL

const currentNote =
notes.find(note => note.id === currentNoteId)
|| notes[0]



React.useEffect(() => {
const unsubscribe = onSnapshot(notesCollection, function(snapshot) {
// Sync up our local notes array with the snapshot data
console.log("this are changing!")
const notesArr = snapshot.docs.map(doc => ({
...doc.data(),
id: doc.id
}))

setNotes(notesArr)
})
return unsubscribe
}, [])

// If notes array changes, check if there is no currentId
React.useEffect(() => {
if (!currentNoteId) {
setCurrentNoteId(notes[0]?.id)
}
}, [notes])

React.useEffect(() => {
if (currentNote) {
setTempNoteText(currentNote.body)
}
}, [currentNote])


React.useEffect(() => {
const timeoutId = setTimeout(() => {
updateNote(tempNoteText)
}, 500)
return () => clearTimeout(timeoutId)
}, [tempNoteText])


async function createNewNote() {
const newNote = {
body: "# Type your markdown note's title here",
createdAt: Date.now(),
updatedAt: Date.now()
}
// Pushing the notes to firestore
// addDoc returns promise
const newNoteRef = await addDoc(notesCollection, newNote)
// setNotes(prevNotes => [newNote, ...prevNotes])
setCurrentNoteId(newNoteRef.id)
}

async function updateNote(text) {
const docRef = doc(db, "notes", currentNoteId)
await setDoc(docRef,
{ body: text, updatedAt: Date.now() },
{ merge: true}
)
}

async function deleteNote(noteId) {
// Get a ref for the doc to be deleted
const docRef = doc(db, "notes", noteId)
await deleteDoc(docRef)
}

return (
<main>
{
notes.length > 0
?
<Split
sizes={[30, 70]}
direction="horizontal"
className="split"
>
<Sidebar
notes={sortedNotes}
currentNote={currentNote}
setCurrentNoteId={setCurrentNoteId}
newNote={createNewNote}
deleteNote={deleteNote}
/>
{
<Editor
tempNoteText={tempNoteText}
setTempNoteText={setTempNoteText}
/>
}
</Split>
:
<div className="no-notes">
<h1>You have no notes</h1>
<button
className="first-note"
onClick={createNewNote}
>
Create one now
</button>
</div>

}
</main>
)
}
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Quick start:

```
$ npm install
$ npm run dev
```
Quick start:

```
$ npm install
$ npm run dev
```
60 changes: 30 additions & 30 deletions components/Editor.jsx
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
import React from "react";
import ReactMde from "react-mde";
import Showdown from "showdown";

export default function Editor({ tempNoteText, setTempNoteText }) {
const [selectedTab, setSelectedTab] = React.useState("write");

const converter = new Showdown.Converter({
tables: true,
simplifiedAutoLink: true,
strikethrough: true,
tasklists: true,
});

return (
<section className="pane editor">
<ReactMde
value={tempNoteText}
onChange={setTempNoteText}
selectedTab={selectedTab}
onTabChange={setSelectedTab}
generateMarkdownPreview={(markdown) =>
Promise.resolve(converter.makeHtml(markdown))
}
minEditorHeight={80}
heightUnits="vh"
/>
</section>
);
}
import React from "react";
import ReactMde from "react-mde";
import Showdown from "showdown";

export default function Editor({ tempNoteText, setTempNoteText }) {
const [selectedTab, setSelectedTab] = React.useState("write");

const converter = new Showdown.Converter({
tables: true,
simplifiedAutoLink: true,
strikethrough: true,
tasklists: true,
});

return (
<section className="pane editor">
<ReactMde
value={tempNoteText}
onChange={setTempNoteText}
selectedTab={selectedTab}
onTabChange={setSelectedTab}
generateMarkdownPreview={(markdown) =>
Promise.resolve(converter.makeHtml(markdown))
}
minEditorHeight={80}
heightUnits="vh"
/>
</section>
);
}
Loading

0 comments on commit 94e1dcb

Please sign in to comment.