Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisnajman committed May 23, 2024
0 parents commit 60783e3
Show file tree
Hide file tree
Showing 26 changed files with 2,841 additions and 0 deletions.
51 changes: 51 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Deploy

on:
push:
branches:
- main

jobs:
build:
name: Build
runs-on: ubuntu-latest

steps:
- name: Checkout repo
uses: actions/checkout@v4 # Ensure this is v4 to support Node.js 20

- name: Setup Node
uses: actions/setup-node@v4 # v4 is correct for Node.js 20
with:
node-version: 20

- name: Install dependencies
run: npm install

- name: Build project
run: npm run build

- name: Upload production-ready build files
uses: actions/upload-artifact@v4 # Ensure this is v4
with:
name: production-files
path: ./dist # Reverted to ./dist

deploy:
name: Deploy
needs: build
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'

steps:
- name: Download artifact
uses: actions/download-artifact@v4 # Ensure this is v4
with:
name: production-files
path: ./dist # Reverted to ./dist

- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v4 # Ensure this is v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./dist # Reverted to ./dist
28 changes: 28 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# 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?

# mine
ref/
*copy*
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Christopher. Najman

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
83 changes: 83 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# Markdown Notes App (Local Storage)

This is the result of the Scrimba Tutorial [Notes App](https://v2.scrimba.com/learn-react-c0e), specifically, the first half (excluding the setting up of _Firebase / Firestore_).

Much of the code was pre-written. The task was to add functionality to an existing codebase.

## Functionality to Add

1. Sync notes with `localStorage`.
2. Create note titles from a summary of the note.
3. Move modified notes to the top of the list.
4. Delete notes.

---

## React Version

> [!IMPORTANT] > `react-mde` (the markdown editor) has not been updated for _React V.18_, so I had to use _V.17_.
---

## Accessibility

In the markdown editor, you can't tab through the toolbar buttons (apart from 'Write' and 'Preview').
This is because `tabindex="-1"` is placed on these buttons, removing them from the tab order.

_ChatGPT_ supplied a solution, which was to give ALL the buttons (including 'Write' and 'Preview') a `tabindex` of zero:

```jsx

function Editor({ currentNote, updateNote }) {

...

useEffect(() => {
// Function to update tabindex of toolbar buttons
const updateTabindex = () => {
const toolbarButtons = document.querySelectorAll(".mde-header button")
toolbarButtons.forEach((button) => {
button.setAttribute("tabindex", "0")
})
}

// Call the function initially after the component mounts
updateTabindex()

// Optional: observe changes to ensure tabindex stays updated
const observer = new MutationObserver(updateTabindex)
const toolbar = document.querySelector(".mde-header")

if (toolbar) {
observer.observe(toolbar, { childList: true, subtree: true })
}

// Cleanup the observer on component unmount
return () => {
observer.disconnect()
}
}, []) // Empty dependency array to run only once on mount

...
}
```

On reflection, however, I have decided **not** to include the code. This is because:

- In order to format the text, you first have to manually select it.
- Then you have to click a formatting button.
- But, if you reverse tab from the selected text to a toolbar button, the text selection disappears, so there is nothing for the button to format.

**Conclusion**: the toolbar formatting buttons are inherently inaccessible to keyboard navigation. (But you can still write and preview markdown code.)

---

## Testing

Tested on Windows 10 with:

- Chrome
- Firefox
- Microsoft Edge

Page tested in both browser and device views.
33 changes: 33 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<html>

<head>
<meta charset="UTF-8" />
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png">
<link rel="manifest" href="/site.webmanifest">
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Markdown Notes App (Local Storage)</title>
<link rel="stylesheet" href="style.css">
<script type="text/javascript">
(function (l) {
if (l.search[1] === "/") {
var decoded = l.search
.slice(1)
.split("&")
.map(function (s) {
return s.replace(/~and~/g, "&");
})
.join("?");
window.history.replaceState(null, null, l.pathname.slice(0, -1) + decoded + l.hash);
}
})(window.location);
</script>
</head>

<body>
<div id="root"></div>
<script src="/src/main.jsx" type="module"></script>
</body>

</html>
Loading

0 comments on commit 60783e3

Please sign in to comment.