Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: refactor of thumbnail badges and compact post cards #1066

Merged
merged 1 commit into from
Jan 18, 2024

Conversation

hjiangsu
Copy link
Member

Pull Request Description

This PR refactors some of the existing logic with post cards. The reasoning for this is to reduce dependencies across widgets, and to clean up some duplicated code. This will be one of many refactors for post cards to help reduce code complexity.

Main changes performed:

  • Removed unnecessary parameters for PostCardViewCompact. A lot of the current parameters that are passed in can be derived from ThunderBloc. As such, it's unnecessary to pass that data down the widget tree.
  • Complete refactor of TypeBadge to reduce duplicated code. TypeBadge no longer has a dependency on PostViewMedia, which will help in certain situations. Rather, it will have a more generic parameter MediaType which will determine the look of the badge.
  • The thumbnail logic has been moved to a separate widget ThumbnailPreview. This helps with reducing duplicated code, and allows us to use ThumbnailPreview elsewhere in the app if needed.

Sidenote: Moderator post reports /post/report/list only returns back a Post rather than a PostView. Because of this, a lot of our existing widgets are not compatible with the response of moderator reports since they take in PostViewMedia. This is one of the initial triggers for refactoring the post cards.

e.g., an example response of /post/report/list

{
  "post_report": {
    "id": 2975,
    "creator_id": 2290976,
    "post_id": 10174984,
    "original_post_name": "Images",
    "original_post_body": "Same instance pictrs: https://lemmy.ca/pictrs/image/4ee47284-643a-434a-9e38-1fb49317aad4.webp?format=webp\n\nDifferent instance pictrs: https://lemmy.world/pictrs/image/aa5c4b44-7b27-4564-8557-67177c1e6dbf.png?format=webp\n\nImgur: https://i.imgur.com/UCYJhaY.jpeg\n\nCatbox: https://files.catbox.moe/1no740.png",
    "reason": "Testing moderation reporting",
    "resolved": false,
    "published": "2024-01-17T18:38:03.738424Z"
  },
  "post": {
    "id": 10174984,
    "name": "Images",
    "body": "Same instance pictrs: https://lemmy.ca/pictrs/image/4ee47284-643a-434a-9e38-1fb49317aad4.webp?format=webp\n\nDifferent instance pictrs: https://lemmy.world/pictrs/image/aa5c4b44-7b27-4564-8557-67177c1e6dbf.png?format=webp\n\nImgur: https://i.imgur.com/UCYJhaY.jpeg\n\nCatbox: https://files.catbox.moe/1no740.png",
    "creator_id": 1841487,
    "community_id": 171412,
    "removed": false,
    "locked": false,
    "published": "2023-11-27T18:40:36.188614Z",
    "deleted": false,
    "nsfw": false,
    "ap_id": "https://lemmy.ca/post/10174984",
    "local": true,
    "language_id": 0,
    "featured_community": false,
    "featured_local": false
  },
  "community": {
    "id": 171412,
    "name": "testing",
    "title": "Testing",
    "description": "![Testing badge markdown](https://img.shields.io/badge/Welcome_to-testing-blue)\n\n![Generic SVG](https://dev.w3.org/SVG/tools/svgweb/samples/svg-files/410.svg)",
    "removed": false,
    "published": "2023-08-25T02:39:56.218540Z",
    "updated": "2024-01-17T16:15:58.788730Z",
    "deleted": false,
    "nsfw": false,
    "actor_id": "https://lemmy.ca/c/testing",
    "local": true,
    "icon": "https://lemmy.ca/pictrs/image/562792f5-0f2b-4a0e-addf-0fbd7b519a41.jpeg",
    "hidden": false,
    "posting_restricted_to_mods": false,
    "instance_id": 119
  },
  "creator": {
    "id": 2290976,
    "name": "darklightxi",
    "banned": false,
    "published": "2023-08-08T17:30:14.773260Z",
    "actor_id": "https://lemmy.ca/u/darklightxi",
    "local": true,
    "deleted": false,
    "bot_account": false,
    "instance_id": 119
  },
  "post_creator": {
    "id": 1841487,
    "name": "ThunderDevTesting",
    "avatar": "https://lemmy.ca/pictrs/image/2505d14a-a600-4c9a-9936-6526c72c2b65.webp",
    "banned": false,
    "published": "2023-07-28T03:55:21.129462Z",
    "actor_id": "https://lemmy.ca/u/ThunderDevTesting",
    "local": true,
    "deleted": false,
    "bot_account": false,
    "instance_id": 119
  },
  "creator_banned_from_community": false,
  "counts": {
    "post_id": 10174984,
    "comments": 0,
    "score": 0,
    "upvotes": 1,
    "downvotes": 1,
    "published": "2023-11-27T18:40:36.188614Z",
    "newest_comment_time": "2023-11-27T18:40:36.188614Z"
  }
}

Issue Being Fixed

Issue Number: N/A

Screenshots / Recordings

Checklist

  • Did you update CHANGELOG.md?
  • Did you use localized strings where applicable?
  • Did you add semanticLabels where applicable for accessibility?

Copy link
Member

@micahmo micahmo left a comment

Choose a reason for hiding this comment

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

LGTM! The main things I would check are that the color gets correctly dimmed when the post is marked as read, and that everything looks good in compact post body view as well.

@hjiangsu
Copy link
Member Author

The main things I would check are that the color gets correctly dimmed when the post is marked as read, and that everything looks good in compact post body view as well.

Just double checked and it looks good!

@hjiangsu hjiangsu merged commit 86942ed into develop Jan 18, 2024
1 check passed
@hjiangsu hjiangsu deleted the refactor/post-card branch January 18, 2024 19:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants