From c7943d3b1d6866ac271bcb12ed201c1eb1b6c6cb Mon Sep 17 00:00:00 2001 From: Ethan Davidson <31261035+EthanThatOneKid@users.noreply.github.com> Date: Thu, 22 Feb 2024 17:23:51 -0800 Subject: [PATCH] Set up Discord OAuth2 (#16) * add oauth2 redirect * wip * wip Reference: - https://discord.com/developers/docs/topics/oauth2 - https://npmjs.com/package/@deno/kv - * added components for availability, data, datetime, time * added sample data for the new question types * Fixed Datetime question input * wip * Ran formating and added availability question * Removed unnecessary AvailabilityQuestionValue from imports in form.svelte * Fixed spelling error lol * Added the name attribute to question types changed sumbit button * blindly-coded wip * wip * wip * wip * add form and submission to `Store` interface * wip * wip * wip * wip * wip * wip * wip * wip * Update kv.ts * wip * update tentative landing page * wip getting sessions to seemingly work maybe TODO: remove rogue console log statements. * Delete +server.ts * run `npm run lint` * add form preview components * wip * wip * Squashed commit of the following: commit 71e0b113927c8e064229e63931f964a98f6e3f1d Author: Alexander Peras <128564378+AlexthePear@users.noreply.github.com> Date: Fri Feb 9 04:42:49 2024 -0800 npm run format commit 7b981e91b73db7c0440c7b8a5db8acf267032c5c Author: Alexander Peras <128564378+AlexthePear@users.noreply.github.com> Date: Fri Feb 9 04:36:09 2024 -0800 fixed textarea resizing after changing fieldset commit 3e947e7fcaed98d4fe6e616c20568dc5d783faa3 Author: Alexander Peras <128564378+AlexthePear@users.noreply.github.com> Date: Fri Feb 9 04:11:33 2024 -0800 npm run format commit 77985119b37499e30829fe04809d4c3197e71ba0 Author: Alexander Peras <128564378+AlexthePear@users.noreply.github.com> Date: Fri Feb 9 04:07:59 2024 -0800 added choiceIndex functionality commit 05adf31b6c58d27455e284d4eb2b2cad86e522ce Author: Alexander Peras <128564378+AlexthePear@users.noreply.github.com> Date: Fri Feb 9 03:47:08 2024 -0800 added functionality for custom choice commit 2150ac7f76165df96936f882ed071bf0a7029c97 Author: Alexander Peras <128564378+AlexthePear@users.noreply.github.com> Date: Fri Feb 9 03:31:02 2024 -0800 npm run format and fixed lint errors commit cdffee6d64210f1798dffd493fc970f663b336e8 Author: Alexander Peras <128564378+AlexthePear@users.noreply.github.com> Date: Fri Feb 9 03:18:23 2024 -0800 replaced default with value in form.ts and all interfaces commit 2106f9fb081882c1349444ab8e0965248e13bbcd Author: AlexthePear Date: Tue Feb 6 14:54:16 2024 -0800 ran npm run format commit 2b79740aaf4987408ac7d1c0c48891d8558eb3af Author: AlexthePear Date: Tue Feb 6 14:51:15 2024 -0800 FIXED: SingleTextSelectQuestion Value didn't extend QuestionValueBase commit 52225085e78275e619987fd76b81faa1c381da3b Author: AlexthePear Date: Sat Feb 3 17:38:01 2024 -0800 wip commit 03c057272c282a769ce33aee95963ef6cc0be781 Author: AlexthePear Date: Sat Feb 3 16:10:03 2024 -0800 WIP: changing availiability question from using data.defualt to AvailabilityQuestionValue to store data commit 964b6e3dfeef4f50c901a5601ebbbb427a130811 Author: AlexthePear Date: Sat Feb 3 15:41:26 2024 -0800 reformated files commit 04f1012ce49f4a0cd492bbb4a7b96317675a42f1 Merge: 63b8577 0bf9f59 Author: AlexthePear Date: Sat Feb 3 15:40:16 2024 -0800 Merge branch 'new-form-questions' of https://github.com/acmcsufoss/form into new-form-questions commit 63b857787fad3ac6d59a8cef7b70c66dc04ba041 Author: AlexthePear Date: Sat Feb 3 15:39:57 2024 -0800 wrapped all questions in fieldset and replaced label with commit 0bf9f59f85c201a680668a059a676c1872f3da1e Author: Alexander Peras <128564378+AlexthePear@users.noreply.github.com> Date: Wed Jan 31 13:40:35 2024 -0800 fixed text area question resizing commit 7538b337b4ee606bd578c707ed4420c1662c51a3 Author: Alexander Peras <128564378+AlexthePear@users.noreply.github.com> Date: Wed Jan 31 13:35:07 2024 -0800 Added validation for avaliability question so its always a valid input * wip * fixed demo_form css * fix demo form * Update +page.svelte * add form editor notes * add check to createForm * add redirect to `/discord_oauth2/logout` endpoint * add `DENO_KV_CONNECT_URL` env var * check workflow: copy default env vars * check workflow: copy default env vars * move db files to `.denokv` directory * Update check.yaml * check workflow: omit build step * replace default `kvPath` * edit form editor component --------- Co-authored-by: Kaitlyn Jao Co-authored-by: AlexthePear Co-authored-by: AlexthePear --- .env.example | 8 + .github/workflows/check.yaml | 9 +- .gitignore | 1 + package-lock.json | 183 ++ package.json | 8 +- src/app.d.ts | 7 +- src/app.html | 1 + src/hooks.server.ts | 15 + .../availability_question_input.svelte | 40 +- .../components/boolean_question_input.svelte | 21 +- .../components/color_question_input.svelte | 17 +- src/lib/components/date_question_input.svelte | 21 +- .../components/datetime_question_imput.svelte | 20 +- src/lib/components/form.svelte | 289 +- src/lib/components/form_editor.svelte | 106 + .../components/number_question_input.svelte | 23 +- src/lib/components/question_input.svelte | 56 + .../components/select_question_input.svelte | 12 + .../single_text_select_question_input.svelte | 23 +- src/lib/components/text_question_input.svelte | 22 +- .../components/textarea_question_input.svelte | 53 +- src/lib/components/time_question_input.svelte | 21 +- .../components/timezone_question_input.svelte | 18 + src/lib/discord/api.ts | 151 + src/lib/discord/index.ts | 1 + src/lib/form/form.ts | 187 +- src/lib/form/id.ts | 4 + src/lib/form/permissions.ts | 27 + src/lib/form/submission.ts | 11 +- src/lib/oauth2/index.ts | 1 + src/lib/oauth2/oauth2.ts | 7 + src/lib/resources/store.ts | 8 + src/lib/store/index.ts | 1 + src/lib/store/kv/index.ts | 1 + src/lib/store/kv/kv.ts | 190 ++ src/lib/store/store.ts | 60 + src/lib/timezones/data.ts | 2656 +++++++++++++++++ src/lib/timezones/index.ts | 2 + src/lib/timezones/timezones.ts | 5 + src/lib/urls/index.ts | 1 + src/lib/urls/urls.ts | 23 + src/routes/+layout.server.ts | 17 + src/routes/+layout.svelte | 7 + src/routes/+page.server.ts | 7 + src/routes/+page.svelte | 27 +- src/routes/+page.ts | 3 + src/routes/demo/+page.svelte | 5 + src/routes/demo/demo_form.svelte | 6 + src/routes/demo/demo_form.ts | 59 + src/routes/discord_oauth2/+server.ts | 96 + src/routes/discord_oauth2/logout/+server.ts | 28 + src/routes/forms/+layout.server.ts | 22 + src/routes/forms/+page.server.ts | 15 + src/routes/forms/+page.svelte | 14 +- src/routes/forms/+page.ts | 3 + src/routes/forms/[form_id]/+page.server.ts | 10 + src/routes/forms/[form_id]/+page.svelte | 13 + src/routes/forms/[form_id]/+page.ts | 3 + .../[form_id]/submissions.csv/+server.ts | 29 + .../forms/[form_id]/submissions/+page.svelte | 14 + .../[submission_id]/+page.server.ts | 10 + .../submissions/[submission_id]/+page.svelte | 12 + .../submissions/[submission_id]/+page.ts | 3 + .../[form_id]/submissions/new/+server.ts | 33 + src/routes/forms/[id]/+page.svelte | 1 - src/routes/forms/form_preview.svelte | 60 + src/routes/forms/form_preview_list.svelte | 18 + src/routes/forms/new/+server.ts | 27 + src/routes/invites/[invite_id]/+page.svelte | 1 + src/routes/responses/[id]/+page.svelte | 1 - static/global.css | 6 + 71 files changed, 4365 insertions(+), 495 deletions(-) create mode 100644 .env.example create mode 100644 src/hooks.server.ts create mode 100644 src/lib/components/form_editor.svelte create mode 100644 src/lib/components/question_input.svelte create mode 100644 src/lib/components/select_question_input.svelte create mode 100644 src/lib/components/timezone_question_input.svelte create mode 100644 src/lib/discord/api.ts create mode 100644 src/lib/discord/index.ts create mode 100644 src/lib/form/id.ts create mode 100644 src/lib/form/permissions.ts create mode 100644 src/lib/oauth2/index.ts create mode 100644 src/lib/oauth2/oauth2.ts create mode 100644 src/lib/resources/store.ts create mode 100644 src/lib/store/index.ts create mode 100644 src/lib/store/kv/index.ts create mode 100644 src/lib/store/kv/kv.ts create mode 100644 src/lib/store/store.ts create mode 100644 src/lib/timezones/data.ts create mode 100644 src/lib/timezones/index.ts create mode 100644 src/lib/timezones/timezones.ts create mode 100644 src/lib/urls/index.ts create mode 100644 src/lib/urls/urls.ts create mode 100644 src/routes/+layout.server.ts create mode 100644 src/routes/+layout.svelte create mode 100644 src/routes/+page.server.ts create mode 100644 src/routes/+page.ts create mode 100644 src/routes/demo/+page.svelte create mode 100644 src/routes/demo/demo_form.svelte create mode 100644 src/routes/demo/demo_form.ts create mode 100644 src/routes/discord_oauth2/+server.ts create mode 100644 src/routes/discord_oauth2/logout/+server.ts create mode 100644 src/routes/forms/+layout.server.ts create mode 100644 src/routes/forms/+page.server.ts create mode 100644 src/routes/forms/+page.ts create mode 100644 src/routes/forms/[form_id]/+page.server.ts create mode 100644 src/routes/forms/[form_id]/+page.svelte create mode 100644 src/routes/forms/[form_id]/+page.ts create mode 100644 src/routes/forms/[form_id]/submissions.csv/+server.ts create mode 100644 src/routes/forms/[form_id]/submissions/+page.svelte create mode 100644 src/routes/forms/[form_id]/submissions/[submission_id]/+page.server.ts create mode 100644 src/routes/forms/[form_id]/submissions/[submission_id]/+page.svelte create mode 100644 src/routes/forms/[form_id]/submissions/[submission_id]/+page.ts create mode 100644 src/routes/forms/[form_id]/submissions/new/+server.ts delete mode 100644 src/routes/forms/[id]/+page.svelte create mode 100644 src/routes/forms/form_preview.svelte create mode 100644 src/routes/forms/form_preview_list.svelte create mode 100644 src/routes/forms/new/+server.ts create mode 100644 src/routes/invites/[invite_id]/+page.svelte delete mode 100644 src/routes/responses/[id]/+page.svelte create mode 100644 static/global.css diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..49504ed --- /dev/null +++ b/.env.example @@ -0,0 +1,8 @@ +DENO_KV_ACCESS_TOKEN="" +DENO_KV_CONNECT_URL="" +DISCORD_REDIRECT_URI="" +DISCORD_CLIENT_ID="" +DISCORD_CLIENT_SECRET="" +DISCORD_GUILD_ID="" +DISCORD_ROLE_ID="" +DISCORD_BOT_TOKEN="" diff --git a/.github/workflows/check.yaml b/.github/workflows/check.yaml index 8ada9ca..ac67733 100644 --- a/.github/workflows/check.yaml +++ b/.github/workflows/check.yaml @@ -36,6 +36,12 @@ jobs: - name: Install Dependencies run: npm ci + - name: Set up .env + run: cp .env.example .env + + - name: Set up .env + run: cp .env.example .env + - name: Svelte check run: npm run check @@ -44,6 +50,3 @@ jobs: - name: Lint run: npm run lint && git diff --exit-code - - - name: Build - run: npm run build diff --git a/.gitignore b/.gitignore index 6635cf5..79fd2da 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ node_modules !.env.example vite.config.js.timestamp-* vite.config.ts.timestamp-* +.denokv* diff --git a/package-lock.json b/package-lock.json index 22e7941..224ca26 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7,6 +7,12 @@ "": { "name": "form", "version": "0.0.1", + "dependencies": { + "@deno/kv": "^0.7.0", + "discord-api-types": "^0.37.67", + "export-to-csv": "^1.2.2", + "ulid": "^2.3.0" + }, "devDependencies": { "@sveltejs/adapter-auto": "^2.0.0", "@sveltejs/kit": "^1.20.4", @@ -46,6 +52,77 @@ "node": ">=6.0.0" } }, + "node_modules/@deno/kv": { + "version": "0.7.0", + "resolved": "https://registry.npmjs.org/@deno/kv/-/kv-0.7.0.tgz", + "integrity": "sha512-+vYCIWDQq+03RKwh85WDBVplwT7gimcLyLezj6C3OuMwaTWfPy9NVmA5y4Mwpoht0+H4CjknEUE7LrfZJAcQ7w==", + "optionalDependencies": { + "@deno/kv-darwin-arm64": "0.7.0", + "@deno/kv-darwin-x64": "0.7.0", + "@deno/kv-linux-x64-gnu": "0.7.0", + "@deno/kv-win32-x64-msvc": "0.7.0" + } + }, + "node_modules/@deno/kv-darwin-arm64": { + "version": "0.7.0", + "resolved": "https://registry.npmjs.org/@deno/kv-darwin-arm64/-/kv-darwin-arm64-0.7.0.tgz", + "integrity": "sha512-PaTriht31Rb08TwWdAkmODrLNnGnl9l8nlF/0aae/v7dzJ5FeaoX+0RgxTD+m90quG3ynsdLsY8iCa+st+MkiA==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">= 18" + } + }, + "node_modules/@deno/kv-darwin-x64": { + "version": "0.7.0", + "resolved": "https://registry.npmjs.org/@deno/kv-darwin-x64/-/kv-darwin-x64-0.7.0.tgz", + "integrity": "sha512-Yw4Gmn6opUJ6ZVuztNaGS4yt11KyJI/juTAyzNiY5H3VhHD7xVm+peG4SGkr6Hq/vXVGcQM3Lldw5b3aJJQYSg==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">= 18" + } + }, + "node_modules/@deno/kv-linux-x64-gnu": { + "version": "0.7.0", + "resolved": "https://registry.npmjs.org/@deno/kv-linux-x64-gnu/-/kv-linux-x64-gnu-0.7.0.tgz", + "integrity": "sha512-D6xJcx4HSUbgomxGV2lGUgKrRmwHNMmCbu8XRxBjIgpsKrFK1W6w+KitI92wMCgEIOAFAnfeyrYxtMzh2ZdYTw==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 18" + } + }, + "node_modules/@deno/kv-win32-x64-msvc": { + "version": "0.7.0", + "resolved": "https://registry.npmjs.org/@deno/kv-win32-x64-msvc/-/kv-win32-x64-msvc-0.7.0.tgz", + "integrity": "sha512-0UWf6a+T7e/1uOcUgUKTrMupIQSnCI02856ecu9JwutajSvvbSgoi+jpmaUnYW6QqcXjY8ECI/28CQi1DvYYhw==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">= 18" + } + }, "node_modules/@esbuild/android-arm": { "version": "0.18.20", "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.18.20.tgz", @@ -686,6 +763,17 @@ "integrity": "sha512-U3PUjAudAdJBeC2pgN8uTIKgxrb4nlDF3SF0++EldXQvQBGkpFZMSnwQiIoDU77tv45VgNkl/L4ouD+rEomujw==", "dev": true }, + "node_modules/@types/node": { + "version": "20.10.5", + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.10.5.tgz", + "integrity": "sha512-nNPsNE65wjMxEKI93yOP+NPGGBJz/PoN3kZsVLee0XMiJolxSekEVD8wRwBUBqkwc7UWop0edW50yrCQW4CyRw==", + "dev": true, + "optional": true, + "peer": true, + "dependencies": { + "undici-types": "~5.26.4" + } + }, "node_modules/@types/pug": { "version": "2.0.8", "resolved": "https://registry.npmjs.org/@types/pug/-/pug-2.0.8.tgz", @@ -1257,6 +1345,11 @@ "node": ">=8" } }, + "node_modules/discord-api-types": { + "version": "0.37.67", + "resolved": "https://registry.npmjs.org/discord-api-types/-/discord-api-types-0.37.67.tgz", + "integrity": "sha512-4HEzUEmwGPXWJdVhGZ/K+9eWs8kurdn5r/I8qD3/0hb14I0MZvx8K/JOyLhKLgcR4/8/jcr6Xej820BNgNXN7A==" + }, "node_modules/doctrine": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/doctrine/-/doctrine-3.0.0.tgz", @@ -1526,6 +1619,11 @@ "node": ">=0.10.0" } }, + "node_modules/export-to-csv": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/export-to-csv/-/export-to-csv-1.2.2.tgz", + "integrity": "sha512-d9BxkLlyxeyFU1yhQKGjnnEQj2fh6PjyDVGyiI/uj7PD/oe7Lo1551B1lTaQeXHGPRX2DHuk6i3JMZB6ncJApQ==" + }, "node_modules/fast-deep-equal": { "version": "3.1.3", "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz", @@ -2958,6 +3056,14 @@ "node": ">=14.17" } }, + "node_modules/ulid": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/ulid/-/ulid-2.3.0.tgz", + "integrity": "sha512-keqHubrlpvT6G2wH0OEfSW4mquYRcbe/J8NMmveoQOjUqmo+hXtO+ORCpWhdbZ7k72UtY61BL7haGxW6enBnjw==", + "bin": { + "ulid": "bin/cli.js" + } + }, "node_modules/undici": { "version": "5.26.4", "resolved": "https://registry.npmjs.org/undici/-/undici-5.26.4.tgz", @@ -2970,6 +3076,14 @@ "node": ">=14.0" } }, + "node_modules/undici-types": { + "version": "5.26.5", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz", + "integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==", + "dev": true, + "optional": true, + "peer": true + }, "node_modules/uri-js": { "version": "4.4.1", "resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.4.1.tgz", @@ -3120,6 +3234,41 @@ "@jridgewell/trace-mapping": "^0.3.9" } }, + "@deno/kv": { + "version": "0.7.0", + "resolved": "https://registry.npmjs.org/@deno/kv/-/kv-0.7.0.tgz", + "integrity": "sha512-+vYCIWDQq+03RKwh85WDBVplwT7gimcLyLezj6C3OuMwaTWfPy9NVmA5y4Mwpoht0+H4CjknEUE7LrfZJAcQ7w==", + "requires": { + "@deno/kv-darwin-arm64": "0.7.0", + "@deno/kv-darwin-x64": "0.7.0", + "@deno/kv-linux-x64-gnu": "0.7.0", + "@deno/kv-win32-x64-msvc": "0.7.0" + } + }, + "@deno/kv-darwin-arm64": { + "version": "0.7.0", + "resolved": "https://registry.npmjs.org/@deno/kv-darwin-arm64/-/kv-darwin-arm64-0.7.0.tgz", + "integrity": "sha512-PaTriht31Rb08TwWdAkmODrLNnGnl9l8nlF/0aae/v7dzJ5FeaoX+0RgxTD+m90quG3ynsdLsY8iCa+st+MkiA==", + "optional": true + }, + "@deno/kv-darwin-x64": { + "version": "0.7.0", + "resolved": "https://registry.npmjs.org/@deno/kv-darwin-x64/-/kv-darwin-x64-0.7.0.tgz", + "integrity": "sha512-Yw4Gmn6opUJ6ZVuztNaGS4yt11KyJI/juTAyzNiY5H3VhHD7xVm+peG4SGkr6Hq/vXVGcQM3Lldw5b3aJJQYSg==", + "optional": true + }, + "@deno/kv-linux-x64-gnu": { + "version": "0.7.0", + "resolved": "https://registry.npmjs.org/@deno/kv-linux-x64-gnu/-/kv-linux-x64-gnu-0.7.0.tgz", + "integrity": "sha512-D6xJcx4HSUbgomxGV2lGUgKrRmwHNMmCbu8XRxBjIgpsKrFK1W6w+KitI92wMCgEIOAFAnfeyrYxtMzh2ZdYTw==", + "optional": true + }, + "@deno/kv-win32-x64-msvc": { + "version": "0.7.0", + "resolved": "https://registry.npmjs.org/@deno/kv-win32-x64-msvc/-/kv-win32-x64-msvc-0.7.0.tgz", + "integrity": "sha512-0UWf6a+T7e/1uOcUgUKTrMupIQSnCI02856ecu9JwutajSvvbSgoi+jpmaUnYW6QqcXjY8ECI/28CQi1DvYYhw==", + "optional": true + }, "@esbuild/android-arm": { "version": "0.18.20", "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.18.20.tgz", @@ -3484,6 +3633,17 @@ "integrity": "sha512-U3PUjAudAdJBeC2pgN8uTIKgxrb4nlDF3SF0++EldXQvQBGkpFZMSnwQiIoDU77tv45VgNkl/L4ouD+rEomujw==", "dev": true }, + "@types/node": { + "version": "20.10.5", + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.10.5.tgz", + "integrity": "sha512-nNPsNE65wjMxEKI93yOP+NPGGBJz/PoN3kZsVLee0XMiJolxSekEVD8wRwBUBqkwc7UWop0edW50yrCQW4CyRw==", + "dev": true, + "optional": true, + "peer": true, + "requires": { + "undici-types": "~5.26.4" + } + }, "@types/pug": { "version": "2.0.8", "resolved": "https://registry.npmjs.org/@types/pug/-/pug-2.0.8.tgz", @@ -3871,6 +4031,11 @@ "path-type": "^4.0.0" } }, + "discord-api-types": { + "version": "0.37.67", + "resolved": "https://registry.npmjs.org/discord-api-types/-/discord-api-types-0.37.67.tgz", + "integrity": "sha512-4HEzUEmwGPXWJdVhGZ/K+9eWs8kurdn5r/I8qD3/0hb14I0MZvx8K/JOyLhKLgcR4/8/jcr6Xej820BNgNXN7A==" + }, "doctrine": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/doctrine/-/doctrine-3.0.0.tgz", @@ -4065,6 +4230,11 @@ "integrity": "sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g==", "dev": true }, + "export-to-csv": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/export-to-csv/-/export-to-csv-1.2.2.tgz", + "integrity": "sha512-d9BxkLlyxeyFU1yhQKGjnnEQj2fh6PjyDVGyiI/uj7PD/oe7Lo1551B1lTaQeXHGPRX2DHuk6i3JMZB6ncJApQ==" + }, "fast-deep-equal": { "version": "3.1.3", "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz", @@ -5033,6 +5203,11 @@ "integrity": "sha512-mI4WrpHsbCIcwT9cF4FZvr80QUeKvsUsUvKDoR+X/7XHQH98xYD8YHZg7ANtz2GtZt/CBq2QJ0thkGJMHfqc1w==", "dev": true }, + "ulid": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/ulid/-/ulid-2.3.0.tgz", + "integrity": "sha512-keqHubrlpvT6G2wH0OEfSW4mquYRcbe/J8NMmveoQOjUqmo+hXtO+ORCpWhdbZ7k72UtY61BL7haGxW6enBnjw==" + }, "undici": { "version": "5.26.4", "resolved": "https://registry.npmjs.org/undici/-/undici-5.26.4.tgz", @@ -5042,6 +5217,14 @@ "@fastify/busboy": "^2.0.0" } }, + "undici-types": { + "version": "5.26.5", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz", + "integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==", + "dev": true, + "optional": true, + "peer": true + }, "uri-js": { "version": "4.4.1", "resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.4.1.tgz", diff --git a/package.json b/package.json index 72e52ca..a5541ec 100644 --- a/package.json +++ b/package.json @@ -28,5 +28,11 @@ "typescript": "^5.0.0", "vite": "^4.4.2" }, - "type": "module" + "type": "module", + "dependencies": { + "@deno/kv": "^0.7.0", + "discord-api-types": "^0.37.67", + "export-to-csv": "^1.2.2", + "ulid": "^2.3.0" + } } diff --git a/src/app.d.ts b/src/app.d.ts index f59b884..81950e9 100644 --- a/src/app.d.ts +++ b/src/app.d.ts @@ -1,11 +1,16 @@ +import type { User } from '$lib/store'; + // See https://kit.svelte.dev/docs/types#app // for information about these interfaces declare global { namespace App { // interface Error {} - // interface Locals {} // interface PageData {} // interface Platform {} + + interface Locals { + user: User | undefined; + } } } diff --git a/src/app.html b/src/app.html index 6769ed5..74eeba8 100644 --- a/src/app.html +++ b/src/app.html @@ -4,6 +4,7 @@ + %sveltekit.head% diff --git a/src/hooks.server.ts b/src/hooks.server.ts new file mode 100644 index 0000000..aa704fb --- /dev/null +++ b/src/hooks.server.ts @@ -0,0 +1,15 @@ +import type { Handle } from '@sveltejs/kit'; +import { s } from '$lib/resources/store'; +import { SESSION_ID_COOKIE_NAME } from '$lib/oauth2'; + +export const handle: Handle = async ({ event, resolve }) => { + const sessionID = event.cookies.get(SESSION_ID_COOKIE_NAME); + if (sessionID) { + const user = await s.getUserBySessionID(sessionID); + if (user) { + event.locals.user = user; + } + } + + return await resolve(event); +}; diff --git a/src/lib/components/availability_question_input.svelte b/src/lib/components/availability_question_input.svelte index 89fac0f..36c2992 100644 --- a/src/lib/components/availability_question_input.svelte +++ b/src/lib/components/availability_question_input.svelte @@ -1,50 +1,28 @@
{data.content}
- {#each Array.from({ length: data.maxDateRanges ?? 1 }, (_, i) => i) as i} + {#each Array.from({ length: data.maxDatetimeRanges ?? 1 }, (_, i) => i) as i}

----

{/each} diff --git a/src/lib/components/boolean_question_input.svelte b/src/lib/components/boolean_question_input.svelte index a813e25..7df0a8b 100644 --- a/src/lib/components/boolean_question_input.svelte +++ b/src/lib/components/boolean_question_input.svelte @@ -1,27 +1,14 @@
{data.content} {#if data.style === 'radio'} - + {:else} - + {/if}
diff --git a/src/lib/components/color_question_input.svelte b/src/lib/components/color_question_input.svelte index fa39014..cdce196 100644 --- a/src/lib/components/color_question_input.svelte +++ b/src/lib/components/color_question_input.svelte @@ -1,20 +1,9 @@
{data.content} - +
diff --git a/src/lib/components/date_question_input.svelte b/src/lib/components/date_question_input.svelte index 2c18944..1d3043b 100644 --- a/src/lib/components/date_question_input.svelte +++ b/src/lib/components/date_question_input.svelte @@ -1,22 +1,7 @@
@@ -27,6 +12,6 @@ required={data.required} min={data.min} max={data.max} - bind:value={data.value} + value={data.value} />
diff --git a/src/lib/components/datetime_question_imput.svelte b/src/lib/components/datetime_question_imput.svelte index 8a2a0af..a12dd94 100644 --- a/src/lib/components/datetime_question_imput.svelte +++ b/src/lib/components/datetime_question_imput.svelte @@ -1,21 +1,7 @@
@@ -24,7 +10,7 @@ name={data.name} type="datetime-local" required={data.required} - bind:value={data.value} + value={data.value} min={data.min} max={data.max} /> diff --git a/src/lib/components/form.svelte b/src/lib/components/form.svelte index 7808bfe..925389c 100644 --- a/src/lib/components/form.svelte +++ b/src/lib/components/form.svelte @@ -1,253 +1,50 @@ -
+
-

form

-

- Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut - labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco - laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in - voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat - non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. -

+

{data.title}

+

{data.description}


-

Account:

-

Name:

-

Date:

-
-
- {#each questionList.data as question} -
- {#if question.type === QuestionType.BOOLEAN} - - {:else if question.type === QuestionType.TEXT} - - {:else if question.type === QuestionType.SINGLE_TEXT_SELECT} - - {:else if question.type === QuestionType.NUMBER} - - {:else if question.type === QuestionType.COLOR} - - {:else if question.type === QuestionType.TEXTAREA} - - {:else if question.type === QuestionType.DATE} - - {:else if question.type === QuestionType.AVAILABILITY} - - {:else if question.type === QuestionType.DATETIME} - - {:else if question.type === QuestionType.TIME} - +

+ Account: + {#if user} + {user.discordUsername} + {:else} + Unauthenticated + {/if} +

+ + {#if data.schedule?.startDate} +

Opened at: {data.schedule?.startDate}

+ {/if} + {#if data.schedule?.endDate} +

Opened until: {data.schedule?.endDate}

{/if}
+
+ {#each data.questions.data as question} + {/each} - - - - - + + diff --git a/src/lib/components/number_question_input.svelte b/src/lib/components/number_question_input.svelte index 2d2f59a..69a2d9d 100644 --- a/src/lib/components/number_question_input.svelte +++ b/src/lib/components/number_question_input.svelte @@ -1,26 +1,7 @@
diff --git a/src/lib/components/question_input.svelte b/src/lib/components/question_input.svelte new file mode 100644 index 0000000..1cd9818 --- /dev/null +++ b/src/lib/components/question_input.svelte @@ -0,0 +1,56 @@ + + +
+ {#if data.type === QuestionType.BOOLEAN} + + {:else if data.type === QuestionType.TEXT} + + {:else if data.type === QuestionType.SINGLE_TEXT_SELECT} + + {:else if data.type === QuestionType.NUMBER} + + {:else if data.type === QuestionType.COLOR} + + {:else if data.type === QuestionType.TEXTAREA} + + {:else if data.type === QuestionType.DATE} + + {:else if data.type === QuestionType.AVAILABILITY} + + {:else if data.type === QuestionType.DATETIME} + + {:else if data.type === QuestionType.TIME} + + {:else if data.type === QuestionType.SELECT} + + {/if} +
+ + diff --git a/src/lib/components/select_question_input.svelte b/src/lib/components/select_question_input.svelte new file mode 100644 index 0000000..5cfb3df --- /dev/null +++ b/src/lib/components/select_question_input.svelte @@ -0,0 +1,12 @@ + + + + diff --git a/src/lib/components/single_text_select_question_input.svelte b/src/lib/components/single_text_select_question_input.svelte index 6be4ab5..099ca9f 100644 --- a/src/lib/components/single_text_select_question_input.svelte +++ b/src/lib/components/single_text_select_question_input.svelte @@ -1,28 +1,11 @@
{data.content} - {#each data.choices as choice, i}
{/if} diff --git a/src/lib/components/text_question_input.svelte b/src/lib/components/text_question_input.svelte index 66c829b..d94e733 100644 --- a/src/lib/components/text_question_input.svelte +++ b/src/lib/components/text_question_input.svelte @@ -1,25 +1,7 @@
diff --git a/src/lib/components/textarea_question_input.svelte b/src/lib/components/textarea_question_input.svelte index b8256fc..d172100 100644 --- a/src/lib/components/textarea_question_input.svelte +++ b/src/lib/components/textarea_question_input.svelte @@ -1,46 +1,37 @@
{data.content}