Skip to content

A class join whose screen is gone before it lands leaves its result behind, and the next «Добавить класс» sheet closes itself on it #161

Closed

Description

@lumenpearson

What is broken. JoinViewModel reports a successful join through a one-shot, joined, and the screen that sent the code consumes it. JoinViewModel lives in the activity's ViewModelStore, so the value outlives any one screen. It is set only after sessionRepository.join(...) and the first timetableRepository.refresh() have run.

The session write alone flips the app's root gate and throws away the screen that sent the code. The one-shot then lands with nobody composed to consume it, and it stays. The next consumer is whichever join UI opens next in the same activity. That is Settings → «Классы» → «Добавить класс», whose LaunchedEffect reads the stale id and closes the sheet before anything can be typed. JoinScreen.kt's own comment records a defect of this shape as fixed.

On main (fa4fe0c). The path is the first-run join.

  1. The class code is entered.
  2. JoinViewModel.submit writes the session (JoinViewModel.kt:196-214).
  3. LessonsApp's signed-in gate swaps the first run for the home (navigation/LessonsApp.kt:178-199) while refresh() is still out.
  4. joined lands on nothing.
  5. Opening «Добавить класс» later in the same activity closes the sheet at once.

This was established by reading the code in that order, not by running main on a device.

Widened on PR #140's branch. Two more paths reach it before its fix:

  • From the diary home. A diary-only phone joins a class from Settings → «Дневник» → «Подключиться к классу по коду». The mode flips DIARY → CLASS, key(home) disposes the whole diary shell and the sheet with it, and the one-shot is orphaned.
  • In the first run. If it survives into the first run's class-code step (leave the class, sign out of the diary, choose «По коду класса»), JoinScreen hands the stale id to OnboardingViewModel.onJoined. With no class stored that calls finish(), which releases the hold the step had just taken. A real join afterwards drops straight to the home and never offers the class's diary sign-in.

Fix. Every join reports under a ticket that the sending screen keeps. A screen acts only on its own ticket and consumes and drops anyone else's, and a successful join clears the typed code. Lands on PR #140's branch with JoinOneShotTest, which fails when the ticket check is reverted («the sheet closed on a join it never sent expected:<0> but was:<1>»).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    • Status
      Done

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions