From 08950f688b68c0229070a03a2806710b5db777c1 Mon Sep 17 00:00:00 2001 From: Sarah Olson Date: Wed, 4 Oct 2023 00:43:53 -0400 Subject: [PATCH 1/3] final iteration 1 --- .gitignore | 24 ++++ README.md | 35 ++---- index.html | 13 +++ jsconfig.json | 32 ++++++ package.json | 20 ++++ public/vite.svg | 1 + server.js | 142 +++++++++++++++++++++++ src/App.svelte | 102 +++++++++++++++++ src/app.css | 80 +++++++++++++ src/assets/svelte.svg | 1 + src/lib/GoalSide.svelte | 236 +++++++++++++++++++++++++++++++++++++++ src/lib/TableSide.svelte | 119 ++++++++++++++++++++ src/main.js | 11 ++ src/vite-env.d.ts | 2 + svelte.config.js | 7 ++ vite.config.js | 7 ++ 16 files changed, 805 insertions(+), 27 deletions(-) create mode 100644 .gitignore create mode 100644 index.html create mode 100644 jsconfig.json create mode 100644 package.json create mode 100644 public/vite.svg create mode 100644 server.js create mode 100644 src/App.svelte create mode 100644 src/app.css create mode 100644 src/assets/svelte.svg create mode 100644 src/lib/GoalSide.svelte create mode 100644 src/lib/TableSide.svelte create mode 100644 src/main.js create mode 100644 src/vite-env.d.ts create mode 100644 svelte.config.js create mode 100644 vite.config.js diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..a547bf36 --- /dev/null +++ b/.gitignore @@ -0,0 +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? diff --git a/README.md b/README.md index 70982294..637a1c0f 100644 --- a/README.md +++ b/README.md @@ -1,33 +1,14 @@ -Assignment 4 - Components -=== +**WPI Badminton Attendance Tracker** -Due: October 4th, by 11:59 AM. +Sarah Olson +A4 Components +link: test.me -For this assignment you will re-implement the client side portion of *either* A2 or A3 using either React or Svelte components. If you choose A3 you only need to use components for the data display / updating; you can leave your login UI as is. +I created a web app for Badminton Club members who are using their participation in this course as a gym credit to track their progress toward their grade goal. First the user either enters or creates account information, so that they can only see their progress, and login in. The user then enters their target grade and the dates + amount of hours they attended on each day to keep track of the user's progress toward their grading goal. -[Svelte Tutorial](https://github.com/cs-4241-23/cs-4241-23.github.io/blob/main/using.svelte.md) -[React Tutorial](https://github.com/cs-4241-23/cs-4241-23.github.io/blob/main/using.react.md) +The user can also edit their grading goal and delete entries they make. -This project can be implemented on any hosting service (Glitch, DigitalOcean, Heroku etc.), however, you must include all files in your GitHub repo so that the course staff can view them. +The most obvious change compared to A3 and A2 is that this iteration uses Svelte rather than pure HTML and JS. I also reverted back to locally storing in the server rather than using MongoDB (like A2), but kept the accesibility, server, and style benefits from A3. -Deliverables ---- + Initially, adding the new technology proved to be quite useful, being able to split up the pages with all the JS, HTML, and CSS for certain sections and having it all in one place and being able to edit it all at once proved to be helpful. But I ran into big issues with having those seperate components functioning as one, with still some features from A3 (mainly seperate pages) missing. If I was more farmiliar with Svelte from the begining, I think I would have had A3 structured differently to work better. -Do the following to complete this assignment: - -1. Implement your project with the above requirements. -3. Test your project to make sure that when someone goes to your main page on Glitch/Heroku/etc., it displays correctly. -4. Ensure that your project has the proper naming scheme `a4-firstname-lastname` so we can find it. -5. Fork this repository and modify the README to the specifications below. Be sure to add *all* project files. -6. Create and submit a Pull Request to the original repo. Name the pull request using the following template: `a4-firstname-lastname`. - -Sample Readme (delete the above when you're ready to submit, and modify the below so with your links and descriptions) ---- - -## Your Web Application Title - -your hosting link e.g. http://a4-charlieroberts.glitch.me - -Include a very brief summary of your project here and what you changed / added to assignment #3. Briefly (3–4 sentences) answer the following question: did the new technology improve or hinder the development experience? - -Unlike previous assignments, this assignment will be solely graded on whether or not you successfully complete it. Partial credit will be generously given. diff --git a/index.html b/index.html new file mode 100644 index 00000000..b8c87297 --- /dev/null +++ b/index.html @@ -0,0 +1,13 @@ + + + + + + + WPI Badminton Tracker + + +
+ + + diff --git a/jsconfig.json b/jsconfig.json new file mode 100644 index 00000000..5696a2de --- /dev/null +++ b/jsconfig.json @@ -0,0 +1,32 @@ +{ + "compilerOptions": { + "moduleResolution": "bundler", + "target": "ESNext", + "module": "ESNext", + /** + * svelte-preprocess cannot figure out whether you have + * a value or a type, so tell TypeScript to enforce using + * `import type` instead of `import` for Types. + */ + "verbatimModuleSyntax": true, + "isolatedModules": true, + "resolveJsonModule": true, + /** + * To have warnings / errors of the Svelte compiler at the + * correct position, enable source maps by default. + */ + "sourceMap": true, + "esModuleInterop": true, + "skipLibCheck": true, + /** + * Typecheck JS in `.svelte` and `.js` files by default. + * Disable this if you'd like to use dynamic types. + */ + "checkJs": true + }, + /** + * Use global.d.ts instead of compilerOptions.types + * to avoid limiting type declarations. + */ + "include": ["src/**/*.d.ts", "src/**/*.js", "src/**/*.svelte"] +} diff --git a/package.json b/package.json new file mode 100644 index 00000000..13b056f4 --- /dev/null +++ b/package.json @@ -0,0 +1,20 @@ +{ + "name": "a4-sarah-olson", + "private": true, + "version": "0.0.0", + "type": "module", + "scripts": { + "dev": "vite", + "build": "vite build", + "preview": "vite preview" + }, + "devDependencies": { + "@sveltejs/vite-plugin-svelte": "^2.4.2", + "svelte": "^4.0.5", + "vite": "^4.4.5" + }, + "dependencies": { + "express": "^4.18.2", + "vite-express": "^0.10.0" + } +} diff --git a/public/vite.svg b/public/vite.svg new file mode 100644 index 00000000..e7b8dfb1 --- /dev/null +++ b/public/vite.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/server.js b/server.js new file mode 100644 index 00000000..2754f9e2 --- /dev/null +++ b/server.js @@ -0,0 +1,142 @@ +import express from 'express' +import ViteExpress from 'vite-express' + +const app = express() + +const hoursTilGrade = [{ "A": 28 }, { "B": 24 }, { "C": 21 }] + +const appdata = [ + +] + +let currentGoal = "" +let hoursTilGoal = 0 +let ogHoursTilGoal = 0 + +app.use( express.json() ) +//app.use( express.static('public') ) + +app.use( (req,res,next) => { + //console.log(req) + next() +}) + + +app.get('/getTable', (req, res) => { + res.json(appdata) + }) + +app.get('/getGrade', (req,res) => { + res.json(currentGoal) +}) + +app.post('/setGoal', (req, res) => { + const body = req.body + const currGoal = body.goal + + console.log(currGoal, body) + + hoursTilGrade.forEach(d => { + for (let g in d) { + if (g === currGoal) { + hoursTilGoal = d[g] + break + } + } + }) + + currentGoal = currGoal + ogHoursTilGoal = hoursTilGoal + + // body['current_goal'] = currGoal + // body['hours_til_goal'] = hoursTilGoal + console.log("KKKKKKKKK", currentGoal) + res.json(currentGoal) +}) + +app.post('/editGoal', (req, res) => { + const body = req.body + const newGoal = req.body.goal + + console.log(newGoal) + + let newGoalNum = 0 + let differenceToChange = 0 + + if (newGoal !== currentGoal) { + + hoursTilGrade.forEach(d => { + for (let g in d) { + if (g === newGoal) { + newGoalNum = d[g] + differenceToChange = newGoalNum - ogHoursTilGoal + break + } + } + }) + + let hoursTilGoaNew = ogHoursTilGoal + differenceToChange + + currentGoal = newGoal + ogHoursTilGoal = hoursTilGoaNew + + console.log(differenceToChange) + //go thru and edit all of the remianings + appdata.forEach(d => { + d.remaining += differenceToChange + }) + } + + console.log(newGoal, appdata) + res.json(currentGoal) + }) + + + app.post('/deleteEntry', (req, res) => { + + const info = req.body.info + //const index = indexObj.idx + + //need to edit all entries after the index + //console.log(req) + //console.log(appdata[index]) + let index = 0; + for(let i = 0; i < appdata.length; i++){ + if(appdata[i] === info){ + index = i + break + } + } + console.log(info, index) + let differenceToChange = parseFloat(info.hours) + + for (let i = index; i < appdata.length; i++) { + appdata[i].remaining += differenceToChange + } + + console.log(appdata) + appdata.splice(parseInt(index), 1) + if(appdata.length === 0) + hoursTilGoal = ogHoursTilGoal + console.log(appdata) + + res.json(appdata) + }) + + app.post('/addHours', (req, res) => { + const body = req.body + + + + + if(appdata.length > 0){ + hoursTilGoal = appdata[appdata.length - 1].remaining + } + + body['remaining'] = hoursTilGoal - body.hours + appdata.push(body) + res.json(appdata) + }) + + + ViteExpress.listen(app, 3000) \ No newline at end of file diff --git a/src/App.svelte b/src/App.svelte new file mode 100644 index 00000000..ba04473b --- /dev/null +++ b/src/App.svelte @@ -0,0 +1,102 @@ + + + + + Attendance Display - WPI Badminton Club Grade Tracker + + + + + + + + + + +

