Skip to content

Conversation

@xenonnn4w
Copy link
Contributor

@xenonnn4w xenonnn4w commented Jan 13, 2026

Purpose / Description/ Approach

This PR adds the foundational infrastructure without changing existing behavior:

  • CardTemplateEditorState: Immutable data class holding UI state (loading, current template ordinal, editor view, errors, messages)
  • CardTemplateEditorViewModel: Manages state via StateFlow with thread-safe updates
  • CardTemplateEditorViewModelTest: Unit tests covering all state operations

This is Part 1 of a multiPR migration:

PR 1 (this): Infrastructure (ViewModel + State) [Done]
PR 2: Wire ViewModel to UI
PR 3: Load notetype + Template manipulation in-memory
PR 4: Atomic save with updateNotetype()
PR 5: Remove legacy code

Links without closing (Part of)

Checklist

Please, go through these checks before submitting the PR.

  • You have a descriptive commit message with a short title (first line, max 50 chars).
  • You have commented your code, particularly in hard-to-understand areas
  • You have performed a self-review of your own code
  • UI changes: include screenshots of all affected screens (in particular showing any new or changed strings)
  • UI Changes: You have tested your change using the Google Accessibility Scanner

Copy link
Member

@david-allison david-allison left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really understand what the abstraction will turn out to be.

Mostly seems fine, even if it's just starting to move the screen to a ViewModel

@david-allison david-allison added the Needs Author Reply Waiting for a reply from the original author label Jan 16, 2026
Introduce CardTemplateEditorViewModel and CardTemplateEditorState as
the foundation for migrating CardTemplateEditor to use the Rust
backend's atomic updateNotetype() API.

Part 1 of migration, infrastructure only, no behavioral changes yet.
Copy link
Member

@david-allison david-allison left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't want to block forward progress on nitpicks, especially as this change does not affect production functionality.

This should be the last 'change request' before an approve.

Thanks!!!

* Transitions to the Loaded state.
* Called internally after data is successfully loaded.
*/
internal fun onLoadComplete() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VisibleForTesting

I'm concerned we're testing at the wrong level of abstraction. (this is non-blocking; It's hard when there are few 'public' methods; we should be testing these private methods through public methods).

I suspect VisibleForTesting will be removed later down the line and the tests should be reworked.

internal should ideally be private, as the 'view' classes are in the same module.

viewModel.onLoadComplete()

val state = viewModel.state.value
assertTrue(state is CardTemplateEditorState.Loaded)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assertInstanceOf<CardTemplateEditorState.Loaded> should work and return the value


@Test
fun `initial state is Loading`() {
val viewModel = createViewModel()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider a withViewModel helper, or setting a field in the constructor.

createViewModel is called in each test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Card Template Editor Needs Author Reply Waiting for a reply from the original author Needs Review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants