Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Dropbox integration #1

Draft
wants to merge 46 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
17fd4ac
Add NextCloud server setting
j-maas Apr 11, 2020
4c559ca
Persist all settings
j-maas Apr 11, 2020
6545f2f
Add basic auth (fails due to CORS)
j-maas Apr 11, 2020
d8e5141
Add basic Dropbox auth
j-maas Apr 11, 2020
18c9352
Refactor port interface
j-maas Apr 12, 2020
bd99b73
Reintroduce long language names in picker
j-maas Apr 12, 2020
9e07644
Persist login and secure with nonce
j-maas Apr 12, 2020
ed5351c
Pull recipes from Dropbox
j-maas Apr 16, 2020
1577dad
Store revisions
j-maas Apr 16, 2020
c31fe33
Add rough sync
j-maas Apr 16, 2020
90af815
Use fork of elm-dropbox
j-maas Apr 18, 2020
342bbd7
Delete recipes from Dropbox
j-maas Apr 18, 2020
bc8727d
Use file names as ids
j-maas Apr 20, 2020
691b689
Extract DropboxSync module
j-maas Apr 20, 2020
b0243b0
Checkout submodules on CI
j-maas Apr 22, 2020
d788b62
Explain init of submodules in README
j-maas Apr 25, 2020
ee7941e
Format package.json
j-maas Apr 25, 2020
3f37b9d
Add logout from Dropbox
j-maas Apr 25, 2020
f5c2912
Add todo
j-maas Apr 26, 2020
2667538
Extract Dropbox Msg into module
j-maas Apr 26, 2020
9e275b4
Add debug npm script
j-maas Apr 26, 2020
3cd873f
Update dependencies
j-maas Jul 23, 2020
952085d
Add Store modules, move FileName to PathComponent
j-maas Jul 23, 2020
6b929cf
Fuzz Store.PathComponent tests
j-maas Jul 23, 2020
f0e35b4
Add type annotations to helper functions
j-maas Jul 23, 2020
74a1ca3
Rename PathComponent functions, add and refactor tests
j-maas Jul 24, 2020
59dfb78
Disallow empty PathComponents
j-maas Jul 24, 2020
d71b004
Add conversions for Path from and to String
j-maas Jul 24, 2020
b66f7d9
Extract FolderPath, refactor
j-maas Jul 24, 2020
ac4e6ae
Implement file-oriented Store
j-maas Jul 25, 2020
9d6032b
Add Store.list
j-maas Jul 25, 2020
f174ca9
Fold FilePath's extension into its name
j-maas Jul 25, 2020
b4bfe86
Add Store.update
j-maas Jul 25, 2020
7c71d3e
Use Store in Main, remove use of DropboxSync
j-maas Jul 26, 2020
b390fc5
Add SyncedStore with insert and read
j-maas Jul 26, 2020
8807c03
Add Store.subfolders
j-maas Jul 26, 2020
e6d82ca
Merge branch 'master' into dropbox
j-maas Jul 26, 2020
06f5ec0
Add SyncedStore update
j-maas Jul 31, 2020
3719d8e
Add listAll and start implementing sync
j-maas Jul 31, 2020
2b43048
Attempt sync
j-maas Aug 2, 2020
af7b965
Add sync
j-maas Aug 2, 2020
9e7eede
Add VersionStore
j-maas Aug 2, 2020
d38f1ba
Fix sync, autorename with dash
j-maas Aug 2, 2020
2acdcdb
Update dependencies
j-maas Sep 12, 2020
dd9e030
Allow remote to send messages
j-maas Dec 26, 2020
8f2fb2e
Update dependencies
j-maas Dec 26, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ jobs:

steps:
- uses: actions/checkout@v2
with:
submodules: true
- name: Use Node.js LTS
uses: actions/setup-node@v1
with:
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ jobs:
steps:
- name: Checkout 🛎️
uses: actions/checkout@v2
with:
persist-credentials: false
submodules: true

- name: Install and Build
run: |
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "submodules/elm-dropbox"]
path = submodules/elm-dropbox
url = https://github.com/Y0hy0h/elm-dropbox.git
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# Recipe Box

