diff --git a/src/assets/css/main.css b/src/assets/css/main.css index 63c1b471..e5c163b1 100644 --- a/src/assets/css/main.css +++ b/src/assets/css/main.css @@ -198,9 +198,9 @@ blockquote { .thumbnail { object-fit: cover; - aspect-ratio: 4/3; - width: 100%; - max-height: 6rem; + aspect-ratio: 1/1; + width: 5rem; + height: 5rem; } .thumbnail svg { diff --git a/src/shared/components/common/image-upload-form.tsx b/src/shared/components/common/image-upload-form.tsx index e8005ccc..854e7105 100644 --- a/src/shared/components/common/image-upload-form.tsx +++ b/src/shared/components/common/image-upload-form.tsx @@ -84,6 +84,8 @@ export class ImageUploadForm extends Component< if (res.state === "success") { if (res.data.msg === "ok") { i.props.onUpload(res.data.url as string); + } else if (res.data.msg === "too_large") { + toast(I18NextService.i18n.t("upload_too_large"), "danger"); } else { toast(JSON.stringify(res), "danger"); } diff --git a/src/shared/components/common/markdown-textarea.tsx b/src/shared/components/common/markdown-textarea.tsx index f7c4760a..5623ace5 100644 --- a/src/shared/components/common/markdown-textarea.tsx +++ b/src/shared/components/common/markdown-textarea.tsx @@ -443,6 +443,10 @@ export class MarkdownTextArea extends Component< const textarea: any = document.getElementById(i.id); autosize.update(textarea); pictrsDeleteToast(image.name, res.data.delete_url as string); + } else if (res.data.msg === "too_large") { + toast(I18NextService.i18n.t("upload_too_large"), "danger"); + i.setState({ imageUploadStatus: undefined }); + throw JSON.stringify(res.data); } else { throw JSON.stringify(res.data); } diff --git a/src/shared/components/home/emojis-form.tsx b/src/shared/components/home/emojis-form.tsx index 149ff032..4108e7a4 100644 --- a/src/shared/components/home/emojis-form.tsx +++ b/src/shared/components/home/emojis-form.tsx @@ -508,6 +508,8 @@ export class EmojiForm extends Component { { form: form, index: index, overrideValue: res.data.url as string }, event ); + } else if (res.data.msg === "too_large") { + toast(I18NextService.i18n.t("upload_too_large"), "danger"); } else { toast(JSON.stringify(res), "danger"); } diff --git a/src/shared/components/post/post-form.tsx b/src/shared/components/post/post-form.tsx index 25a0fcc0..c29d3b1f 100644 --- a/src/shared/components/post/post-form.tsx +++ b/src/shared/components/post/post-form.tsx @@ -187,6 +187,8 @@ function handleImageUpload(i: PostForm, event: any) { imageLoading: false, imageDeleteUrl: res.data.delete_url as string, }); + } else if (res.data.msg === "too_large") { + toast(I18NextService.i18n.t("upload_too_large"), "danger"); } else { toast(JSON.stringify(res), "danger"); } diff --git a/src/shared/components/post/post-listing.tsx b/src/shared/components/post/post-listing.tsx index eb3d0f64..ae6e2f3b 100644 --- a/src/shared/components/post/post-listing.tsx +++ b/src/shared/components/post/post-listing.tsx @@ -333,7 +333,7 @@ export class PostListing extends Component { return ( @@ -981,9 +1024,8 @@ export class PostListing extends Component { get modUnbanFromCommunityButton() { return ( @@ -993,20 +1035,15 @@ export class PostListing extends Component { get addModToCommunityButton() { return ( ); @@ -1015,11 +1052,10 @@ export class PostListing extends Component { get modBanButton() { return ( ); } @@ -1027,14 +1063,13 @@ export class PostListing extends Component { get modUnbanButton() { return ( ); @@ -1043,11 +1078,10 @@ export class PostListing extends Component { get purgePersonButton() { return ( ); } @@ -1055,11 +1089,10 @@ export class PostListing extends Component { get purgePostButton() { return ( ); } @@ -1067,20 +1100,31 @@ export class PostListing extends Component { get toggleAdminButton() { return ( ); } + get transferCommunityButton() { + return ( + + ); + } + get modRemoveButton() { const removed = this.postView.post.removed; return ( @@ -1095,102 +1139,17 @@ export class PostListing extends Component { {this.state.removeLoading ? ( ) : !removed ? ( - I18NextService.i18n.t("remove") + capitalizeFirstLetter(I18NextService.i18n.t("remove_post")) ) : ( - I18NextService.i18n.t("restore") + <> + {capitalizeFirstLetter(I18NextService.i18n.t("restore"))}{" "} + {I18NextService.i18n.t("post")} + )} ); } - /** - * Mod/Admin actions to be taken against the author. - */ - userActionsLine() { - // TODO: make nicer - const post_view = this.postView; - return ( - this.state.showAdvanced && ( -
- {this.canMod_ && ( - <> - {!this.creatorIsMod_ && - (!post_view.creator_banned_from_community - ? this.modBanFromCommunityButton - : this.modUnbanFromCommunityButton)} - {!post_view.creator_banned_from_community && - this.addModToCommunityButton} - - )} - - {/* Community creators and admins can transfer community to another mod */} - {(amCommunityCreator(post_view.creator.id, this.props.moderators) || - this.canAdmin_) && - this.creatorIsMod_ && - (!this.state.showConfirmTransferCommunity ? ( - - ) : ( - <> - - - - - ))} - {/* Admins can ban from all, and appoint other admins */} - {this.canAdmin_ && ( - <> - {!this.creatorIsAdmin_ && ( - <> - {!isBanned(post_view.creator) - ? this.modBanButton - : this.modUnbanButton} - {this.purgePersonButton} - {this.purgePostButton} - - )} - {!isBanned(post_view.creator) && - post_view.creator.local && - this.toggleAdminButton} - - )} -
- ) - ); - } - removeAndBanDialogs() { const post = this.postView; const purgeTypeText = @@ -1218,11 +1177,7 @@ export class PostListing extends Component { value={this.state.removeReason} onInput={linkEvent(this, this.handleModRemoveReasonChange)} /> - )} + {this.state.showConfirmTransferCommunity && ( + <> + + + + + )} {this.state.showBanDialog && (
@@ -1284,11 +1266,7 @@ export class PostListing extends Component { {/* */} {/*
*/}
- )} @@ -1409,7 +1379,6 @@ export class PostListing extends Component { {this.mobileThumbnail()} {this.commentsLine(true)} - {this.userActionsLine()} {this.duplicatesLine()} {this.removeAndBanDialogs()}
@@ -1433,15 +1402,14 @@ export class PostListing extends Component { )}
-
+
{this.thumbnail()}
-
+
{this.postTitleLine()} {this.createdLine()} {this.commentsLine()} {this.duplicatesLine()} - {this.userActionsLine()} {this.removeAndBanDialogs()}
diff --git a/src/shared/components/search.tsx b/src/shared/components/search.tsx index b58580e5..5360066c 100644 --- a/src/shared/components/search.tsx +++ b/src/shared/components/search.tsx @@ -332,9 +332,7 @@ export class Search extends Component { } async componentDidMount() { - if ( - !(this.state.isIsomorphic || this.props.history.location.state?.searched) - ) { + if (!this.state.isIsomorphic) { const promises = [this.fetchCommunities()]; if (this.state.searchText) { promises.push(this.search()); @@ -432,7 +430,15 @@ export class Search extends Component { q: query, auth, }; - resolveObjectResponse = await client.resolveObject(resolveObjectForm); + resolveObjectResponse = await HttpService.silent_client.resolveObject( + resolveObjectForm + ); + + // If we return this object with a state of failed, the catch-all-handler will redirect + // to an error page, so we ignore it by covering up the error with the empty state. + if (resolveObjectResponse.state === "failed") { + resolveObjectResponse = { state: "empty" }; + } } } } @@ -950,7 +956,7 @@ export class Search extends Component { if (auth) { this.setState({ resolveObjectRes: { state: "loading" } }); this.setState({ - resolveObjectRes: await HttpService.client.resolveObject({ + resolveObjectRes: await HttpService.silent_client.resolveObject({ q, auth, }), @@ -1097,10 +1103,6 @@ export class Search extends Component { sort: sort ?? urlSort, }; - this.props.history.push(`/search${getQueryString(queryParams)}`, { - searched: true, - }); - - await this.search(); + this.props.history.push(`/search${getQueryString(queryParams)}`); } } diff --git a/src/shared/services/HttpService.ts b/src/shared/services/HttpService.ts index 361ffbd3..11ec292a 100644 --- a/src/shared/services/HttpService.ts +++ b/src/shared/services/HttpService.ts @@ -1,9 +1,9 @@ import { getHttpBase } from "@utils/env"; import { LemmyHttp } from "lemmy-js-client"; -import { toast } from "../../shared/toast"; +import { toast } from "../toast"; import { I18NextService } from "./I18NextService"; -type EmptyRequestState = { +export type EmptyRequestState = { state: "empty"; }; @@ -45,7 +45,7 @@ export type WrappedLemmyHttp = { class WrappedLemmyHttpClient { #client: LemmyHttp; - constructor(client: LemmyHttp) { + constructor(client: LemmyHttp, silent = false) { this.#client = client; for (const key of Object.getOwnPropertyNames( @@ -61,8 +61,10 @@ class WrappedLemmyHttpClient { state: !(res === undefined || res === null) ? "success" : "empty", }; } catch (error) { - console.error(`API error: ${error}`); - toast(I18NextService.i18n.t(error), "danger"); + if (!silent) { + console.error(`API error: ${error}`); + toast(I18NextService.i18n.t(error), "danger"); + } return { state: "failed", msg: error, @@ -74,16 +76,23 @@ class WrappedLemmyHttpClient { } } -export function wrapClient(client: LemmyHttp) { - return new WrappedLemmyHttpClient(client) as unknown as WrappedLemmyHttp; // unfortunately, this verbose cast is necessary +export function wrapClient(client: LemmyHttp, silent = false) { + // unfortunately, this verbose cast is necessary + return new WrappedLemmyHttpClient( + client, + silent + ) as unknown as WrappedLemmyHttp; } export class HttpService { static #_instance: HttpService; + #silent_client: WrappedLemmyHttp; #client: WrappedLemmyHttp; private constructor() { - this.#client = wrapClient(new LemmyHttp(getHttpBase())); + const lemmyHttp = new LemmyHttp(getHttpBase()); + this.#client = wrapClient(lemmyHttp); + this.#silent_client = wrapClient(lemmyHttp, true); } static get #Instance() { @@ -93,4 +102,8 @@ export class HttpService { public static get client() { return this.#Instance.#client; } + + public static get silent_client() { + return this.#Instance.#silent_client; + } } diff --git a/webpack.config.js b/webpack.config.js index 4d95a80c..a2b31d04 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -96,6 +96,7 @@ const createClientConfig = (_env, mode) => { entry: "./src/client/index.tsx", output: { filename: "js/client.js", + publicPath: "/static/", }, plugins: [ ...base.plugins, @@ -106,7 +107,7 @@ const createClientConfig = (_env, mode) => { "/": "/static/", }, cacheId: "lemmy", - include: [/(assets|styles)\/.+\..+|client\.js$/g], + include: [/(assets|styles|js)\/.+\..+$/g], inlineWorkboxRuntime: true, runtimeCaching: [ {