Skip to content

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

Description

@dessalines

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.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    2 - low/medium priorityThis issue is not planned to be implemented soonenhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions