LemmyNet / LemmyNet/jerboa

Pass up API forms instead of large objects to top level screens

Open
#2,168 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

2 - low/medium priority enhancement
Dominant language
Kotlin
Stars
1.3k
Forks
175
Avg merge
6d 22h
Merged PRs (30d)
9

Description

Pre-Flight checklist
  • Did you check to see if this issue already exists?
  • This is a single feature request. (Do not put multiple feature requests in one issue)
  • This is not a question or discussion. (Use https://lemmy.ml/c/jerboa for that)
Describe The Feature Request Below

Looking at PostListings.kt, it looks like we're currently passing up larger objects for actions, instead of forms. IE:

onUpvoteClick: (postView: PostView) -> Unit

We then have to do the logic of building the API form manually in a top-level component like HomePane.kt.

homeViewModel.likePost(
  CreatePostLike(
    post_id = postView.post.id,
    score = newVote(postView.post_actions?.like_score ?: 0, VoteType.Upvote),
   ),
)

A better pattern from lemmy-ui, is simply to pass up the form itself, so that top-level components don't have to do any logic:

onUpvoteClick: (form: CreatePostLike) -> Unit

Then we can simply do viewModel.likePost(form), and there's no chance of any mistakes or manipulations.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading PostListings.kt and HomePane.kt, focusing on callbacks that currently pass PostView objects and construct API forms in the top-level screen. Trace the related ViewModel calls and compare the pattern with the issue's CreatePostLike example. Done means the relevant action callbacks pass their API forms directly and top-level components no longer build those forms themselves.

Written by the indexing model from the issue text.

Assessment

Tech stack
kotlin
Domain
mobile
Issue type
Refactor
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
58/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.