From 6aa33e6809f7da40c6d2f7fc92ba84986577c76e Mon Sep 17 00:00:00 2001 From: Dessalines Date: Tue, 21 Feb 2023 15:52:12 -0500 Subject: [PATCH 1/6] Remove buggy navbar search. Fixes #921 (#950) --- src/assets/css/main.css | 10 --- src/shared/components/app/navbar.tsx | 64 ++-------------- src/shared/components/search.tsx | 109 +++++++++++++++------------ 3 files changed, 66 insertions(+), 117 deletions(-) diff --git a/src/assets/css/main.css b/src/assets/css/main.css index 98e98d26..766c9dbd 100644 --- a/src/assets/css/main.css +++ b/src/assets/css/main.css @@ -305,16 +305,6 @@ pre { transition: width 0.2s ease-out 0s !important; } -.show-input { - width: 13vw !important; -} -.hide-input { - background: transparent !important; - background-color: transparent !important; - width: 0px !important; - padding: 0 !important; -} - br.big { display: block; content: ""; diff --git a/src/shared/components/app/navbar.tsx b/src/shared/components/app/navbar.tsx index d758af60..4d0b88fd 100644 --- a/src/shared/components/app/navbar.tsx +++ b/src/shared/components/app/navbar.tsx @@ -1,4 +1,4 @@ -import { Component, createRef, linkEvent, RefObject } from "inferno"; +import { Component, linkEvent } from "inferno"; import { NavLink } from "inferno-router"; import { CommentResponse, @@ -44,7 +44,6 @@ interface NavbarState { unreadReportCount: number; unreadApplicationCount: number; searchParam: string; - toggleSearch: boolean; showDropdown: boolean; onSiteBanner?(url: string): any; } @@ -55,14 +54,12 @@ export class Navbar extends Component { private unreadInboxCountSub: Subscription; private unreadReportCountSub: Subscription; private unreadApplicationCountSub: Subscription; - private searchTextField: RefObject; state: NavbarState = { unreadInboxCount: 0, unreadReportCount: 0, unreadApplicationCount: 0, expanded: false, searchParam: "", - toggleSearch: false, showDropdown: false, }; subscription: any; @@ -77,8 +74,6 @@ export class Navbar extends Component { componentDidMount() { // Subscribe to jwt changes if (isBrowser()) { - this.searchTextField = createRef(); - // On the first load, check the unreads let auth = myAuth(false); if (auth && UserService.Instance.myUserInfo) { @@ -123,7 +118,6 @@ export class Navbar extends Component { updateUrl() { const searchParam = this.state.searchParam; this.setState({ searchParam: "" }); - this.setState({ toggleSearch: false }); this.setState({ showDropdown: false, expanded: false }); if (searchParam === "") { this.context.router.history.push(`/search/`); @@ -308,35 +302,13 @@ export class Navbar extends Component { ) && (
  • -
    - - - -
    + +
)} @@ -520,28 +492,6 @@ export class Navbar extends Component { i.setState({ searchParam: event.target.value }); } - handleSearchSubmit(i: Navbar, event: any) { - event.preventDefault(); - i.updateUrl(); - } - - handleSearchBtn(i: Navbar, event: any) { - event.preventDefault(); - i.setState({ toggleSearch: true }); - - i.searchTextField.current?.focus(); - const offsetWidth = i.searchTextField.current?.offsetWidth; - if (i.state.searchParam && offsetWidth && offsetWidth > 100) { - i.updateUrl(); - } - } - - handleSearchBlur(i: Navbar, event: any) { - if (!(event.relatedTarget && event.relatedTarget.name !== "search-btn")) { - i.setState({ toggleSearch: false }); - } - } - handleLogoutClick(i: Navbar) { i.setState({ showDropdown: false, expanded: false }); UserService.Instance.logout(); diff --git a/src/shared/components/search.tsx b/src/shared/components/search.tsx index 102e0fca..b96e1c5c 100644 --- a/src/shared/components/search.tsx +++ b/src/shared/components/search.tsx @@ -75,7 +75,7 @@ if (isBrowser()) { } interface SearchProps { - q: string; + q?: string; type_: SearchType; sort: SortType; listingType: ListingType; @@ -85,7 +85,7 @@ interface SearchProps { } interface SearchState { - q: string; + q?: string; type_: SearchType; sort: SortType; listingType: ListingType; @@ -97,7 +97,7 @@ interface SearchState { creatorDetails?: GetPersonDetailsResponse; loading: boolean; siteRes: GetSiteResponse; - searchText: string; + searchText?: string; resolveObjectResponse?: ResolveObjectResponse; } @@ -135,13 +135,13 @@ export class Search extends Component { this.props.match.params.community_id ), creatorId: Search.getCreatorIdFromProps(this.props.match.params.creator_id), - loading: true, + loading: false, siteRes: this.isoData.site_res, communities: [], }; - static getSearchQueryFromProps(q: string): string { - return decodeURIComponent(q) || ""; + static getSearchQueryFromProps(q?: string): string | undefined { + return q ? decodeURIComponent(q) : undefined; } static getSearchTypeFromProps(type_: string): SearchType { @@ -219,7 +219,10 @@ export class Search extends Component { } } else { this.fetchCommunities(); - this.search(); + + if (this.state.q) { + this.search(); + } } } @@ -298,29 +301,33 @@ export class Search extends Component { promises.push(Promise.resolve()); } - let form: SearchForm = { - q: this.getSearchQueryFromProps(pathSplit[3]), - community_id, - creator_id, - type_: this.getSearchTypeFromProps(pathSplit[5]), - sort: this.getSortTypeFromProps(pathSplit[7]), - listing_type: this.getListingTypeFromProps(pathSplit[9]), - page: this.getPageFromProps(pathSplit[15]), - limit: fetchLimit, - auth: req.auth, - }; + let q = this.getSearchQueryFromProps(pathSplit[3]); - let resolveObjectForm: ResolveObject = { - q: this.getSearchQueryFromProps(pathSplit[3]), - auth: req.auth, - }; + if (q) { + let form: SearchForm = { + q, + community_id, + creator_id, + type_: this.getSearchTypeFromProps(pathSplit[5]), + sort: this.getSortTypeFromProps(pathSplit[7]), + listing_type: this.getListingTypeFromProps(pathSplit[9]), + page: this.getPageFromProps(pathSplit[15]), + limit: fetchLimit, + auth: req.auth, + }; - if (form.q != "") { - promises.push(req.client.search(form)); - promises.push(req.client.resolveObject(resolveObjectForm)); - } else { - promises.push(Promise.resolve()); - promises.push(Promise.resolve()); + let resolveObjectForm: ResolveObject = { + q, + auth: req.auth, + }; + + if (form.q != "") { + promises.push(req.client.search(form)); + promises.push(req.client.resolveObject(resolveObjectForm)); + } else { + promises.push(Promise.resolve()); + promises.push(Promise.resolve()); + } } return promises; @@ -336,11 +343,13 @@ export class Search extends Component { lastState.creatorId !== this.state.creatorId || lastState.page !== this.state.page ) { - this.setState({ - loading: true, - searchText: this.state.q, - }); - this.search(); + if (this.state.q) { + this.setState({ + loading: true, + searchText: this.state.q, + }); + this.search(); + } } } @@ -779,24 +788,24 @@ export class Search extends Component { this.state.creatorId == 0 ? undefined : this.state.creatorId; let auth = myAuth(false); - let form: SearchForm = { - q: this.state.q, - community_id, - creator_id, - type_: this.state.type_, - sort: this.state.sort, - listing_type: this.state.listingType, - page: this.state.page, - limit: fetchLimit, - auth, - }; + if (this.state.q && this.state.q != "") { + let form: SearchForm = { + q: this.state.q, + community_id, + creator_id, + type_: this.state.type_, + sort: this.state.sort, + listing_type: this.state.listingType, + page: this.state.page, + limit: fetchLimit, + auth, + }; - let resolveObjectForm: ResolveObject = { - q: this.state.q, - auth, - }; + let resolveObjectForm: ResolveObject = { + q: this.state.q, + auth, + }; - if (this.state.q != "") { this.setState({ searchResponse: undefined, resolveObjectResponse: undefined, @@ -919,7 +928,7 @@ export class Search extends Component { updateUrl(paramUpdates: UrlParams) { const qStr = paramUpdates.q || this.state.q; - const qStrEncoded = encodeURIComponent(qStr); + const qStrEncoded = encodeURIComponent(qStr || ""); const typeStr = paramUpdates.type_ || this.state.type_; const listingTypeStr = paramUpdates.listingType || this.state.listingType; const sortStr = paramUpdates.sort || this.state.sort; From b1dcd222abdd92394eaee02de8161b15a7477aec Mon Sep 17 00:00:00 2001 From: Dessalines Date: Tue, 21 Feb 2023 15:52:34 -0500 Subject: [PATCH 2/6] Check to make sure post is correct. Fixes #934 (#949) --- src/shared/components/post/post.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/shared/components/post/post.tsx b/src/shared/components/post/post.tsx index 72a54284..2f8a2089 100644 --- a/src/shared/components/post/post.tsx +++ b/src/shared/components/post/post.tsx @@ -651,6 +651,7 @@ export class Post extends Component { data.recipient_ids.length == 0 && !creatorBlocked && postRes && + data.comment_view.post.id == postRes.post_view.post.id && commentsRes ) { commentsRes.comments.unshift(data.comment_view); From 1b1168d79fd437d3a51c171bc77660e54662d610 Mon Sep 17 00:00:00 2001 From: Dessalines Date: Tue, 21 Feb 2023 15:52:57 -0500 Subject: [PATCH 3/6] Do local community checks for buttons. Fixes #918 (#948) --- .../components/comment/comment-node.tsx | 42 ++++++++++--------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/src/shared/components/comment/comment-node.tsx b/src/shared/components/comment/comment-node.tsx index 50da4561..6f903b48 100644 --- a/src/shared/components/comment/comment-node.tsx +++ b/src/shared/components/comment/comment-node.tsx @@ -163,27 +163,29 @@ export class CommentNode extends Component { ? i18n.t("purge_comment") : `${i18n.t("purge")} ${cv.creator.name}`; - let canMod_ = canMod( - cv.creator.id, - this.props.moderators, - this.props.admins - ); - let canModOnSelf = canMod( - cv.creator.id, - this.props.moderators, - this.props.admins, - UserService.Instance.myUserInfo, - true - ); - let canAdmin_ = canAdmin(cv.creator.id, this.props.admins); - let canAdminOnSelf = canAdmin( - cv.creator.id, - this.props.admins, - UserService.Instance.myUserInfo, - true - ); + let canMod_ = + canMod(cv.creator.id, this.props.moderators, this.props.admins) && + cv.community.local; + let canModOnSelf = + canMod( + cv.creator.id, + this.props.moderators, + this.props.admins, + UserService.Instance.myUserInfo, + true + ) && cv.community.local; + let canAdmin_ = + canAdmin(cv.creator.id, this.props.admins) && cv.community.local; + let canAdminOnSelf = + canAdmin( + cv.creator.id, + this.props.admins, + UserService.Instance.myUserInfo, + true + ) && cv.community.local; let isMod_ = isMod(cv.creator.id, this.props.moderators); - let isAdmin_ = isAdmin(cv.creator.id, this.props.admins); + let isAdmin_ = + isAdmin(cv.creator.id, this.props.admins) && cv.community.local; let amCommunityCreator_ = amCommunityCreator( cv.creator.id, this.props.moderators From a09b301429b6e602c241c6d63238648f3993bb6a Mon Sep 17 00:00:00 2001 From: Dessalines Date: Tue, 21 Feb 2023 15:53:15 -0500 Subject: [PATCH 4/6] Fixing line formatting. (#947) --- src/shared/components/post/post-listing.tsx | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/shared/components/post/post-listing.tsx b/src/shared/components/post/post-listing.tsx index f8140c3e..7580daf3 100644 --- a/src/shared/components/post/post-listing.tsx +++ b/src/shared/components/post/post-listing.tsx @@ -434,15 +434,18 @@ export class PostListing extends Component { let post = this.props.post_view.post; return ( -
+
); } @@ -457,16 +460,19 @@ export class PostListing extends Component { {url ? ( this.props.showBody ? ( -
+
) : ( this.postLink @@ -477,7 +483,7 @@ export class PostListing extends Component { {(url && isImage(url)) || (post.thumbnail_url && ( -
- )} +
+
+ {i18n.t("undetermined_language_warning")} +
+
+ +
+ {this.selectBtn} + {this.props.multiple && ( +
+ +
+ )} +
); From 49acf514e9cca8ef0629444655f53193d6a6e6db Mon Sep 17 00:00:00 2001 From: Dessalines Date: Tue, 21 Feb 2023 15:53:51 -0500 Subject: [PATCH 6/6] Let any mod feature and lock posts. Fixes #875 (#944) * Let any mod feature and lock posts. Fixes #875 * Change to amAdmin --- src/shared/components/post/post-listing.tsx | 57 ++++++++++++--------- 1 file changed, 32 insertions(+), 25 deletions(-) diff --git a/src/shared/components/post/post-listing.tsx b/src/shared/components/post/post-listing.tsx index 7580daf3..d0e72e4d 100644 --- a/src/shared/components/post/post-listing.tsx +++ b/src/shared/components/post/post-listing.tsx @@ -30,6 +30,7 @@ import { UserService, WebSocketService } from "../../services"; import { amAdmin, amCommunityCreator, + amMod, canAdmin, canMod, futureDaysToUnixTime, @@ -614,7 +615,8 @@ export class PostListing extends Component { {this.state.showAdvanced && ( <> {this.showBody && post_view.post.body && this.viewSourceButton} - {this.canModOnSelf_ && ( + {/* Any mod can do these, not limited to hierarchy*/} + {(amMod(this.props.moderators) || amAdmin()) && ( <> {this.lockButton} {this.featureButton} @@ -848,41 +850,40 @@ export class PostListing extends Component { } get featureButton() { - const featured_community = this.props.post_view.post.featured_community; - const label_community = featured_community + const featuredCommunity = this.props.post_view.post.featured_community; + const labelCommunity = featuredCommunity ? i18n.t("unfeature_from_community") : i18n.t("feature_in_community"); - const is_admin = amAdmin(); - const featured_local = this.props.post_view.post.featured_local; - const label_local = featured_local + const featuredLocal = this.props.post_view.post.featured_local; + const labelLocal = featuredLocal ? i18n.t("unfeature_from_local") : i18n.t("feature_in_local"); return ( - {is_admin && ( + {amAdmin() && (