store.main. actions

The actions to manipulate the store state

Methods

(static) add_class(teacher_email, class_id, class_name, class_period) → {Promise}

Add a class to the active user's document, and show a toast saying that the class was added

Parameters:
NameTypeDescription
teacher_emailString

The email of the teacher whose class it is

class_idString

The id of the class to add

class_nameString

The name of the class being added

class_periodNumber

The period of the class being added

See
  • classes
Returns:

A promise that resolves to nothing or rejects with an {String} error

Type: 
Promise

(static) archive_task(task_ref) → {Promise}

Archive an instance of a task from a class (for teachers). Intended to be preformed from the ViewTask Modal

Parameters:
NameTypeDescription
task_refString

the "email/class_id" String representation of the task ref in firebase

See
  • create_task
Returns:

A promise that resolves to nothing or rejects with an {String} error

Type: 
Promise

(static) class_from_ref(ref) → {Promise}

Get the class object from a class reference

Parameters:
NameTypeDescription
refString

The class reference to get the class object from

Returns:

A promise that resolves to the class object or rejects with an error

Type: 
Promise

(static) class_text(class_obj) → {String}

get the smart text associated with a given class

Parameters:
NameTypeDescription
class_objString
Returns:

text - the formatted name text associated with the class data

Type: 
String

(static) clear()

Reset the store state and local storage, and redirect to home if page requires auth

(static) code_from_ref(ref)

Create a proxy code from a ref (email/uid)

Parameters:
NameTypeDescription
refString

ref in email/uid format

See
  • hash

(static) create_class(class_obj) → {Promise}

Create a class with the given object, and add it to the active user's document. (for teachers)

Parameters:
NameTypeDescription
class_objObject

The class object to with the class data, document will be created in /classes under the teacher's email with these contents

See
  • is_teacher
  • teacher
Returns:

A promise that resolves to nothing or rejects with an {String} error

Type: 
Promise

(static) create_doc()

Create the user's document in the remote database, create a teacher document if the user is a teacher, and create a personal account if the user is using a personal account. Also preforms onboarding for non-teacher

See
  • create_teacher_doc
  • update_remote
  • get_remote

(static) create_task(task_obj, task_classes) → {Promise}

Create a task with the given object, and add it to the classes specified in the object. (for teachers)

Parameters:
NameTypeDescription
task_objObject

The task object to with the task data, data will be added to /classes docs

task_classesArray

The classes to add the task to

Returns:

A promise that resolves to nothing or rejects with an {String} error

Type: 
Promise

(static) create_teacher_doc()

Create the teacher document for the user, and redirect to the create class page

See
  • create_doc
  • is_teacher

(static) doc_from_uid(uid) → {Promise}

Get a user document from a uid

Parameters:
NameTypeDescription
uidString

The uid of the user to get the document for

See
  • getDoc
  • link_account_uid
Returns:

A promise that resolves to the {Object} user document or rejects with an {String} error

Type: 
Promise

(static) fetch_classes() → {Array}

Fetch all classes from the user's document and combine them into an array, while checking for duplicates and invalid classes

See
  • classes
  • fetch_classes_by_email
  • remove_invalid
  • remove_class
  • remove_class_id_helper
Returns:

Array of all (unique) classes from the user's document

Type: 
Array

(static) fetch_classes_by_email(email)

Fetch all classes for a given email, and set the loaded classes to the result

Parameters:
NameTypeDescription
emailString

The email to fetch classes for

See
  • loaded_classes
  • loaded_email
  • fetch_classes

(static) finish_tutorial() → {Promise}

Set the user's tutorial status to finished

See
  • done_tutorial
Returns:

A promise that resolves to nothing or rejects with an {String} error

Type: 
Promise

(static) get_cached_surveys(dates) → {Promise}

Get the survey data for the given dates for this user, using the cached data in the active doc. If the data does not include the given dates, get the data from the server and save it to use as the cashe

Parameters:
NameTypeDescription
datesArray

Array of dates to get the survey data for

See
  • save_daily_survey
  • done_daily_survey
Returns:

Promise resolving to survey data for the given dates, with date objects added to each object

Type: 
Promise

(static) get_remote()

Get the user's document from the remote database, and create it if it doesn't exist. Preforms additional checks for personal accounts, and removes the linked account if it doesn't exist

