-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added some comments to the code #11
base: main
Are you sure you want to change the base?
Changes from 4 commits
af8df5a
4242b8b
0b8ef1b
753e834
2145d54
3997fc1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
//The name and code suggests this file does the spreadsheet/server stuff | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah this file has the function get to fetch the data from the spreadsheet and get it in the correct shape for using in the site, and then also append which turns the response queue into what the server wants. The server is in server/server.js I think and on get requests grabs match data from the sheet as well as the form schema. On post requests it appends each row of data (comes in a list of lists) after the last row of data in a sheet that we specify |
||
|
||
import { form, keys, lastGet, matches, teams } from "$lib/store"; | ||
import type { | ||
Group, | ||
|
@@ -13,6 +15,7 @@ import type { | |
import { get as getStore } from "svelte/store"; | ||
import { PUBLIC_API_URL } from "$env/static/public"; | ||
|
||
//gets data from spreadsheet | ||
export const get = async () => { | ||
try { | ||
const response = await fetch(PUBLIC_API_URL); | ||
|
@@ -35,6 +38,7 @@ export const get = async () => { | |
} | ||
}; | ||
|
||
//Formats app data so it can be sent to the spreadsheet | ||
export const append = async (responseQueue: Response[]) => { | ||
try { | ||
await fetch(PUBLIC_API_URL, { | ||
|
@@ -59,6 +63,8 @@ export const append = async (responseQueue: Response[]) => { | |
return false; | ||
} | ||
}; | ||
|
||
//this is where the form gets set | ||
const setForm = ( | ||
sections: string[][], | ||
config: string[][], | ||
|
@@ -201,5 +207,6 @@ const setMatches = (match_array: number[][]) => { | |
matches.set(match_obj); | ||
}; | ||
|
||
//Im not really sure what this does but it is necessary for setform | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a matrix transpose the data is in a 2d array but the columns and rows are incorrect for what we want to do because Google sheets gives us an array of columns but we want an array of rows I think that's what it is atleast haven't touched this code in a while |
||
const transpose = <T>(matrix: T[][]) => | ||
matrix[0].map((_, i) => matrix.map((array) => array[i])); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,24 +3,50 @@ import type { Form, Response, Team, Match, Field } from "$lib/types"; | |
import { persisted } from "svelte-local-storage-store"; | ||
import { extractGroups } from "./serialize"; | ||
|
||
//Details of which type of form is being used | ||
export const form = persisted<Form | null>("form", null); | ||
|
||
//for autofilling form creation data | ||
export const scout = persisted<string>("scout", ""); | ||
export const teams = persisted<Record<number, Team>>("teams", {}); | ||
export const matches = persisted<Record<number, Match>>("matches", {}); | ||
Comment on lines
10
to
12
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These are for autocomplete when adding a new response, scout saves the name so you don't have to type it in again, and teams and matches is used to have a dropdown for them |
||
|
||
//The currently active response (the one the user sees on the form page) | ||
export const response = persisted<number | null>("response", null); | ||
|
||
//ID of the response we are displaying the QR code of | ||
export const code = persisted<number | null>("code", null); | ||
|
||
//list of responses which are "active" eg. can be edited (not yet submitted) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Important part is that this is also structured as a map from the response id to the response, which is useful because we use the id in a bunch of places to refer to the response we are using |
||
//Structured as a map of ids to responses | ||
export const activeResponses = persisted<Record<number, Response>>( | ||
"activeResponses", | ||
{} | ||
); | ||
|
||
//something to do with grid, shouldn't be necessary this year | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah so the grid won't be necessary but if there is a need for a form field that needs multiple data points then let me know because that is why the grid is much more complicated and needs special handling |
||
export const fields = persisted<Record<number, Record<string, Field>>>( | ||
"fields", | ||
{} | ||
); | ||
|
||
//This is used for formatting responses before they are sent to the server (not quite sure how though) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the order of the keys because JavaScript objects aren't ordered when we take the data from it we want them to be in the correct order for the server |
||
export const keys = persisted<string[]>("keys", []); | ||
|
||
//list of QRs that have already been scanned so they don't get scanned twice | ||
export const scans = persisted<number[]>("scans", []); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah this is just a list of the ids of responses we have already scanned so we don't double scan anything and send it twice to the sheet |
||
|
||
//list of submitted responses waiting to go to server | ||
export const responseQueue = persisted<Response[]>("responseQueue", []); | ||
|
||
//the time that the get function was last called? not sure what get does yet | ||
export const lastGet = persisted("lastGet", 0); | ||
|
||
//check is device connected to internet (writable only works online) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like I don't actually use this at all, but both get and append in sheet.ts instead of causing an error when offline will just return false, which for append is important cause only if it returns true do we know it's safe to remove the submitted responses from the response queue |
||
export const online = writable(true); | ||
|
||
//colour theme stuff, not necessary | ||
export const theme = persisted("theme", "arctos"); | ||
|
||
//looks like a list of IDs and boolean values for whether or not those forms have errors? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah if a form has any errors then we want to be able to disable the submit button in the home page, key thing here is we initially set the error to true when we create a new response because fields won't populate with default values till the form is actually opened |
||
export const errors = persisted<Record<number, boolean>>("errors", {}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,3 +20,4 @@ | |
</div> | ||
</div> | ||
{/if} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you update sveltekit then you will probably need to update vitepwa/sveltekit as well, does it still build properly with this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It still builds properly. I think I have a whole bunch of stuff thats been updated since polaris was made in this commit, but it doesn't seem to have any impact.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah no worries if something breaks I can push a hotfix for it