From ebb22c3b5e1deb33eac1c94dd64dffddd46b5042 Mon Sep 17 00:00:00 2001 From: James Date: Fri, 12 Apr 2019 14:41:07 +0800 Subject: [PATCH] Add better subscriptions client for auto-reconnect --- .eslintrc.js | 3 +- .vscode/settings.json | 5 + package.json | 9 +- rollup.config.js | 16 +-- src/components/GroupSelect.svelte | 1 - src/components/dashboard/Dashboard.svelte | 53 +--------- src/components/sessions/EditSession.svelte | 2 +- src/components/sessions/Sessions.svelte | 13 +++ src/components/sessions/data.js | 55 ++++++---- src/components/sessions/queries.js | 50 +++++++++ src/data/timer.js | 8 ++ src/data/ws-client.js | 32 ++++++ src/data/ws-client2.js | 113 +++++++++++++++++++++ src/utils.js | 13 +++ 14 files changed, 292 insertions(+), 81 deletions(-) create mode 100644 src/data/ws-client2.js create mode 100644 src/utils.js diff --git a/.eslintrc.js b/.eslintrc.js index dcc5c85..2da5922 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -3,6 +3,7 @@ module.exports = { plugins: ['svelte3'], rules: { "unicorn/filename-case": 0, - "no-labels": 0 + "no-labels": 0, + "import/first": 0 } } diff --git a/.vscode/settings.json b/.vscode/settings.json index 7193140..7e16d03 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -2,6 +2,11 @@ "files.associations": { "*.svelte": "html" }, + "files.watcherExclude": { + "public/bundle": true + }, + "editor.formatOnType": true, + "javascript.format.insertSpaceBeforeFunctionParenthesis": true, "eslint.autoFixOnSave": true, "eslint.validate": [ "javascript", diff --git a/package.json b/package.json index f67cd12..8c5f6c7 100644 --- a/package.json +++ b/package.json @@ -4,8 +4,10 @@ "scripts": { "build": "npm run clean && rollup -c", "clean": "rm -rf public/bundle", - "dev": "rollup -c -w", - "start": "sirv public --single" + "start": "sirv public --single", + "autobuild": "rollup -c -w", + "dev": "run-p start:dev autobuild", + "start:dev": "sirv public --dev --single" }, "devDependencies": { "bulma": "^0.7.4", @@ -17,6 +19,7 @@ "eslint-plugin-svelte3": "^0.4.7", "eslint-plugin-unicorn": "^8.0.1", "node-sass": "^4.11.0", + "npm-run-all": "^4.1.5", "rollup": "^1.9.0", "rollup-plugin-commonjs": "^9.2.0", "rollup-plugin-commonjs-alternate": "0.0.5", @@ -34,7 +37,9 @@ "dependencies": { "@fortawesome/fontawesome-free": "^5.8.1", "date-fns": "^2.0.0-alpha.27", + "eslint-plugin-import": "^2.16.0", "flatpickr": "^4.5.7", + "graphql-subscriptions-client": "^0.10.0", "navaid": "^1.0.0" } } diff --git a/rollup.config.js b/rollup.config.js index b60e0dc..367460d 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -33,14 +33,14 @@ module.exports = [{ }), resolve(), commonjs(), - !production && serve({ - contentBase: 'public', - historyApiFallback: true, - port: 5050 - }), - !production && livereload({ - watch: 'public' - }), + // !production && serve({ + // contentBase: 'public', + // historyApiFallback: true, + // port: 5050 + // }), + // !production && livereload({ + // watch: 'public' + // }), notify(), // If we're building for production (npm run build diff --git a/src/components/GroupSelect.svelte b/src/components/GroupSelect.svelte index 36dea0a..ac5660d 100644 --- a/src/components/GroupSelect.svelte +++ b/src/components/GroupSelect.svelte @@ -16,7 +16,6 @@ } }) - $: console.log(groups) function checkValidity () { error = !selectElement.validity.valid && selectElement.validationMessage ? selectElement.validationMessage diff --git a/src/components/dashboard/Dashboard.svelte b/src/components/dashboard/Dashboard.svelte index 575de6f..0f8cff6 100644 --- a/src/components/dashboard/Dashboard.svelte +++ b/src/components/dashboard/Dashboard.svelte @@ -1,56 +1,7 @@ diff --git a/src/components/sessions/EditSession.svelte b/src/components/sessions/EditSession.svelte index e0788a1..5a03371 100644 --- a/src/components/sessions/EditSession.svelte +++ b/src/components/sessions/EditSession.svelte @@ -22,7 +22,7 @@ input.endsAt = new Date(input.endsAt).toISOString() loading = true try { - const updatedSession = await sessions.update(id, input, groupId) + const updatedSession = await sessions.patch(id, input, groupId) const date = formatRelative(new Date(input.startsAt), new Date(), { addSuffix: true }) notifications.add({ text: `Update session to ${date} with ${updatedSession.group.name} class`, type: 'success' }) reset() diff --git a/src/components/sessions/Sessions.svelte b/src/components/sessions/Sessions.svelte index 64d73e5..3deeef5 100644 --- a/src/components/sessions/Sessions.svelte +++ b/src/components/sessions/Sessions.svelte @@ -1,4 +1,5 @@