Skip to content

Lesson Plan API

Sarah Xu edited this page Mar 29, 2023 · 14 revisions

LessonPlan

Psst: here's how to test your local storage calls!

saveLessonPlan

  • Store a lesson plan on the app’s local backend
  • Saves object to JSON structure as "LESSON_NAME.json" using RNFS.writeFile:
{
  "name": "lesson_name",
  "warmUp": [
    {
      "type": "text",
      "name": "text",
      "content": "warmup1"
    },
    {
      "type": "activity",
      "name": "C Sharp",
      "content": "dir/path/to/card"
    }
  ],
  "mainLesson": [],
  "coolDown": [],
  "notes": ["note1", "note2"]
}

Signature

static saveLessonPlan(lesson: LessonPlan): none

Returns

  • Returns none

getLessonPlan

  • Creates and returns a LessonPlan object
  • Check for JSON using RNFS.exists and RNFS.readFile, destructure into new object, store into local storage
  • If the name/file does not exist, then error is thrown

Signature

static getLessonPlan(name: str): lesson

Returns

  • Returns LessonPlan object

getAllLessonPlanNames

  • Returns an array of LessonPlan names. Does not require the content of each LessonPlan
  • Reads each LessonPlan name using RNFS.readFile
  • If no LessonPlans exist, error is thrown

Signature

static getAllLessonPlanNames(): string []

Returns

  • Returns array

setLessonPlanName

  • Rename a lesson plan. Throws an error if the lesson plan doesn’t exist or if renamed to an existing name
  • Uses RNFS.moveFile() with the original filename and the new filename

Signature

static setLessonPlanName(old_name: str, new_name: str): none

Returns

  • Returns none

deleteLessonPlan

  • Delete a lesson plan using the lesson plan name
  • Uses RNFS.unlink() with the filepath and lesson name

Signature

static deleteLessonPlan(name: str): none

Returns

  • Returns none

favouriteLessonPlan

  • Move a given lesson plan from the Default directory into the Favourited directory
  • Uses RNFS.moveFile()
  • Make sure to check the lesson plan already exists first!

Signature

static favouriteLessonPlan(name: str): none

Returns

  • Returns none

unFavouriteLessonPlan

  • Move a given lesson plan from the Favourited directory into the Default directory
  • Uses RNFS.moveFile()
  • Make sure to check the lesson plan already exists first!

Signature

static unFavouriteLessonPlan(name: str): none

Returns

  • Returns none