See
  • create_doc
  • update_remote
  • active_doc

(static) get_surveys(dates) → {Array}

Get the survey data for the given dates for this user

Parameters:
NameTypeDescription
datesArray

Array of dates to get the survey data for

See
  • save_daily_survey
  • done_daily_survey
Returns:

The survey data for the given dates, with date objects added to each object

Type: 
Array

(static) get_tasks() → {Promise}

Get all tasks from all classes

Default Value
  • []
See
  • fetch_classes
Returns:

Promise that resolves to Array of all tasks from all classes, with class name and color added

Type: 
Promise

(static) hash(ref) → {String}

Parameters:
NameTypeDescription
refString

ref in email/uid format

See
  • code_from_ref
Returns:

6-character code from ref

Type: 
String

(static) hide_timeout()

Hide the popup saying that the session has timed out

See
  • show_timeout
  • refresh_timeout

(static) invite_linked(email) → {Promise}

Invite a user account to link to another user's account (for personal accounts only,) including sending them an email with the code to join

Parameters:
NameTypeDescription
emailString

The email of the user to invite (and send an invite email to)

Returns:

A promise that resolves to nothing or rejects with an {String} error

Type: 
Promise

Link a user account to another user's account by uid (for personal accounts only)

Parameters:
NameTypeDescription
uidString

The uid of the user to link to

See
  • invite_linked
Returns:

A promise that resolves to nothing or rejects with an {String} error

Type: 
Promise

(static) login() → {Promise}

Log the user in with Google OAuth (using the appropriate prompt type based on window support), and set the user object.

See
  • user
  • logout
Returns:

A promise that resolves to nothing or rejects with an {String} error

Type: 
Promise

(static) login_personal() → {Promise}

Most things that login() does, but for personal accounts (does not preform org account check, enforce sign-in domain, or redirect)

See
  • personal_account
  • user
  • login
Returns:

A promise that resolves to nothing or rejects with an {String} error

Type: 
Promise

(static) login_promise() → {Promise}

A wrapper for the store.user state, to wait for the user to be set

See
  • user
  • login
Returns:

A promise that resolves to the user object

Type: 
Promise

(static) logout()

Log the user out and clear the store state

See
  • clear

(static) note_for(ref) → {String}

Get the note for the given ref

Parameters:
NameTypeDescription
refString

The ref of the task to get the note for

See
  • set_note
  • notes
Returns:

The note for the given ref

Type: 
String

(static) path_to_ref(path) → {String}

Convert a path to a ref (email~class_id?~task_id)

Parameters:
NameTypeDescription
pathString

The path to convert

Default Value
  • null
Returns:

The ref (email~class_id?~task_id)

Type: 
String

(static) ref_from_code(code) → {Promise}

Get the ref (email/uid) from a code

Parameters:
NameTypeDescription
codeString

The code to get the ref for

Returns:

A promise that resolves to the ref (email/uid) or rejects with an error

Type: 
Promise

(static) ref_to_path(path) → {String}

Convert a ref to a path (email/class_id?/task_id)

Parameters:
NameTypeDescription
pathString

The path to convert

Default Value
  • null
Returns:

The ref (email/class_id?/task_id)

Type: 
String

(static) refresh_timeout(delay)

A proxy for the refreshTimeout function in firebase.ts (to reduce unnecessary onSnapshot calls)

Parameters:
NameTypeDescription
delayNumber

The delay in milliseconds to refresh the timeout for (default 1000 set in firebase.ts)

See
  • refreshTimeout

(static) remove_class()

Remove a class from the active user's document, and show a toast saying that the class was removed manually

See
  • remove_class_id_helper

(static) remove_class_id_helper()

Helper function to remove a class from the active user's document and save changes to remote

See
  • remove_class
  • remove_invalid
  • fetch_classes

(static) remove_invalid()

Remove a class from the active user's document, and show a toast saying that the class was removed because it was invalid

See
  • remove_class_id_helper

(static) report_logs() → {Promise}

save logs to server for debugging later, with some session data attached

Returns:
Type: 
Promise

(static) save_daily_survey(responses) → {Promise}

Save the responses from the daily survey to the active user's document

Parameters:
NameTypeDescription
responsesObject

