From be939c90a929b25efaae4df95f5e0eb5f36433c9 Mon Sep 17 00:00:00 2001 From: Dessalines Date: Sat, 26 Sep 2020 11:18:49 -0500 Subject: [PATCH] Fixing saved / starred. Fixes #42 --- src/shared/components/post-listing.tsx | 587 +++++++++++++------------ src/shared/components/user.tsx | 15 + 2 files changed, 315 insertions(+), 287 deletions(-) diff --git a/src/shared/components/post-listing.tsx b/src/shared/components/post-listing.tsx index 0f56d22..e3e75dd 100644 --- a/src/shared/components/post-listing.tsx +++ b/src/shared/components/post-listing.tsx @@ -54,6 +54,7 @@ interface PostListingState { imageExpanded: boolean; viewSource: boolean; showAdvanced: boolean; + showMoreMobile: boolean; my_vote: number; score: number; upvotes: number; @@ -85,6 +86,7 @@ export class PostListing extends Component { imageExpanded: false, viewSource: false, showAdvanced: false, + showMoreMobile: false, my_vote: this.props.post.my_vote, score: this.props.post.score, upvotes: this.props.post.upvotes, @@ -493,7 +495,7 @@ export class PostListing extends Component { commentsLine(mobile: boolean = false) { let post = this.props.post; return ( -
+
- {!mobile && this.state.downvotes !== 0 && ( - + {!mobile && ( + <> + {this.state.downvotes !== 0 && ( + + )} + {!this.props.showBody && ( + + )} + )} {/* This is an expanding spacer for mobile */}
@@ -541,7 +564,7 @@ export class PostListing extends Component { {this.state.upvotes}
+ + {!this.state.showMoreMobile && this.props.showBody && ( + + )} + {this.state.showMoreMobile && this.postActions(mobile)} )}
@@ -591,313 +627,284 @@ export class PostListing extends Component { ); } - postActions() { + postActions(mobile: boolean = false) { let post = this.props.post; return ( -
    - {UserService.Instance.user && ( - <> - {this.props.showBody && ( - <> -
  • - + {this.props.showBody && ( + <> + {!mobile && ( +
  • - - )} - {this.myPost && this.props.showBody && ( - <> -
  • + + + + )} + + + + + + + )} + {this.myPost && this.props.showBody && ( + <> + + + + )} + + {!this.state.showAdvanced && this.props.showBody ? ( + + ) : ( + <> + {this.props.showBody && post.body && ( + + )} + {this.canModOnSelf && ( + <> -
  • -
  • -
  • - - )} - - {!this.state.showAdvanced && this.props.showBody ? ( -
  • - -
  • - ) : ( - <> - {this.props.showBody && post.body && ( -
  • - -
  • - )} - {this.canModOnSelf && ( - <> -
  • - -
  • -
  • - -
  • - - )} - {/* Mods can ban from community, and appoint as mods to community */} - {(this.canMod || this.canAdmin) && ( -
  • - {!post.removed ? ( + + )} + {/* Mods can ban from community, and appoint as mods to community */} + {(this.canMod || this.canAdmin) && + (!post.removed ? ( + + {i18n.t('remove')} + + ) : ( + + {i18n.t('restore')} + + ))} + {this.canMod && ( + <> + {!this.isMod && + (!post.banned_from_community ? ( - {i18n.t('remove')} + {i18n.t('ban')} ) : ( - {i18n.t('restore')} + {i18n.t('unban')} + ))} + {!post.banned_from_community && post.creator_local && ( + + {this.isMod + ? i18n.t('remove_as_mod') + : i18n.t('appoint_as_mod')} + + )} + + )} + {/* Community creators and admins can transfer community to another mod */} + {(this.amCommunityCreator || this.canAdmin) && + this.isMod && + post.creator_local && + (!this.state.showConfirmTransferCommunity ? ( + - )} - {this.canMod && ( + > + {i18n.t('transfer_community')} + + ) : ( <> - {!this.isMod && ( -
  • - {!post.banned_from_community ? ( - - {i18n.t('ban')} - - ) : ( - - {i18n.t('unban')} - - )} -
  • - )} - {!post.banned_from_community && post.creator_local && ( -
  • - - {this.isMod - ? i18n.t('remove_as_mod') - : i18n.t('appoint_as_mod')} - -
  • - )} - - )} - {/* Community creators and admins can transfer community to another mod */} - {(this.amCommunityCreator || this.canAdmin) && - this.isMod && - post.creator_local && ( -
  • - {!this.state.showConfirmTransferCommunity ? ( - - {i18n.t('transfer_community')} - - ) : ( - <> - - {i18n.t('are_you_sure')} - - - {i18n.t('yes')} - - - {i18n.t('no')} - - + + {i18n.t('are_you_sure')} + + + {i18n.t('yes')} + + - )} - {/* Admins can ban from all, and appoint other admins */} - {this.canAdmin && ( - <> - {!this.isAdmin && ( -
  • - {!post.banned ? ( - - {i18n.t('ban_from_site')} - - ) : ( - - {i18n.t('unban_from_site')} - - )} -
  • - )} - {!post.banned && post.creator_local && ( -
  • - - {this.isAdmin - ? i18n.t('remove_as_admin') - : i18n.t('appoint_as_admin')} - -
  • - )} + > + {i18n.t('no')} + - )} - {/* Site Creator can transfer to another admin */} - {this.amSiteCreator && this.isAdmin && ( -
  • - {!this.state.showConfirmTransferSite ? ( + ))} + {/* Admins can ban from all, and appoint other admins */} + {this.canAdmin && ( + <> + {!this.isAdmin && + (!post.banned ? ( - {i18n.t('transfer_site')} + {i18n.t('ban_from_site')} ) : ( - <> - - {i18n.t('are_you_sure')} - - - {i18n.t('yes')} - - - {i18n.t('no')} - - + + {i18n.t('unban_from_site')} + + ))} + {!post.banned && post.creator_local && ( + + {this.isAdmin + ? i18n.t('remove_as_admin') + : i18n.t('appoint_as_admin')} + + )} + + )} + {/* Site Creator can transfer to another admin */} + {this.amSiteCreator && + this.isAdmin && + (!this.state.showConfirmTransferSite ? ( + - )} - - )} - - )} -
+ > + {i18n.t('transfer_site')} + + ) : ( + <> + + {i18n.t('are_you_sure')} + + + {i18n.t('yes')} + + + {i18n.t('no')} + + + ))} + + )} + + ) ); } @@ -1014,7 +1021,6 @@ export class PostListing extends Component { {this.commentsLine(true)} {this.duplicatesLine()} - {this.postActions()} {this.removeAndBanDialogs()} @@ -1443,6 +1449,13 @@ export class PostListing extends Component { setupTippy(); } + handleShowMoreMobile(i: PostListing) { + i.state.showMoreMobile = !i.state.showMoreMobile; + i.state.showAdvanced = !i.state.showAdvanced; + i.setState(i.state); + setupTippy(); + } + get pointsTippy(): string { let points = i18n.t('number_of_points', { count: this.state.score, diff --git a/src/shared/components/user.tsx b/src/shared/components/user.tsx index 109e71c..f93ab94 100644 --- a/src/shared/components/user.tsx +++ b/src/shared/components/user.tsx @@ -43,6 +43,7 @@ import { setAuth, lemmyHttp, previewLines, + editPostFindRes, } from '../utils'; import { UserListing } from './user-listing'; import { HtmlTags } from './html-tags'; @@ -884,6 +885,9 @@ export class User extends Component { this.props.history.push( `/u/${this.state.userName}/view/${viewStr}/sort/${sortStr}/page/${page}` ); + this.state.loading = true; + this.setState(this.state); + this.fetchUserData(); } handlePageChange(page: number) { @@ -1141,6 +1145,17 @@ export class User extends Component { const data = res.data as CommentResponse; saveCommentRes(data, this.state.userRes.comments); this.setState(this.state); + } else if ( + res.op == UserOperation.EditPost || + res.op == UserOperation.DeletePost || + res.op == UserOperation.RemovePost || + res.op == UserOperation.LockPost || + res.op == UserOperation.StickyPost || + res.op == UserOperation.SavePost + ) { + let data = res.data as PostResponse; + editPostFindRes(data, this.state.userRes.posts); + this.setState(this.state); } else if (res.op == UserOperation.CreatePostLike) { const data = res.data as PostResponse; createPostLikeFindRes(data, this.state.userRes.posts); -- 2.44.1