+ If you are taking Badminton Club for Gym Credit you receive your grade + based on the amount of hours you attend. +

+ +

+ Below highlights your current progress toward your previously established + grade goal +

+ +
+
+
+ +
+ +
+ +
+
+
+ + + + diff --git a/src/app.css b/src/app.css new file mode 100644 index 00000000..b87aec72 --- /dev/null +++ b/src/app.css @@ -0,0 +1,80 @@ +:root { + font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif; + line-height: 1.5; + font-weight: 400; + + color-scheme: light dark; + color: rgba(255, 255, 255, 0.87); + background-color: #242424; + + font-synthesis: none; + text-rendering: optimizeLegibility; + -webkit-font-smoothing: antialiased; + -moz-osx-font-smoothing: grayscale; + -webkit-text-size-adjust: 100%; +} + +a { + font-weight: 500; + color: #646cff; + text-decoration: inherit; +} +a:hover { + color: #535bf2; +} + +body { + margin: 0; + display: flex; + place-items: center; + min-width: 320px; + min-height: 100vh; +} + +h1 { + font-size: 3.2em; + line-height: 1.1; +} + +.card { + padding: 2em; +} + +#app { + max-width: 1280px; + margin: 0 auto; + padding: 2rem; + text-align: center; +} + +button { + border-radius: 8px; + border: 1px solid transparent; + padding: 0.6em 1.2em; + font-size: 1em; + font-weight: 500; + font-family: inherit; + background-color: #1a1a1a; + cursor: pointer; + transition: border-color 0.25s; +} +button:hover { + border-color: #646cff; +} +button:focus, +button:focus-visible { + outline: 4px auto -webkit-focus-ring-color; +} + +@media (prefers-color-scheme: light) { + :root { + color: #213547; + background-color: #ffffff; + } + a:hover { + color: #747bff; + } + button { + background-color: #f9f9f9; + } +} diff --git a/src/assets/svelte.svg b/src/assets/svelte.svg new file mode 100644 index 00000000..c5e08481 --- /dev/null +++ b/src/assets/svelte.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/lib/GoalSide.svelte b/src/lib/GoalSide.svelte new file mode 100644 index 00000000..829efb72 --- /dev/null +++ b/src/lib/GoalSide.svelte @@ -0,0 +1,236 @@ + + + + + + +

Grade Goal for this Term:

+{#await promiseG then grade} +

{grade}

+{/await} + +{#if hasGoal} + +

If you would like to edit your goal, change it below

+ + + +
+
+
+ + +
+ +
+
+ + + + + +{:else} +
+

It appears that you have not previously entered a grade goal

+

Please enter one below and click submit to establish it

+
+ + + +
+ + +
+{/if} + + diff --git a/src/lib/TableSide.svelte b/src/lib/TableSide.svelte new file mode 100644 index 00000000..c9768639 --- /dev/null +++ b/src/lib/TableSide.svelte @@ -0,0 +1,119 @@ + + + +

+ Enter the day you last attended with the amount of hours you logged +

+ +
+
+
+ + +
+
+ + +
+ +
+
+ + + + + + + + + + + + {#await promise then tableD} + + {#each tableD as info} + + + + + {#if info.remaining >= 0} + + {:else} + + {/if} + + + {/each} + + {/await} +
DateHoursRemainingDelete
{info.date}{info.hours}{info.remaining}0
+ + diff --git a/src/main.js b/src/main.js new file mode 100644 index 00000000..3a321ad0 --- /dev/null +++ b/src/main.js @@ -0,0 +1,11 @@ +import './app.css' +//import App from './App.svelte' +// @ts-ignore +import App from './App.svelte' + +const app = new App({ + target: document.getElementById('app'), +}) + +export default app + diff --git a/src/vite-env.d.ts b/src/vite-env.d.ts new file mode 100644 index 00000000..4078e747 --- /dev/null +++ b/src/vite-env.d.ts @@ -0,0 +1,2 @@ +/// +/// diff --git a/svelte.config.js b/svelte.config.js new file mode 100644 index 00000000..b0683fd2 --- /dev/null +++ b/svelte.config.js @@ -0,0 +1,7 @@ +import { vitePreprocess } from '@sveltejs/vite-plugin-svelte' + +export default { + // Consult https://svelte.dev/docs#compile-time-svelte-preprocess + // for more information about preprocessors + preprocess: vitePreprocess(), +} diff --git a/vite.config.js b/vite.config.js new file mode 100644 index 00000000..d7019694 --- /dev/null +++ b/vite.config.js @@ -0,0 +1,7 @@ +import { defineConfig } from 'vite' +import { svelte } from '@sveltejs/vite-plugin-svelte' + +// https://vitejs.dev/config/ +export default defineConfig({ + plugins: [svelte()], +}) From e65e070ec90d21eff8333b031de500b826a56ad0 Mon Sep 17 00:00:00 2001 From: Sarah Olson Date: Wed, 4 Oct 2023 01:01:36 -0400 Subject: [PATCH 2/3] final iteration 2 --- README.md | 3 ++- package.json | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 637a1c0f..bc96c9e6 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,8 @@ Sarah Olson A4 Components -link: test.me +link: https://stackblitz.com/edit/a4-sarah-olson?embed=1&file=index.html&hideExplorer=1&hideNavigation=1&view=preview +Note: if clicking the link above results in the page saying "Cannot GET /", clicking "Editor" then "Preview" in the bottom right corner of the browser should allow the page to load. I created a web app for Badminton Club members who are using their participation in this course as a gym credit to track their progress toward their grade goal. First the user either enters or creates account information, so that they can only see their progress, and login in. The user then enters their target grade and the dates + amount of hours they attended on each day to keep track of the user's progress toward their grading goal. diff --git a/package.json b/package.json index 13b056f4..9d997a4d 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "version": "0.0.0", "type": "module", "scripts": { - "dev": "vite", + "dev": "node server.js", "build": "vite build", "preview": "vite preview" }, From 74dbd0b2d75b267731b06ad5fb8675e86bc30ad6 Mon Sep 17 00:00:00 2001 From: Sarah Olson Date: Wed, 4 Oct 2023 01:26:59 -0400 Subject: [PATCH 3/3] final iteration: fixed styling --- src/App.svelte | 1 + src/lib/GoalSide.svelte | 5 +++++ src/lib/TableSide.svelte | 9 +++++++++ 3 files changed, 15 insertions(+) diff --git a/src/App.svelte b/src/App.svelte index ba04473b..800871f0 100644 --- a/src/App.svelte +++ b/src/App.svelte @@ -63,6 +63,7 @@ const tableHeaders = ['Date', 'Hours', 'Time Remaining Until Goal', 'Delete'] p { text-align: center; + color: white } /* h1 { diff --git a/src/lib/GoalSide.svelte b/src/lib/GoalSide.svelte index 829efb72..e35d1e99 100644 --- a/src/lib/GoalSide.svelte +++ b/src/lib/GoalSide.svelte @@ -199,6 +199,7 @@ border-style: solid; border-color: #beffa6; text-align: center; + color: white } .B { @@ -206,6 +207,7 @@ border-style: solid; border-color: #e3ffa6; text-align: center; + color: white } .C { @@ -213,6 +215,7 @@ border-style: solid; border-color: #fbf3a3; text-align: center; + color: white } .NR { @@ -220,6 +223,7 @@ border-style: solid; border-color: #fbb7a3; text-align: center; + color: white } .contrast:focus-visible { @@ -232,5 +236,6 @@ p { text-align: center; + color: white; } diff --git a/src/lib/TableSide.svelte b/src/lib/TableSide.svelte index c9768639..05cc18fc 100644 --- a/src/lib/TableSide.svelte +++ b/src/lib/TableSide.svelte @@ -109,11 +109,20 @@ padding: 4px; } + th,td{ + color: white + } + + form{ + color: white + } + button { text-decoration: underline; } p { text-align: center; + color: white }