The responses from the daily survey to save

See
  • done_daily_survey
Returns:

A promise that resolves to nothing or rejects with an {String} error

Type: 
Promise

(static) save_join_form(responses) → {Promise}

Save the responses from the join form to the active user's document

Parameters:
NameTypeDescription
responsesObject

The responses from the join form to save

Returns:

A promise that resolves to nothing or rejects with an {String} error

Type: 
Promise

(static) set_account_pref(pref, value) → {Promise}

Set a preference in the account doc

Parameters:
NameTypeDescription
prefString

The preference to set

valueString

The value to set the preference to

Returns:

A promise that resolves to nothing or rejects with an {String} error

Type: 
Promise

(static) set_active(data)

Set the active document (the signed-in account's doc, or the linked account's if it exists) to the provided document

Parameters:
NameTypeDescription
dataObject

The document data to replace the active document (account_doc or linked_doc) with

(static) set_finished(finished, ref) → {Promise}

set a task with the given ref to finished in the finished array of the active doc (remove if finished is false, add path if finished is true)

Parameters:
NameTypeDescription
finishedBoolean

The finished status to set

refString

The ref of the task to check

See
  • is_finished
Returns:

A promise that resolves to nothing or rejects with an {String} error

Type: 
Promise

(static) set_note(note, ref) → {Promise}

set a task with the given path to have a note in the keyed "notes" property of the active doc (remove if value is falsey, add note if truthy)

Parameters:
NameTypeDescription
noteString

The note to set

refString

The ref of the task to set the note for

See
  • note_for
  • notes
Returns:

A promise that resolves to nothing or rejects with an {String} error

Type: 
Promise

(static) set_user()

Set the user object and load the user's document, with some additional checks and error handling. Also set the user's document if it exists, or create it if it doesn't, and logs them out if the account is deemed invalid

See
  • user
  • authChangeAction
  • account_doc
  • linked_account_doc
  • personal_account

(static) show_timeout()

Show a popup saying that the session has timed out

See
  • hide_timeout
  • refresh_timeout

(static) task_from_ref(ref) → {Promise}

Get the task object from a task reference

Parameters:
NameTypeDescription
refString

The task reference to get the task object from

Returns:

A promise that resolves to the task object or rejects with an {String} error

Type: 
Promise

(static) toggle_simplified()

Toggle the simplified display view

See
  • account_doc

(static) toggle_teacher() → {Promise}

Toggle teacher mode (for testing)

See
  • is_teacher
Returns:

A promise that resolves to nothing or rejects with an {String} error

Type: 
Promise

(static) toggle_theme()

Toggle the theme between light and dark, and save to local storage and user account doc

See
  • get_theme
  • theme

(static) uninvite_linked() → {Promise}

Unlink a user account from another user's account (for personal accounts only)

See
  • invite_linked
Returns:

A promise that resolves to nothing or rejects with an {String} error

Type: 
Promise

(static) upcoming_from_ref(ref, class_obj)

Get the next 4 upcoming task objects for a given class reference

Parameters:
NameTypeDescription
refString
class_objObject

(static) update_class(class_ref, class_obj) → {Promise}

Update an instance of a class (for teachers). Intended to be preformed from the EditClass Modal

Parameters:
NameTypeDescription
class_refString

the "email/class_id" String representation of the class ref in firebase

class_objObject

The updated class object

Returns:

A promise that resolves to nothing or rejects with an error

Type: 
Promise

(static) update_remote()

Update the active user's document in the remote database

See
  • get_remote
  • active_doc
  • active_ref

(static) update_task(task_ref, task_obj) → {Promise}

Update an instance of a task from a class (for teachers). Intended to be preformed from the EditTask Modal

Parameters:
NameTypeDescription
task_refString

the "email/class_id/task_id" String representation of the task ref in firebase

task_objObject

The updated task object

Returns:

A promise that resolves to nothing or rejects with an {String} error

Type: 
Promise

(static) update_wrapper_acc_doc()

Update the authenticated user's document in the remote database (for personal accounts only)

See
  • update_remote
  • personal_account

(static) update_wrapper_acc_doc()

Update the authenticated user's document in the remote database with the data given (for personal accounts only)

See
  • update_remote
  • personal_account
  • update_wrapper_acc_doc