wongjiahau / ttap-web

This is repo for storing codes of TTAP(UTAR)-Web version
https://get-ttap.surge.sh
MIT License
6 stars 9 forks source link

fix(select-alternative-slots): sometimes will crash the app #193

Closed wongjiahau closed 3 years ago

wongjiahau commented 3 years ago

Root Cause (this is not entirely correct, need to also read comments below)

This is probably because the algorithm for findAlternativeSlots and goToThisAlternativeSlot is buggy, due the frequent usage of for loops and array indexing. Not only does this algorithm crash the app sometimes, it is actually incomplete, in the sense that it will not search for all possible destination timetables for each slot.

Solution

First of all, we ned to remove for loops and and array indexing (which will incur performance cost). Secondly, the main flow of this feature needs to be changed to minimise the performance impact.

Old flow

When view a new timetable, find all the alternatives slots for each slot of the current timetable. Because of this, showing alternative slots and going alternative slot is almost costless.

New flow

Because the new algorithm utilises only higher order functions like filter, map, reduce, and this algorithm aims to be complete (see above for what incomplete mean). Thus, the new flow is as follows: When view a new timetable, only find out which slots has alternative slots (which means the search loop can stop whenever we find a first alternative timetable), then we will only search for all destination timetables when user want to show the alternative slots of a particular slot.

wongjiahau commented 3 years ago

Notes

In the end, the New flow is not used, because it is hard to implement, so after the fix, the Old flow is still being used.

wongjiahau commented 3 years ago

I found the actual problem that caused the crash.

Steps to reproduce

  1. Select FM2
  2. Click on FM2-P1 to show its alternative slots.
  3. Without closing the alternative slots of FM-P1, click on FM2-T1

Expected result

App don't crash

Actual result

Notice some of the red lines point to the top left corner. image

After this screen is reached, clicking on any of the slots will crash the app, resulting in whitescreen.

wongjiahau commented 3 years ago

Closed by d9c31f80a023ffeca5872076a918a4e4c5521ff4