## Getting started
1. `npm install` to install dependencies.
2. `npm run watch` to start a server that makes the app available at http://localhost:8000.
1. Ensure that the [Git submodules](https://git-scm.com/book/en/v2/Git-Tools-Submodules) are initialized: `git submodule update --init`
2. `npm install` to install dependencies.
3. `npm run watch` to start a server that makes the app available at http://localhost:8000.

Tests can be run with `npm run test`.

Expand Down Expand Up @@ -35,16 +36,18 @@ To build everything, run `npm run build` and deploy the `dist` folder.
- [ ] Add indicator to top of files that explains how to view the recipes for people who do not know what to do with the files.
- [ ] Add WebDav integration (for NextCloud).
- [ ] Add DropBox integration.
- [ ] Show name of account when logged in.
- Overview
- [ ] Filter recipes.
- [ ] Search by ingredient.
- [ ] For duplicated titles, show file name as additional info.
- Recipe
- [x] Indicate how many ingredients there are in ingredient heading.
- [x] Show quantities in method. This is helpful when assembling ingredients while cooking.
- [ ] Highlight occurrences of ingredients on hover.
- [ ] Prevent display from turning off while cooking. (Wake Lock API (in draft) is only reasonable implementation.)
- [x] Workaround: Allow playing a soothing YouTube video in a loop.
- [ ] Offer customization of what video to play.
- [x] Offer customization of what video to play.
- [ ] Allow setting portions.
- [ ] Embed timers.
- [ ] Instead of brute deletion, have a bin to protect against accidental deletion.
Expand All @@ -60,6 +63,8 @@ To build everything, run `npm run build` and deploy the `dist` folder.
- [ ] Prevent multiple repetitions of context explanations. (E.g., when a quantity is empty, there is a problem for an expected float and an expected text that are listed separately.)
- [ ] Highlight errors in textarea. (See https://codersblock.com/blog/highlight-text-inside-a-textarea/)
- [ ] Allow named sections representing steps that have individual ingredient lists for preparation.
- Settings
- [ ] Offer reset to default value.
- [ ] Make it work offline. (Using a service worker.)
- [x] Increase font size slightly.
- [ ] Fix highlight on real button differing from link button.
Expand Down
56 changes: 42 additions & 14 deletions dist/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,28 @@
<body>
<div id="elm"></div>
<script>
var recipes = [];
var recipeChecks = [];
var recipesDict = {};
var recipePrefix = "recipe:"
var checksPrefix = "recipeChecks:"
function push(fileName, key, item) {
recipesDict[fileName] = recipesDict[fileName] || { code: null, checks: [] };
recipesDict[fileName][key] = item;
}
for (var i = 0; i < localStorage.length; i++) {
var key = localStorage.key(i);
if (key.startsWith(recipePrefix)) {
recipes.push(localStorage.getItem(key));
var fileName = key.slice(recipePrefix.length);
var entry = JSON.parse(localStorage.getItem(key));
push(fileName, "fileName", fileName)
push(fileName, "code", entry.code);
push(fileName, "revision", entry.revision);
} else if (key.startsWith(checksPrefix)) {
var title = key.slice(checksPrefix.length);
recipeChecks.push([title, JSON.parse(localStorage.getItem(key))]);
var fileName = key.slice(checksPrefix.length);
push(fileName, "checks", JSON.parse(localStorage.getItem(key)));
}
}
var recipes = Object.values(recipesDict);
console.info("Loaded " + recipes.length + " recipes.");
console.info("Loaded check marks for " + recipeChecks.length + " recipes.");

var shoppingListKey = "shoppingList";
function getShoppingList() {
Expand Down Expand Up @@ -61,25 +68,29 @@
}

var settingsKey = "settings";
var settings = JSON.parse(localStorage.getItem(settingsKey)) || {
wakeVideoId: null
};
var settings = JSON.parse(localStorage.getItem(settingsKey));
console.info("Loaded settings:", settings);

var nonceKey = "nonce";
var nonce = localStorage.getItem(nonceKey);
if (nonce) {
console.info("Loaded nonce.");
}

var app = Elm.Main.init({
node: document.getElementById('elm'),
flags: {
recipes,
recipeChecks,
shoppingList,
language,
settings,
nonce,
}
});

function saveRecipe(title, code) {
console.info("Saving recipe with title '" + title + "'.")
localStorage.setItem(recipeKeyFromTitle(title), code);
function saveRecipe(title, code, revision) {
console.info("Saving recipe with title '" + title + "' and revision '" + revision + "'.")
localStorage.setItem(recipeKeyFromTitle(title), JSON.stringify({ code, revision }));
}

function removeRecipe(title) {
Expand Down Expand Up @@ -115,8 +126,22 @@
localStorage.setItem(settingsKey, JSON.stringify(settings));
}

function generateNonce() {
var characterset = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_-";
var random = crypto.getRandomValues(new Uint8Array(64));
var nonce = "";
random.forEach(number => {
index = number % characterset.length;
nonce += characterset[index];
});
localStorage.setItem(nonceKey, nonce);

console.info("Generated and stored nonce.");
app.ports.nonceGenerated.send(nonce);
}

app.ports.saveRecipe.subscribe(function (data) {
saveRecipe(data.title, data.code);
saveRecipe(data.title, data.code, data.revision);
});
app.ports.removeRecipe.subscribe(function (title) {
removeRecipe(title);
Expand All @@ -133,6 +158,9 @@
app.ports.saveSettings.subscribe(function (settings) {
saveSettings(settings);
})
app.ports.generateNonce.subscribe(function () {
generateNonce();
});
</script>
</body>

Expand Down
28 changes: 18 additions & 10 deletions elm.json
Original file line number Diff line number Diff line change
@@ -1,35 +1,43 @@
{
"type": "application",
"source-directories": [
"src"
"src",
"submodules/elm-dropbox/src"
],
"elm-version": "0.19.1",
"dependencies": {
"direct": {
"Chadtech/elm-relational-database": "1.2.2",
"NoRedInk/elm-json-decode-pipeline": "1.0.0",
"elm/browser": "1.0.2",
"elm/core": "1.0.5",
"elm/html": "1.0.0",
"elm/http": "2.0.0",
"elm/json": "1.1.3",
"elm/parser": "1.1.0",
"elm/regex": "1.0.0",
"elm/time": "1.0.0",
"elm/url": "1.0.0",
"elm-community/list-extra": "8.2.3",
"rtfeldman/elm-css": "16.0.1",
"elm-community/json-extra": "4.3.0",
"elm-community/list-extra": "8.2.4",
"elm-community/string-extra": "4.0.1",
"rtfeldman/elm-css": "16.1.0",
"rtfeldman/elm-iso8601-date-strings": "1.1.3",
"tricycle/elm-embed-youtube": "1.1.2"
},
"indirect": {
"Skinney/murmur3": "2.0.8",
"elm/regex": "1.0.0",
"elm/time": "1.0.0",
"elm/bytes": "1.0.8",
"elm/file": "1.0.5",
"elm/random": "1.0.0",
"elm/virtual-dom": "1.0.2",
"krisajenkins/remotedata": "6.0.1",
"rtfeldman/elm-hex": "1.0.0"
}
},
"test-dependencies": {
"direct": {
"elm-explorations/test": "1.2.2"
},
"indirect": {
"elm/random": "1.0.0"
}
"indirect": {}
}
}
}
35 changes: 26 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
},
"devDependencies": {
"elm-live": "^4.0.2",
"terser": "^4.6.10"
"terser": "^5.3.1"
},
"scripts": {
"test": "elm-test",
"build": "elm make src/Main.elm --output dist/elm.min.js --optimize && terser dist/elm.min.js --output dist/elm.min.js --compress pure_funcs=[F2,F3,F4,F5,F6,F7,F8,F9,A2,A3,A4,A5,A6,A7,A8,A9],pure_getters,keep_fargs=false,unsafe_comps,unsafe --mangle",
"watch": "elm-live src/Main.elm --dir ./dist --start-page index.html -- --output dist/elm.min.js"
}
}
}
Loading