Skip to content

TA Announcements

danakim21 edited this page Dec 4, 2022 · 3 revisions

TA Announcements

TA Announcements is a feature that the TA / Professors can use to share announcements to a particular session. A TA / Professor should be able to post a new announcement, delete an announcement, and view other announcements. A student should be able to view all current announcements.

Props

The component requires a user prop with type FireUser and a session prop with type FireSession. Since the two information are stored in the redux store, the current TA Announcements component receive from the redux store.

State

showBody

This state is a boolean controlling whether the body of the TA announcements section shows or not. The body can show either the current announcement list or a text box for adding a new announcement -- [true] for visible, [false] for not rendered.

showAnnouncements

This state is a boolean controlling whether the list of announcements is shown or not -- [true] for visible, [false] for not rendered.

showNewAnnouncement

This state is a boolean controlling whether the new announcement text box is shown or not -- [true] for visible, [false] for not rendered.

announcementContent

This state is a string controlling the content of the new announcement

taAnnouncements

This state is a type of TaAnnouncement[] which stores the list of current announcements for the session

Functions

clickCircleIcon

  • Parameters: None
  • Runtime: O(1)
  • Returns: void
  • This function is triggered when the circle plus icon is clicked. It sets the body to show by setting showBody to true and sets showNewAnnouncements to true and showAnnouncements to false so that the list of announcements are shown first.

collapseBody

  • Parameters: None
  • Runtime: O(1)
  • Returns: void
  • This function is triggered when the chevron button is clicked. It may either collapse the body or not, so it sets showBody to false if it was set to true, and sets it to true if it was set to false.

enterAnnouncement

  • Parameters: e, which corresponds to the React.ChangeEvent<HTMLInputElement> type
  • Runtime: O(1)
  • Returns: void
  • This function is triggered whenever a TA / professor edits the current announcement. It sets the input text as the announcementContent value.

onClickCancelButton

  • Parameters: None
  • Runtime: O(1)
  • Returns: void
  • This function is triggered when the cancel button is clicked while a TA / professor was inputting a new announcement. It sets the announcementContent back to an empty string and collapses the entire body.

onClickPostButton

  • Parameters: None
  • Runtime: O(n) where n is the number of current announcements
  • Returns: void
  • This function is triggered when a TA / professor clicks on the post button for posting a new announcement. It triggers the backend function addTaAnnouncement and successfully adds a new announcement.

deleteAnnouncement

  • Parameters: announcement of type string, uploadTime of type FireTimeStamp
  • Runtime: O(n) where n is the number of current announcements
  • Returns: void
  • This function is triggered when a TA / professor deletes an announcement. It triggers the backend function deleteTaAnnouncement and successfully deletes the announcement.

getTimeDifference

  • Parameters: announcement of type TaAnnouncement
  • Runtime: O(1)
  • Returns: number
  • This function returns the time difference between the current time and when the announcement was posted.

useEffect

  • The useEffect sets the taAnnouncements