From ad2bf18ab46f758cba9e262af286cb9decf91fe6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82?= <30625554+n3oney@users.noreply.github.com> Date: Fri, 16 Jun 2023 18:32:21 +0200 Subject: [PATCH 01/47] fix: fix loading custom themes with a custom LEMMY_UI_EXTRA_THEMES_FOLDER --- src/server/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/server/index.tsx b/src/server/index.tsx index 3a12ad7e5..7fca89f26 100644 --- a/src/server/index.tsx +++ b/src/server/index.tsx @@ -87,7 +87,7 @@ server.get("/css/themes/:name", async (req, res) => { res.send("Theme must be a css file"); } - const customTheme = path.resolve(`./${extraThemesFolder}/${theme}`); + const customTheme = path.resolve(`${extraThemesFolder}/${theme}`); if (existsSync(customTheme)) { res.sendFile(customTheme); } else { From 0854af3794f7fb2b7712c9b30ab1147cc18583a3 Mon Sep 17 00:00:00 2001 From: Alec Armbruster Date: Fri, 16 Jun 2023 17:07:55 -0400 Subject: [PATCH 02/47] break out all role utils --- src/client/index.tsx | 6 +- src/shared/components/app/navbar.tsx | 4 +- .../components/comment/comment-node.tsx | 12 +- src/shared/components/community/sidebar.tsx | 6 +- src/shared/components/home/home.tsx | 2 +- src/shared/components/modlog.tsx | 4 +- src/shared/components/person/profile.tsx | 6 +- src/shared/components/person/reports.tsx | 2 +- src/shared/components/post/post-listing.tsx | 16 +-- src/shared/utils.ts | 112 ------------------ src/shared/utils/roles/am-admin.ts | 5 + .../utils/roles/am-community-creator.ts | 12 ++ src/shared/utils/roles/am-mod.ts | 10 ++ src/shared/utils/roles/am-site-creator.ts | 11 ++ src/shared/utils/roles/am-top-mod.ts | 9 ++ src/shared/utils/roles/can-admin.ts | 12 ++ .../utils/roles/can-create-community.ts | 12 ++ src/shared/utils/roles/can-mod.ts | 31 +++++ src/shared/utils/roles/is-admin.ts | 5 + src/shared/utils/roles/is-banned.ts | 16 +++ src/shared/utils/roles/is-mod.ts | 8 ++ 21 files changed, 160 insertions(+), 141 deletions(-) create mode 100644 src/shared/utils/roles/am-admin.ts create mode 100644 src/shared/utils/roles/am-community-creator.ts create mode 100644 src/shared/utils/roles/am-mod.ts create mode 100644 src/shared/utils/roles/am-site-creator.ts create mode 100644 src/shared/utils/roles/am-top-mod.ts create mode 100644 src/shared/utils/roles/can-admin.ts create mode 100644 src/shared/utils/roles/can-create-community.ts create mode 100644 src/shared/utils/roles/can-mod.ts create mode 100644 src/shared/utils/roles/is-admin.ts create mode 100644 src/shared/utils/roles/is-banned.ts create mode 100644 src/shared/utils/roles/is-mod.ts diff --git a/src/client/index.tsx b/src/client/index.tsx index 7b6b6b1cd..860c07565 100644 --- a/src/client/index.tsx +++ b/src/client/index.tsx @@ -1,14 +1,13 @@ import { hydrate } from "inferno-hydrate"; import { Router } from "inferno-router"; import { App } from "../shared/components/app/app"; +import { HistoryService } from "../shared/services/HistoryService"; import { initializeSite } from "../shared/utils"; import "bootstrap/js/dist/collapse"; import "bootstrap/js/dist/dropdown"; -import { HistoryService } from "../shared/services/HistoryService"; -const site = window.isoData.site_res; -initializeSite(site); +initializeSite(window.isoData.site_res); const wrapper = ( @@ -17,6 +16,7 @@ const wrapper = ( ); const root = document.getElementById("root"); + if (root) { hydrate(wrapper, root); } diff --git a/src/shared/components/app/navbar.tsx b/src/shared/components/app/navbar.tsx index 6d310eef3..8c7c9202f 100644 --- a/src/shared/components/app/navbar.tsx +++ b/src/shared/components/app/navbar.tsx @@ -10,8 +10,6 @@ import { i18n } from "../../i18next"; import { UserService } from "../../services"; import { HttpService, RequestState } from "../../services/HttpService"; import { - amAdmin, - canCreateCommunity, donateLemmyUrl, isBrowser, myAuth, @@ -21,6 +19,8 @@ import { toast, updateUnreadCountsInterval, } from "../../utils"; +import { amAdmin } from "../../utils/roles/am-admin"; +import { canCreateCommunity } from "../../utils/roles/can-create-community"; import { Icon } from "../common/icon"; import { PictrsImage } from "../common/pictrs-image"; diff --git a/src/shared/components/comment/comment-node.tsx b/src/shared/components/comment/comment-node.tsx index 0380a7266..10b13c126 100644 --- a/src/shared/components/comment/comment-node.tsx +++ b/src/shared/components/comment/comment-node.tsx @@ -40,16 +40,10 @@ import { } from "../../interfaces"; import { UserService } from "../../services"; import { - amCommunityCreator, - canAdmin, - canMod, colorList, commentTreeMaxDepth, futureDaysToUnixTime, getCommentParentId, - isAdmin, - isBanned, - isMod, mdToHtml, mdToHtmlNoImages, myAuth, @@ -59,6 +53,12 @@ import { setupTippy, showScores, } from "../../utils"; +import { amCommunityCreator } from "../../utils/roles/am-community-creator"; +import { canAdmin } from "../../utils/roles/can-admin"; +import { canMod } from "../../utils/roles/can-mod"; +import { isAdmin } from "../../utils/roles/is-admin"; +import { isBanned } from "../../utils/roles/is-banned"; +import { isMod } from "../../utils/roles/is-mod"; import { Icon, PurgeWarning, Spinner } from "../common/icon"; import { MomentTime } from "../common/moment-time"; import { CommunityLink } from "../community/community-link"; diff --git a/src/shared/components/community/sidebar.tsx b/src/shared/components/community/sidebar.tsx index a5c620f3b..2774747b0 100644 --- a/src/shared/components/community/sidebar.tsx +++ b/src/shared/components/community/sidebar.tsx @@ -16,15 +16,15 @@ import { import { i18n } from "../../i18next"; import { UserService } from "../../services"; import { - amAdmin, - amMod, - amTopMod, getUnixTime, hostname, mdToHtml, myAuthRequired, numToSI, } from "../../utils"; +import { amAdmin } from "../../utils/roles/am-admin"; +import { amMod } from "../../utils/roles/am-mod"; +import { amTopMod } from "../../utils/roles/am-top-mod"; import { BannerIconHeader } from "../common/banner-icon-header"; import { Icon, PurgeWarning, Spinner } from "../common/icon"; import { CommunityForm } from "../community/community-form"; diff --git a/src/shared/components/home/home.tsx b/src/shared/components/home/home.tsx index 1abb1ee32..4e23c03c9 100644 --- a/src/shared/components/home/home.tsx +++ b/src/shared/components/home/home.tsx @@ -57,7 +57,6 @@ import { UserService } from "../../services"; import { FirstLoadService } from "../../services/FirstLoadService"; import { HttpService, RequestState } from "../../services/HttpService"; import { - canCreateCommunity, commentsToFlatNodes, editComment, editPost, @@ -85,6 +84,7 @@ import { trendingFetchLimit, updatePersonBlock, } from "../../utils"; +import { canCreateCommunity } from "../../utils/roles/can-create-community"; import { CommentNodes } from "../comment/comment-nodes"; import { DataTypeSelect } from "../common/data-type-select"; import { HtmlTags } from "../common/html-tags"; diff --git a/src/shared/components/modlog.tsx b/src/shared/components/modlog.tsx index d917f5f35..4ab5ec563 100644 --- a/src/shared/components/modlog.tsx +++ b/src/shared/components/modlog.tsx @@ -34,8 +34,6 @@ import { HttpService, RequestState } from "../services/HttpService"; import { Choice, QueryParams, - amAdmin, - amMod, debounce, fetchLimit, fetchUsers, @@ -48,6 +46,8 @@ import { personToChoice, setIsoData, } from "../utils"; +import { amAdmin } from "../utils/roles/am-admin"; +import { amMod } from "../utils/roles/am-mod"; import { HtmlTags } from "./common/html-tags"; import { Icon, Spinner } from "./common/icon"; import { MomentTime } from "./common/moment-time"; diff --git a/src/shared/components/person/profile.tsx b/src/shared/components/person/profile.tsx index f80d5b907..4d9f8f77b 100644 --- a/src/shared/components/person/profile.tsx +++ b/src/shared/components/person/profile.tsx @@ -54,7 +54,6 @@ import { FirstLoadService } from "../../services/FirstLoadService"; import { HttpService, RequestState } from "../../services/HttpService"; import { QueryParams, - canMod, capitalizeFirstLetter, editComment, editPost, @@ -67,8 +66,6 @@ import { getPageFromString, getQueryParams, getQueryString, - isAdmin, - isBanned, mdToHtml, myAuth, myAuthRequired, @@ -81,6 +78,9 @@ import { toast, updatePersonBlock, } from "../../utils"; +import { canMod } from "../../utils/roles/can-mod"; +import { isAdmin } from "../../utils/roles/is-admin"; +import { isBanned } from "../../utils/roles/is-banned"; import { BannerIconHeader } from "../common/banner-icon-header"; import { HtmlTags } from "../common/html-tags"; import { Icon, Spinner } from "../common/icon"; diff --git a/src/shared/components/person/reports.tsx b/src/shared/components/person/reports.tsx index 29daa3ff6..187fe4c2e 100644 --- a/src/shared/components/person/reports.tsx +++ b/src/shared/components/person/reports.tsx @@ -23,7 +23,6 @@ import { HttpService, UserService } from "../../services"; import { FirstLoadService } from "../../services/FirstLoadService"; import { RequestState } from "../../services/HttpService"; import { - amAdmin, editCommentReport, editPostReport, editPrivateMessageReport, @@ -31,6 +30,7 @@ import { myAuthRequired, setIsoData, } from "../../utils"; +import { amAdmin } from "../../utils/roles/am-admin"; import { CommentReport } from "../comment/comment-report"; import { HtmlTags } from "../common/html-tags"; import { Spinner } from "../common/icon"; diff --git a/src/shared/components/post/post-listing.tsx b/src/shared/components/post/post-listing.tsx index 60e188a33..3ec1a4567 100644 --- a/src/shared/components/post/post-listing.tsx +++ b/src/shared/components/post/post-listing.tsx @@ -28,18 +28,10 @@ import { i18n } from "../../i18next"; import { BanType, PostFormParams, PurgeType, VoteType } from "../../interfaces"; import { UserService } from "../../services"; import { - amAdmin, - amCommunityCreator, - amMod, - canAdmin, - canMod, canShare, futureDaysToUnixTime, hostname, - isAdmin, - isBanned, isImage, - isMod, isVideo, mdNoImages, mdToHtml, @@ -52,6 +44,14 @@ import { share, showScores, } from "../../utils"; +import { amAdmin } from "../../utils/roles/am-admin"; +import { amCommunityCreator } from "../../utils/roles/am-community-creator"; +import { amMod } from "../../utils/roles/am-mod"; +import { canAdmin } from "../../utils/roles/can-admin"; +import { canMod } from "../../utils/roles/can-mod"; +import { isAdmin } from "../../utils/roles/is-admin"; +import { isBanned } from "../../utils/roles/is-banned"; +import { isMod } from "../../utils/roles/is-mod"; import { Icon, PurgeWarning, Spinner } from "../common/icon"; import { MomentTime } from "../common/moment-time"; import { PictrsImage } from "../common/pictrs-image"; diff --git a/src/shared/utils.ts b/src/shared/utils.ts index 4a3b298a8..b1b06e2ec 100644 --- a/src/shared/utils.ts +++ b/src/shared/utils.ts @@ -9,7 +9,6 @@ import { CommentReportView, CommentSortType, CommentView, - CommunityModeratorView, CommunityView, CustomEmojiView, GetSiteMetadata, @@ -17,7 +16,6 @@ import { Language, LemmyHttp, MyUserInfo, - Person, PersonMentionView, PersonView, PostReportView, @@ -228,92 +226,6 @@ export function futureDaysToUnixTime(days?: number): number | undefined { : undefined; } -export function canMod( - creator_id: number, - mods?: CommunityModeratorView[], - admins?: PersonView[], - myUserInfo = UserService.Instance.myUserInfo, - onSelf = false -): boolean { - // You can do moderator actions only on the mods added after you. - let adminsThenMods = - admins - ?.map(a => a.person.id) - .concat(mods?.map(m => m.moderator.id) ?? []) ?? []; - - if (myUserInfo) { - const myIndex = adminsThenMods.findIndex( - id => id == myUserInfo.local_user_view.person.id - ); - if (myIndex == -1) { - return false; - } else { - // onSelf +1 on mod actions not for yourself, IE ban, remove, etc - adminsThenMods = adminsThenMods.slice(0, myIndex + (onSelf ? 0 : 1)); - return !adminsThenMods.includes(creator_id); - } - } else { - return false; - } -} - -export function canAdmin( - creatorId: number, - admins?: PersonView[], - myUserInfo = UserService.Instance.myUserInfo, - onSelf = false -): boolean { - return canMod(creatorId, undefined, admins, myUserInfo, onSelf); -} - -export function isMod( - creatorId: number, - mods?: CommunityModeratorView[] -): boolean { - return mods?.map(m => m.moderator.id).includes(creatorId) ?? false; -} - -export function amMod( - mods?: CommunityModeratorView[], - myUserInfo = UserService.Instance.myUserInfo -): boolean { - return myUserInfo ? isMod(myUserInfo.local_user_view.person.id, mods) : false; -} - -export function isAdmin(creatorId: number, admins?: PersonView[]): boolean { - return admins?.map(a => a.person.id).includes(creatorId) ?? false; -} - -export function amAdmin(myUserInfo = UserService.Instance.myUserInfo): boolean { - return myUserInfo?.local_user_view.person.admin ?? false; -} - -export function amCommunityCreator( - creator_id: number, - mods?: CommunityModeratorView[], - myUserInfo = UserService.Instance.myUserInfo -): boolean { - const myId = myUserInfo?.local_user_view.person.id; - // Don't allow mod actions on yourself - return myId == mods?.at(0)?.moderator.id && myId != creator_id; -} - -export function amSiteCreator( - creator_id: number, - admins?: PersonView[], - myUserInfo = UserService.Instance.myUserInfo -): boolean { - const myId = myUserInfo?.local_user_view.person.id; - return myId == admins?.at(0)?.person.id && myId != creator_id; -} - -export function amTopMod( - mods: CommunityModeratorView[], - myUserInfo = UserService.Instance.myUserInfo -): boolean { - return mods.at(0)?.moderator.id == myUserInfo?.local_user_view.person.id; -} - const imageRegex = /(http)?s?:?(\/\/[^"']*\.(?:jpg|jpeg|gif|png|svg|webp))/; const videoRegex = /(http)?s?:?(\/\/[^"']*\.(?:mp4|webm))/; @@ -1291,21 +1203,6 @@ export function numToSI(value: number): string { return SHORTNUM_SI_FORMAT.format(value); } -export function isBanned(ps: Person): boolean { - const expires = ps.ban_expires; - // Add Z to convert from UTC date - // TODO this check probably isn't necessary anymore - if (expires) { - if (ps.banned && new Date(expires + "Z") > new Date()) { - return true; - } else { - return false; - } - } else { - return ps.banned; - } -} - export function myAuth(): string | undefined { return UserService.Instance.auth(); } @@ -1337,15 +1234,6 @@ export function postToCommentSortType(sort: SortType): CommentSortType { } } -export function canCreateCommunity( - siteRes: GetSiteResponse, - myUserInfo = UserService.Instance.myUserInfo -): boolean { - const adminOnly = siteRes.site_view.local_site.community_creation_admin_only; - // TODO: Make this check if user is logged on as well - return !adminOnly || amAdmin(myUserInfo); -} - export function isPostBlocked( pv: PostView, myUserInfo: MyUserInfo | undefined = UserService.Instance.myUserInfo diff --git a/src/shared/utils/roles/am-admin.ts b/src/shared/utils/roles/am-admin.ts new file mode 100644 index 000000000..aadf52ce7 --- /dev/null +++ b/src/shared/utils/roles/am-admin.ts @@ -0,0 +1,5 @@ +import { UserService } from "../../services"; + +export function amAdmin(myUserInfo = UserService.Instance.myUserInfo): boolean { + return myUserInfo?.local_user_view.person.admin ?? false; +} diff --git a/src/shared/utils/roles/am-community-creator.ts b/src/shared/utils/roles/am-community-creator.ts new file mode 100644 index 000000000..20f9b1dda --- /dev/null +++ b/src/shared/utils/roles/am-community-creator.ts @@ -0,0 +1,12 @@ +import { CommunityModeratorView } from "lemmy-js-client"; +import { UserService } from "../../services"; + +export function amCommunityCreator( + creator_id: number, + mods?: CommunityModeratorView[], + myUserInfo = UserService.Instance.myUserInfo +): boolean { + const myId = myUserInfo?.local_user_view.person.id; + // Don't allow mod actions on yourself + return myId == mods?.at(0)?.moderator.id && myId != creator_id; +} diff --git a/src/shared/utils/roles/am-mod.ts b/src/shared/utils/roles/am-mod.ts new file mode 100644 index 000000000..7b792b39d --- /dev/null +++ b/src/shared/utils/roles/am-mod.ts @@ -0,0 +1,10 @@ +import { CommunityModeratorView } from "lemmy-js-client"; +import { UserService } from "../../services"; +import { isMod } from "./is-mod"; + +export function amMod( + mods?: CommunityModeratorView[], + myUserInfo = UserService.Instance.myUserInfo +): boolean { + return myUserInfo ? isMod(myUserInfo.local_user_view.person.id, mods) : false; +} diff --git a/src/shared/utils/roles/am-site-creator.ts b/src/shared/utils/roles/am-site-creator.ts new file mode 100644 index 000000000..323ac0a4c --- /dev/null +++ b/src/shared/utils/roles/am-site-creator.ts @@ -0,0 +1,11 @@ +import { PersonView } from "lemmy-js-client"; +import { UserService } from "../../services"; + +export function amSiteCreator( + creator_id: number, + admins?: PersonView[], + myUserInfo = UserService.Instance.myUserInfo +): boolean { + const myId = myUserInfo?.local_user_view.person.id; + return myId == admins?.at(0)?.person.id && myId != creator_id; +} diff --git a/src/shared/utils/roles/am-top-mod.ts b/src/shared/utils/roles/am-top-mod.ts new file mode 100644 index 000000000..4b942da70 --- /dev/null +++ b/src/shared/utils/roles/am-top-mod.ts @@ -0,0 +1,9 @@ +import { CommunityModeratorView } from "lemmy-js-client"; +import { UserService } from "../../services"; + +export function amTopMod( + mods: CommunityModeratorView[], + myUserInfo = UserService.Instance.myUserInfo +): boolean { + return mods.at(0)?.moderator.id == myUserInfo?.local_user_view.person.id; +} diff --git a/src/shared/utils/roles/can-admin.ts b/src/shared/utils/roles/can-admin.ts new file mode 100644 index 000000000..080c7acc3 --- /dev/null +++ b/src/shared/utils/roles/can-admin.ts @@ -0,0 +1,12 @@ +import { PersonView } from "lemmy-js-client"; +import { UserService } from "../../services"; +import { canMod } from "./can-mod"; + +export function canAdmin( + creatorId: number, + admins?: PersonView[], + myUserInfo = UserService.Instance.myUserInfo, + onSelf = false +): boolean { + return canMod(creatorId, undefined, admins, myUserInfo, onSelf); +} diff --git a/src/shared/utils/roles/can-create-community.ts b/src/shared/utils/roles/can-create-community.ts new file mode 100644 index 000000000..202290d20 --- /dev/null +++ b/src/shared/utils/roles/can-create-community.ts @@ -0,0 +1,12 @@ +import { GetSiteResponse } from "lemmy-js-client"; +import { UserService } from "../../services"; +import { amAdmin } from "./am-admin"; + +export function canCreateCommunity( + siteRes: GetSiteResponse, + myUserInfo = UserService.Instance.myUserInfo +): boolean { + const adminOnly = siteRes.site_view.local_site.community_creation_admin_only; + // TODO: Make this check if user is logged on as well + return !adminOnly || amAdmin(myUserInfo); +} diff --git a/src/shared/utils/roles/can-mod.ts b/src/shared/utils/roles/can-mod.ts new file mode 100644 index 000000000..2892304df --- /dev/null +++ b/src/shared/utils/roles/can-mod.ts @@ -0,0 +1,31 @@ +import { CommunityModeratorView, PersonView } from "lemmy-js-client"; +import { UserService } from "../../services"; + +export function canMod( + creator_id: number, + mods?: CommunityModeratorView[], + admins?: PersonView[], + myUserInfo = UserService.Instance.myUserInfo, + onSelf = false +): boolean { + // You can do moderator actions only on the mods added after you. + let adminsThenMods = + admins + ?.map(a => a.person.id) + .concat(mods?.map(m => m.moderator.id) ?? []) ?? []; + + if (myUserInfo) { + const myIndex = adminsThenMods.findIndex( + id => id == myUserInfo.local_user_view.person.id + ); + if (myIndex == -1) { + return false; + } else { + // onSelf +1 on mod actions not for yourself, IE ban, remove, etc + adminsThenMods = adminsThenMods.slice(0, myIndex + (onSelf ? 0 : 1)); + return !adminsThenMods.includes(creator_id); + } + } else { + return false; + } +} diff --git a/src/shared/utils/roles/is-admin.ts b/src/shared/utils/roles/is-admin.ts new file mode 100644 index 000000000..fbf662b8e --- /dev/null +++ b/src/shared/utils/roles/is-admin.ts @@ -0,0 +1,5 @@ +import { PersonView } from "lemmy-js-client"; + +export function isAdmin(creatorId: number, admins?: PersonView[]): boolean { + return admins?.map(a => a.person.id).includes(creatorId) ?? false; +} diff --git a/src/shared/utils/roles/is-banned.ts b/src/shared/utils/roles/is-banned.ts new file mode 100644 index 000000000..dd5ffe6c7 --- /dev/null +++ b/src/shared/utils/roles/is-banned.ts @@ -0,0 +1,16 @@ +import { Person } from "lemmy-js-client"; + +export function isBanned(ps: Person): boolean { + const expires = ps.ban_expires; + // Add Z to convert from UTC date + // TODO this check probably isn't necessary anymore + if (expires) { + if (ps.banned && new Date(expires + "Z") > new Date()) { + return true; + } else { + return false; + } + } else { + return ps.banned; + } +} diff --git a/src/shared/utils/roles/is-mod.ts b/src/shared/utils/roles/is-mod.ts new file mode 100644 index 000000000..873110726 --- /dev/null +++ b/src/shared/utils/roles/is-mod.ts @@ -0,0 +1,8 @@ +import { CommunityModeratorView } from "lemmy-js-client"; + +export function isMod( + creatorId: number, + mods?: CommunityModeratorView[] +): boolean { + return mods?.map(m => m.moderator.id).includes(creatorId) ?? false; +} From 976ed12d077e89298b6fc574d59f23455c211a15 Mon Sep 17 00:00:00 2001 From: Alec Armbruster Date: Fri, 16 Jun 2023 17:25:53 -0400 Subject: [PATCH 03/47] break out browser and helper methods --- src/shared/components/app/navbar.tsx | 4 +- .../components/common/markdown-textarea.tsx | 3 +- .../components/community/communities.tsx | 6 +- src/shared/components/community/community.tsx | 7 +- src/shared/components/home/home.tsx | 6 +- src/shared/components/home/login.tsx | 3 +- src/shared/components/home/signup.tsx | 2 +- src/shared/components/modlog.tsx | 6 +- src/shared/components/person/profile.tsx | 6 +- src/shared/components/post/create-post.tsx | 4 +- src/shared/components/post/post-listing.tsx | 4 +- src/shared/components/post/post.tsx | 2 +- src/shared/components/search.tsx | 6 +- src/shared/env.ts | 2 +- src/shared/services/UserService.ts | 3 +- src/shared/utils.ts | 73 +------------------ src/shared/utils/browser/can-share.ts | 5 ++ src/shared/utils/browser/is-browser.ts | 3 + src/shared/utils/browser/share.ts | 7 ++ src/shared/utils/helpers/get-query-params.ts | 19 +++++ src/shared/utils/helpers/get-query-string.ts | 10 +++ src/shared/utils/helpers/group-by.ts | 8 ++ src/shared/utils/helpers/poll.ts | 12 +++ src/shared/utils/helpers/sleep.ts | 3 + src/shared/utils/types/query-params.ts | 3 + 25 files changed, 104 insertions(+), 103 deletions(-) create mode 100644 src/shared/utils/browser/can-share.ts create mode 100644 src/shared/utils/browser/is-browser.ts create mode 100644 src/shared/utils/browser/share.ts create mode 100644 src/shared/utils/helpers/get-query-params.ts create mode 100644 src/shared/utils/helpers/get-query-string.ts create mode 100644 src/shared/utils/helpers/group-by.ts create mode 100644 src/shared/utils/helpers/poll.ts create mode 100644 src/shared/utils/helpers/sleep.ts create mode 100644 src/shared/utils/types/query-params.ts diff --git a/src/shared/components/app/navbar.tsx b/src/shared/components/app/navbar.tsx index 8c7c9202f..20d4f2514 100644 --- a/src/shared/components/app/navbar.tsx +++ b/src/shared/components/app/navbar.tsx @@ -11,14 +11,14 @@ import { UserService } from "../../services"; import { HttpService, RequestState } from "../../services/HttpService"; import { donateLemmyUrl, - isBrowser, myAuth, numToSI, - poll, showAvatars, toast, updateUnreadCountsInterval, } from "../../utils"; +import { isBrowser } from "../../utils/browser/is-browser"; +import { poll } from "../../utils/helpers/poll"; import { amAdmin } from "../../utils/roles/am-admin"; import { canCreateCommunity } from "../../utils/roles/can-create-community"; import { Icon } from "../common/icon"; diff --git a/src/shared/components/common/markdown-textarea.tsx b/src/shared/components/common/markdown-textarea.tsx index 9318d3bb8..c1e852433 100644 --- a/src/shared/components/common/markdown-textarea.tsx +++ b/src/shared/components/common/markdown-textarea.tsx @@ -7,7 +7,6 @@ import { HttpService, UserService } from "../../services"; import { concurrentImageUpload, customEmojisLookup, - isBrowser, markdownFieldCharacterLimit, markdownHelpUrl, maxUploadImages, @@ -20,12 +19,12 @@ import { setupTribute, toast, } from "../../utils"; +import { isBrowser } from "../../utils/browser/is-browser"; import { EmojiPicker } from "./emoji-picker"; import { Icon, Spinner } from "./icon"; import { LanguageSelect } from "./language-select"; import NavigationPrompt from "./navigation-prompt"; import ProgressBar from "./progress-bar"; - interface MarkdownTextAreaProps { initialContent?: string; initialLanguageId?: number; diff --git a/src/shared/components/community/communities.tsx b/src/shared/components/community/communities.tsx index 623269439..b98bf251c 100644 --- a/src/shared/components/community/communities.tsx +++ b/src/shared/components/community/communities.tsx @@ -11,17 +11,17 @@ import { InitialFetchRequest } from "../../interfaces"; import { FirstLoadService } from "../../services/FirstLoadService"; import { HttpService, RequestState } from "../../services/HttpService"; import { - QueryParams, editCommunity, getPageFromString, - getQueryParams, - getQueryString, myAuth, myAuthRequired, numToSI, setIsoData, showLocal, } from "../../utils"; +import { getQueryParams } from "../../utils/helpers/get-query-params"; +import { getQueryString } from "../../utils/helpers/get-query-string"; +import type { QueryParams } from "../../utils/types/query-params"; import { HtmlTags } from "../common/html-tags"; import { Spinner } from "../common/icon"; import { ListingTypeSelect } from "../common/listing-type-select"; diff --git a/src/shared/components/community/community.tsx b/src/shared/components/community/community.tsx index 7dc150f33..cb7e95173 100644 --- a/src/shared/components/community/community.tsx +++ b/src/shared/components/community/community.tsx @@ -62,7 +62,6 @@ import { UserService } from "../../services"; import { FirstLoadService } from "../../services/FirstLoadService"; import { HttpService, RequestState } from "../../services/HttpService"; import { - QueryParams, commentsToFlatNodes, communityRSSUrl, editComment, @@ -74,8 +73,6 @@ import { getCommentParentId, getDataTypeString, getPageFromString, - getQueryParams, - getQueryString, myAuth, postToCommentSortType, relTags, @@ -88,6 +85,9 @@ import { updateCommunityBlock, updatePersonBlock, } from "../../utils"; +import { getQueryParams } from "../../utils/helpers/get-query-params"; +import { getQueryString } from "../../utils/helpers/get-query-string"; +import type { QueryParams } from "../../utils/types/query-params"; import { CommentNodes } from "../comment/comment-nodes"; import { BannerIconHeader } from "../common/banner-icon-header"; import { DataTypeSelect } from "../common/data-type-select"; @@ -99,7 +99,6 @@ import { Sidebar } from "../community/sidebar"; import { SiteSidebar } from "../home/site-sidebar"; import { PostListings } from "../post/post-listings"; import { CommunityLink } from "./community-link"; - interface State { communityRes: RequestState; postsRes: RequestState; diff --git a/src/shared/components/home/home.tsx b/src/shared/components/home/home.tsx index 4e23c03c9..ed3afd01a 100644 --- a/src/shared/components/home/home.tsx +++ b/src/shared/components/home/home.tsx @@ -67,13 +67,10 @@ import { getCommentParentId, getDataTypeString, getPageFromString, - getQueryParams, - getQueryString, getRandomFromList, mdToHtml, myAuth, postToCommentSortType, - QueryParams, relTags, restoreScrollPosition, saveScrollPosition, @@ -84,7 +81,10 @@ import { trendingFetchLimit, updatePersonBlock, } from "../../utils"; +import { getQueryParams } from "../../utils/helpers/get-query-params"; +import { getQueryString } from "../../utils/helpers/get-query-string"; import { canCreateCommunity } from "../../utils/roles/can-create-community"; +import type { QueryParams } from "../../utils/types/query-params"; import { CommentNodes } from "../comment/comment-nodes"; import { DataTypeSelect } from "../common/data-type-select"; import { HtmlTags } from "../common/html-tags"; diff --git a/src/shared/components/home/login.tsx b/src/shared/components/home/login.tsx index 381c13bb0..d7e20ec78 100644 --- a/src/shared/components/home/login.tsx +++ b/src/shared/components/home/login.tsx @@ -3,7 +3,8 @@ import { GetSiteResponse, LoginResponse } from "lemmy-js-client"; import { i18n } from "../../i18next"; import { UserService } from "../../services"; import { HttpService, RequestState } from "../../services/HttpService"; -import { isBrowser, myAuth, setIsoData, toast, validEmail } from "../../utils"; +import { myAuth, setIsoData, toast, validEmail } from "../../utils"; +import { isBrowser } from "../../utils/browser/is-browser"; import { HtmlTags } from "../common/html-tags"; import { Spinner } from "../common/icon"; diff --git a/src/shared/components/home/signup.tsx b/src/shared/components/home/signup.tsx index 16a3cc6d3..192393db9 100644 --- a/src/shared/components/home/signup.tsx +++ b/src/shared/components/home/signup.tsx @@ -13,7 +13,6 @@ import { i18n } from "../../i18next"; import { UserService } from "../../services"; import { HttpService, RequestState } from "../../services/HttpService"; import { - isBrowser, joinLemmyUrl, mdToHtml, myAuth, @@ -21,6 +20,7 @@ import { toast, validEmail, } from "../../utils"; +import { isBrowser } from "../../utils/browser/is-browser"; import { HtmlTags } from "../common/html-tags"; import { Icon, Spinner } from "../common/icon"; import { MarkdownTextArea } from "../common/markdown-textarea"; diff --git a/src/shared/components/modlog.tsx b/src/shared/components/modlog.tsx index 4ab5ec563..cd0cfcb9c 100644 --- a/src/shared/components/modlog.tsx +++ b/src/shared/components/modlog.tsx @@ -33,21 +33,21 @@ import { FirstLoadService } from "../services/FirstLoadService"; import { HttpService, RequestState } from "../services/HttpService"; import { Choice, - QueryParams, debounce, fetchLimit, fetchUsers, getIdFromString, getPageFromString, - getQueryParams, - getQueryString, getUpdatedSearchId, myAuth, personToChoice, setIsoData, } from "../utils"; +import { getQueryParams } from "../utils/helpers/get-query-params"; +import { getQueryString } from "../utils/helpers/get-query-string"; import { amAdmin } from "../utils/roles/am-admin"; import { amMod } from "../utils/roles/am-mod"; +import type { QueryParams } from "../utils/types/query-params"; import { HtmlTags } from "./common/html-tags"; import { Icon, Spinner } from "./common/icon"; import { MomentTime } from "./common/moment-time"; diff --git a/src/shared/components/person/profile.tsx b/src/shared/components/person/profile.tsx index 4d9f8f77b..c12114bc8 100644 --- a/src/shared/components/person/profile.tsx +++ b/src/shared/components/person/profile.tsx @@ -53,7 +53,6 @@ import { UserService } from "../../services"; import { FirstLoadService } from "../../services/FirstLoadService"; import { HttpService, RequestState } from "../../services/HttpService"; import { - QueryParams, capitalizeFirstLetter, editComment, editPost, @@ -64,8 +63,6 @@ import { futureDaysToUnixTime, getCommentParentId, getPageFromString, - getQueryParams, - getQueryString, mdToHtml, myAuth, myAuthRequired, @@ -78,9 +75,12 @@ import { toast, updatePersonBlock, } from "../../utils"; +import { getQueryParams } from "../../utils/helpers/get-query-params"; +import { getQueryString } from "../../utils/helpers/get-query-string"; import { canMod } from "../../utils/roles/can-mod"; import { isAdmin } from "../../utils/roles/is-admin"; import { isBanned } from "../../utils/roles/is-banned"; +import type { QueryParams } from "../../utils/types/query-params"; import { BannerIconHeader } from "../common/banner-icon-header"; import { HtmlTags } from "../common/html-tags"; import { Icon, Spinner } from "../common/icon"; diff --git a/src/shared/components/post/create-post.tsx b/src/shared/components/post/create-post.tsx index 71fac79ae..ed1df4c1c 100644 --- a/src/shared/components/post/create-post.tsx +++ b/src/shared/components/post/create-post.tsx @@ -16,14 +16,14 @@ import { } from "../../services/HttpService"; import { Choice, - QueryParams, enableDownvotes, enableNsfw, getIdFromString, - getQueryParams, myAuth, setIsoData, } from "../../utils"; +import { getQueryParams } from "../../utils/helpers/get-query-params"; +import type { QueryParams } from "../../utils/types/query-params"; import { HtmlTags } from "../common/html-tags"; import { Spinner } from "../common/icon"; import { PostForm } from "./post-form"; diff --git a/src/shared/components/post/post-listing.tsx b/src/shared/components/post/post-listing.tsx index 3ec1a4567..4c36f6511 100644 --- a/src/shared/components/post/post-listing.tsx +++ b/src/shared/components/post/post-listing.tsx @@ -28,7 +28,6 @@ import { i18n } from "../../i18next"; import { BanType, PostFormParams, PurgeType, VoteType } from "../../interfaces"; import { UserService } from "../../services"; import { - canShare, futureDaysToUnixTime, hostname, isImage, @@ -41,9 +40,10 @@ import { numToSI, relTags, setupTippy, - share, showScores, } from "../../utils"; +import { canShare } from "../../utils/browser/can-share"; +import { share } from "../../utils/browser/share"; import { amAdmin } from "../../utils/roles/am-admin"; import { amCommunityCreator } from "../../utils/roles/am-community-creator"; import { amMod } from "../../utils/roles/am-mod"; diff --git a/src/shared/components/post/post.tsx b/src/shared/components/post/post.tsx index 9c68532be..250c08a74 100644 --- a/src/shared/components/post/post.tsx +++ b/src/shared/components/post/post.tsx @@ -73,7 +73,6 @@ import { getCommentParentId, getDepthFromComment, getIdFromProps, - isBrowser, isImage, myAuth, restoreScrollPosition, @@ -84,6 +83,7 @@ import { updateCommunityBlock, updatePersonBlock, } from "../../utils"; +import { isBrowser } from "../../utils/browser/is-browser"; import { CommentForm } from "../comment/comment-form"; import { CommentNodes } from "../comment/comment-nodes"; import { HtmlTags } from "../common/html-tags"; diff --git a/src/shared/components/search.tsx b/src/shared/components/search.tsx index 8097dbde4..59bbf616c 100644 --- a/src/shared/components/search.tsx +++ b/src/shared/components/search.tsx @@ -26,7 +26,6 @@ import { FirstLoadService } from "../services/FirstLoadService"; import { HttpService, RequestState } from "../services/HttpService"; import { Choice, - QueryParams, capitalizeFirstLetter, commentsToFlatNodes, communityToChoice, @@ -38,8 +37,6 @@ import { fetchUsers, getIdFromString, getPageFromString, - getQueryParams, - getQueryString, getUpdatedSearchId, myAuth, numToSI, @@ -49,6 +46,9 @@ import { setIsoData, showLocal, } from "../utils"; +import { getQueryParams } from "../utils/helpers/get-query-params"; +import { getQueryString } from "../utils/helpers/get-query-string"; +import type { QueryParams } from "../utils/types/query-params"; import { CommentNodes } from "./comment/comment-nodes"; import { HtmlTags } from "./common/html-tags"; import { Spinner } from "./common/icon"; diff --git a/src/shared/env.ts b/src/shared/env.ts index 576c6c58e..969f87612 100644 --- a/src/shared/env.ts +++ b/src/shared/env.ts @@ -1,4 +1,4 @@ -import { isBrowser } from "./utils"; +import { isBrowser } from "./utils/browser/is-browser"; const testHost = "0.0.0.0:8536"; diff --git a/src/shared/services/UserService.ts b/src/shared/services/UserService.ts index 57c8aecf7..8f553aba2 100644 --- a/src/shared/services/UserService.ts +++ b/src/shared/services/UserService.ts @@ -4,7 +4,8 @@ import jwt_decode from "jwt-decode"; import { LoginResponse, MyUserInfo } from "lemmy-js-client"; import { isHttps } from "../env"; import { i18n } from "../i18next"; -import { isAuthPath, isBrowser, toast } from "../utils"; +import { isAuthPath, toast } from "../utils"; +import { isBrowser } from "../utils/browser/is-browser"; interface Claims { sub: number; diff --git a/src/shared/utils.ts b/src/shared/utils.ts index b1b06e2ec..54b5a3f4a 100644 --- a/src/shared/utils.ts +++ b/src/shared/utils.ts @@ -43,6 +43,8 @@ import { getHttpBase } from "./env"; import { i18n, languages } from "./i18next"; import { CommentNodeI, DataType, IsoData, VoteType } from "./interfaces"; import { HttpService, UserService } from "./services"; +import { isBrowser } from "./utils/browser/is-browser"; +import { groupBy } from "./utils/helpers/group-by"; let Tribute: any; if (isBrowser()) { @@ -1070,10 +1072,6 @@ export function siteBannerCss(banner: string): string { `; } -export function isBrowser() { - return typeof window !== "undefined"; -} - export function setIsoData(context: any): IsoData { // If its the browser, you need to deserialize the data from the window if (isBrowser()) { @@ -1314,64 +1312,12 @@ interface EmojiMartSkin { src: string; } -const groupBy = ( - array: T[], - predicate: (value: T, index: number, array: T[]) => string -) => - array.reduce((acc, value, index, array) => { - (acc[predicate(value, index, array)] ||= []).push(value); - return acc; - }, {} as { [key: string]: T[] }); - -export type QueryParams> = { - [key in keyof T]?: string; -}; - -export function getQueryParams>(processors: { - [K in keyof T]: (param: string) => T[K]; -}): T { - if (isBrowser()) { - const searchParams = new URLSearchParams(window.location.search); - - return Array.from(Object.entries(processors)).reduce( - (acc, [key, process]) => ({ - ...acc, - [key]: process(searchParams.get(key)), - }), - {} as T - ); - } - - return {} as T; -} - -export function getQueryString>( - obj: T -) { - return Object.entries(obj) - .filter(([, val]) => val !== undefined && val !== null) - .reduce( - (acc, [key, val], index) => `${acc}${index > 0 ? "&" : ""}${key}=${val}`, - "?" - ); -} - export function isAuthPath(pathname: string) { return /create_.*|inbox|settings|admin|reports|registration_applications/g.test( pathname ); } -export function canShare() { - return isBrowser() && !!navigator.canShare; -} - -export function share(shareData: ShareData) { - if (isBrowser()) { - navigator.share(shareData); - } -} - export function newVote(voteType: VoteType, myVote?: number): number { if (voteType == VoteType.Upvote) { return myVote == 1 ? 0 : 1; @@ -1379,18 +1325,3 @@ export function newVote(voteType: VoteType, myVote?: number): number { return myVote == -1 ? 0 : -1; } } - -function sleep(millis: number): Promise { - return new Promise(resolve => setTimeout(resolve, millis)); -} - -/** - * Polls / repeatedly runs a promise, every X milliseconds - */ -export async function poll(promiseFn: any, millis: number) { - if (window.document.visibilityState !== "hidden") { - await promiseFn(); - } - await sleep(millis); - return poll(promiseFn, millis); -} diff --git a/src/shared/utils/browser/can-share.ts b/src/shared/utils/browser/can-share.ts new file mode 100644 index 000000000..bec7e8051 --- /dev/null +++ b/src/shared/utils/browser/can-share.ts @@ -0,0 +1,5 @@ +import { isBrowser } from "./is-browser"; + +export function canShare() { + return isBrowser() && !!navigator.canShare; +} diff --git a/src/shared/utils/browser/is-browser.ts b/src/shared/utils/browser/is-browser.ts new file mode 100644 index 000000000..4139b25d9 --- /dev/null +++ b/src/shared/utils/browser/is-browser.ts @@ -0,0 +1,3 @@ +export function isBrowser() { + return typeof window !== "undefined"; +} diff --git a/src/shared/utils/browser/share.ts b/src/shared/utils/browser/share.ts new file mode 100644 index 000000000..b1d1b5bed --- /dev/null +++ b/src/shared/utils/browser/share.ts @@ -0,0 +1,7 @@ +import { isBrowser } from "./is-browser"; + +export function share(shareData: ShareData) { + if (isBrowser()) { + navigator.share(shareData); + } +} diff --git a/src/shared/utils/helpers/get-query-params.ts b/src/shared/utils/helpers/get-query-params.ts new file mode 100644 index 000000000..213d3521a --- /dev/null +++ b/src/shared/utils/helpers/get-query-params.ts @@ -0,0 +1,19 @@ +import { isBrowser } from "../browser/is-browser"; + +export function getQueryParams>(processors: { + [K in keyof T]: (param: string) => T[K]; +}): T { + if (isBrowser()) { + const searchParams = new URLSearchParams(window.location.search); + + return Array.from(Object.entries(processors)).reduce( + (acc, [key, process]) => ({ + ...acc, + [key]: process(searchParams.get(key)), + }), + {} as T + ); + } + + return {} as T; +} diff --git a/src/shared/utils/helpers/get-query-string.ts b/src/shared/utils/helpers/get-query-string.ts new file mode 100644 index 000000000..a66b5af4b --- /dev/null +++ b/src/shared/utils/helpers/get-query-string.ts @@ -0,0 +1,10 @@ +export function getQueryString>( + obj: T +) { + return Object.entries(obj) + .filter(([, val]) => val !== undefined && val !== null) + .reduce( + (acc, [key, val], index) => `${acc}${index > 0 ? "&" : ""}${key}=${val}`, + "?" + ); +} diff --git a/src/shared/utils/helpers/group-by.ts b/src/shared/utils/helpers/group-by.ts new file mode 100644 index 000000000..4dd5d5db8 --- /dev/null +++ b/src/shared/utils/helpers/group-by.ts @@ -0,0 +1,8 @@ +export const groupBy = ( + array: T[], + predicate: (value: T, index: number, array: T[]) => string +) => + array.reduce((acc, value, index, array) => { + (acc[predicate(value, index, array)] ||= []).push(value); + return acc; + }, {} as { [key: string]: T[] }); diff --git a/src/shared/utils/helpers/poll.ts b/src/shared/utils/helpers/poll.ts new file mode 100644 index 000000000..055f17f4f --- /dev/null +++ b/src/shared/utils/helpers/poll.ts @@ -0,0 +1,12 @@ +import { sleep } from "./sleep"; + +/** + * Polls / repeatedly runs a promise, every X milliseconds + */ +export async function poll(promiseFn: any, millis: number) { + if (window.document.visibilityState !== "hidden") { + await promiseFn(); + } + await sleep(millis); + return poll(promiseFn, millis); +} diff --git a/src/shared/utils/helpers/sleep.ts b/src/shared/utils/helpers/sleep.ts new file mode 100644 index 000000000..5b7c53881 --- /dev/null +++ b/src/shared/utils/helpers/sleep.ts @@ -0,0 +1,3 @@ +export function sleep(millis: number): Promise { + return new Promise(resolve => setTimeout(resolve, millis)); +} diff --git a/src/shared/utils/types/query-params.ts b/src/shared/utils/types/query-params.ts new file mode 100644 index 000000000..37705bd82 --- /dev/null +++ b/src/shared/utils/types/query-params.ts @@ -0,0 +1,3 @@ +export type QueryParams> = { + [key in keyof T]?: string; +}; From 6126900bd54a302c871cc52f332a725fe159d04b Mon Sep 17 00:00:00 2001 From: Alec Armbruster Date: Fri, 16 Jun 2023 18:49:28 -0400 Subject: [PATCH 04/47] forgot debounce --- src/shared/components/modlog.tsx | 2 +- src/shared/components/person/settings.tsx | 2 +- src/shared/components/post/post-form.tsx | 2 +- src/shared/components/post/post.tsx | 2 +- src/shared/components/search.tsx | 2 +- src/shared/utils.ts | 46 +---------------------- src/shared/utils/helpers/debounce.ts | 44 ++++++++++++++++++++++ 7 files changed, 50 insertions(+), 50 deletions(-) create mode 100644 src/shared/utils/helpers/debounce.ts diff --git a/src/shared/components/modlog.tsx b/src/shared/components/modlog.tsx index cd0cfcb9c..99f15e501 100644 --- a/src/shared/components/modlog.tsx +++ b/src/shared/components/modlog.tsx @@ -33,7 +33,6 @@ import { FirstLoadService } from "../services/FirstLoadService"; import { HttpService, RequestState } from "../services/HttpService"; import { Choice, - debounce, fetchLimit, fetchUsers, getIdFromString, @@ -43,6 +42,7 @@ import { personToChoice, setIsoData, } from "../utils"; +import { debounce } from "../utils/helpers/debounce"; import { getQueryParams } from "../utils/helpers/get-query-params"; import { getQueryString } from "../utils/helpers/get-query-string"; import { amAdmin } from "../utils/roles/am-admin"; diff --git a/src/shared/components/person/settings.tsx b/src/shared/components/person/settings.tsx index a29f61b00..564daff42 100644 --- a/src/shared/components/person/settings.tsx +++ b/src/shared/components/person/settings.tsx @@ -18,7 +18,6 @@ import { Choice, capitalizeFirstLetter, communityToChoice, - debounce, elementUrl, emDash, enableNsfw, @@ -38,6 +37,7 @@ import { updateCommunityBlock, updatePersonBlock, } from "../../utils"; +import { debounce } from "../../utils/helpers/debounce"; import { HtmlTags } from "../common/html-tags"; import { Icon, Spinner } from "../common/icon"; import { ImageUploadForm } from "../common/image-upload-form"; diff --git a/src/shared/components/post/post-form.tsx b/src/shared/components/post/post-form.tsx index 4640922d0..c21a6e2b8 100644 --- a/src/shared/components/post/post-form.tsx +++ b/src/shared/components/post/post-form.tsx @@ -18,7 +18,6 @@ import { archiveTodayUrl, capitalizeFirstLetter, communityToChoice, - debounce, fetchCommunities, getIdFromString, ghostArchiveUrl, @@ -33,6 +32,7 @@ import { validURL, webArchiveUrl, } from "../../utils"; +import { debounce } from "../../utils/helpers/debounce"; import { Icon, Spinner } from "../common/icon"; import { LanguageSelect } from "../common/language-select"; import { MarkdownTextArea } from "../common/markdown-textarea"; diff --git a/src/shared/components/post/post.tsx b/src/shared/components/post/post.tsx index 250c08a74..2c61f79e7 100644 --- a/src/shared/components/post/post.tsx +++ b/src/shared/components/post/post.tsx @@ -64,7 +64,6 @@ import { buildCommentsTree, commentsToFlatNodes, commentTreeMaxDepth, - debounce, editComment, editWith, enableDownvotes, @@ -84,6 +83,7 @@ import { updatePersonBlock, } from "../../utils"; import { isBrowser } from "../../utils/browser/is-browser"; +import { debounce } from "../../utils/helpers/debounce"; import { CommentForm } from "../comment/comment-form"; import { CommentNodes } from "../comment/comment-nodes"; import { HtmlTags } from "../common/html-tags"; diff --git a/src/shared/components/search.tsx b/src/shared/components/search.tsx index 59bbf616c..d32e40875 100644 --- a/src/shared/components/search.tsx +++ b/src/shared/components/search.tsx @@ -29,7 +29,6 @@ import { capitalizeFirstLetter, commentsToFlatNodes, communityToChoice, - debounce, enableDownvotes, enableNsfw, fetchCommunities, @@ -46,6 +45,7 @@ import { setIsoData, showLocal, } from "../utils"; +import { debounce } from "../utils/helpers/debounce"; import { getQueryParams } from "../utils/helpers/get-query-params"; import { getQueryString } from "../utils/helpers/get-query-string"; import type { QueryParams } from "../utils/types/query-params"; diff --git a/src/shared/utils.ts b/src/shared/utils.ts index 54b5a3f4a..c0caad88a 100644 --- a/src/shared/utils.ts +++ b/src/shared/utils.ts @@ -44,6 +44,7 @@ import { i18n, languages } from "./i18next"; import { CommentNodeI, DataType, IsoData, VoteType } from "./interfaces"; import { HttpService, UserService } from "./services"; import { isBrowser } from "./utils/browser/is-browser"; +import { debounce } from "./utils/helpers/debounce"; import { groupBy } from "./utils/helpers/group-by"; let Tribute: any; @@ -268,51 +269,6 @@ export function getDataTypeString(dt: DataType) { return dt === DataType.Post ? "Post" : "Comment"; } -export function debounce( - func: (...e: T) => R, - wait = 1000, - immediate = false -) { - // 'private' variable for instance - // The returned function will be able to reference this due to closure. - // Each call to the returned function will share this common timer. - let timeout: NodeJS.Timeout | null; - - // Calling debounce returns a new anonymous function - return function () { - // reference the context and args for the setTimeout function - const args = arguments; - - // Should the function be called now? If immediate is true - // and not already in a timeout then the answer is: Yes - const callNow = immediate && !timeout; - - // This is the basic debounce behavior where you can call this - // function several times, but it will only execute once - // [before or after imposing a delay]. - // Each time the returned function is called, the timer starts over. - clearTimeout(timeout ?? undefined); - - // Set the new timeout - timeout = setTimeout(function () { - // Inside the timeout function, clear the timeout variable - // which will let the next execution run when in 'immediate' mode - timeout = null; - - // Check if the function already ran with the immediate flag - if (!immediate) { - // Call the original function with apply - // apply lets you define the 'this' object as well as the arguments - // (both captured before setTimeout) - func.apply(this, args); - } - }, wait); - - // Immediate mode and no wait timer? Execute the function.. - if (callNow) func.apply(this, args); - } as (...e: T) => R; -} - export function getLanguages( override?: string, myUserInfo = UserService.Instance.myUserInfo diff --git a/src/shared/utils/helpers/debounce.ts b/src/shared/utils/helpers/debounce.ts new file mode 100644 index 000000000..7a1e8b19b --- /dev/null +++ b/src/shared/utils/helpers/debounce.ts @@ -0,0 +1,44 @@ +export function debounce( + func: (...e: T) => R, + wait = 1000, + immediate = false +) { + // 'private' variable for instance + // The returned function will be able to reference this due to closure. + // Each call to the returned function will share this common timer. + let timeout: NodeJS.Timeout | null; + + // Calling debounce returns a new anonymous function + return function () { + // reference the context and args for the setTimeout function + const args = arguments; + + // Should the function be called now? If immediate is true + // and not already in a timeout then the answer is: Yes + const callNow = immediate && !timeout; + + // This is the basic debounce behavior where you can call this + // function several times, but it will only execute once + // [before or after imposing a delay]. + // Each time the returned function is called, the timer starts over. + clearTimeout(timeout ?? undefined); + + // Set the new timeout + timeout = setTimeout(function () { + // Inside the timeout function, clear the timeout variable + // which will let the next execution run when in 'immediate' mode + timeout = null; + + // Check if the function already ran with the immediate flag + if (!immediate) { + // Call the original function with apply + // apply lets you define the 'this' object as well as the arguments + // (both captured before setTimeout) + func.apply(this, args); + } + }, wait); + + // Immediate mode and no wait timer? Execute the function.. + if (callNow) func.apply(this, args); + } as (...e: T) => R; +} From 6c6ddd5b5112afcab1641d49b2462083142bf265 Mon Sep 17 00:00:00 2001 From: Alec Armbruster Date: Fri, 16 Jun 2023 18:56:23 -0400 Subject: [PATCH 05/47] reset, merge issues --- .github/CODEOWNERS | 2 +- .github/ISSUE_TEMPLATE/BUG_REPORT.yml | 2 +- .github/ISSUE_TEMPLATE/FEATURE_REQUEST.yml | 2 +- Dockerfile | 2 +- dev.dockerfile | 2 +- package.json | 2 +- src/assets/css/main.css | 24 +++++ src/shared/components/common/html-tags.tsx | 6 +- .../components/common/markdown-textarea.tsx | 98 +++++++++---------- src/shared/components/common/moment-time.tsx | 6 +- src/shared/components/modlog.tsx | 2 +- src/shared/components/person/settings.tsx | 2 +- src/shared/components/post/post-form.tsx | 2 +- src/shared/components/post/post.tsx | 2 +- src/shared/components/search.tsx | 2 +- src/shared/i18next.ts | 26 +---- src/shared/utils.ts | 79 +++++---------- src/shared/utils/helpers/debounce.ts | 44 +++++++++ yarn.lock | 8 +- 19 files changed, 166 insertions(+), 147 deletions(-) create mode 100644 src/shared/utils/helpers/debounce.ts diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 76916e604..6df17d57c 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1 +1 @@ -* @dessalines @SleeplessOne1917 @alectrocute +* @dessalines @SleeplessOne1917 diff --git a/.github/ISSUE_TEMPLATE/BUG_REPORT.yml b/.github/ISSUE_TEMPLATE/BUG_REPORT.yml index ae2d4e51f..2273a1382 100644 --- a/.github/ISSUE_TEMPLATE/BUG_REPORT.yml +++ b/.github/ISSUE_TEMPLATE/BUG_REPORT.yml @@ -21,7 +21,7 @@ body: - label: Is this only a single bug? Do not put multiple bugs in one issue. required: true - label: Is this a server side (not related to the UI) issue? Use the [Lemmy back end](https://github.com/LemmyNet/lemmy) repo. - required: false + required: true - type: textarea id: summary attributes: diff --git a/.github/ISSUE_TEMPLATE/FEATURE_REQUEST.yml b/.github/ISSUE_TEMPLATE/FEATURE_REQUEST.yml index 3c75050ab..2f6f3fc1f 100644 --- a/.github/ISSUE_TEMPLATE/FEATURE_REQUEST.yml +++ b/.github/ISSUE_TEMPLATE/FEATURE_REQUEST.yml @@ -19,7 +19,7 @@ body: - label: Is this only a feature request? Do not put multiple feature requests in one issue. required: true - label: Is this a server side (not related to the UI) issue? Use the [Lemmy back end](https://github.com/LemmyNet/lemmy) repo. - required: false + required: true - type: textarea id: problem attributes: diff --git a/Dockerfile b/Dockerfile index 2b36581d2..3d6d6212d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM node:20.2-alpine as builder +FROM node:alpine as builder RUN apk update && apk add curl yarn python3 build-base gcc wget git --no-cache RUN curl -sf https://gobinaries.com/tj/node-prune | sh diff --git a/dev.dockerfile b/dev.dockerfile index 3bfc10dae..0e925c0a9 100644 --- a/dev.dockerfile +++ b/dev.dockerfile @@ -1,4 +1,4 @@ -FROM node:20.2-alpine as builder +FROM node:alpine as builder RUN apk update && apk add curl yarn python3 build-base gcc wget git --no-cache WORKDIR /usr/src/app diff --git a/package.json b/package.json index b7c48c79b..2298d9e14 100644 --- a/package.json +++ b/package.json @@ -54,7 +54,7 @@ "inferno-server": "^8.1.1", "isomorphic-cookie": "^1.2.4", "jwt-decode": "^3.1.2", - "lemmy-js-client": "0.18.0-rc.1", + "lemmy-js-client": "0.17.2-rc.24", "lodash": "^4.17.21", "markdown-it": "^13.0.1", "markdown-it-container": "^3.0.0", diff --git a/src/assets/css/main.css b/src/assets/css/main.css index 82f8433e8..e1adfc53e 100644 --- a/src/assets/css/main.css +++ b/src/assets/css/main.css @@ -80,6 +80,30 @@ overflow-x: auto; } +.md-div table { + border-collapse: collapse; + width: 100%; + margin-bottom: 1rem; + border: 1px solid var(--dark); +} + +.md-div table th, +.md-div table td { + padding: 0.3rem; + vertical-align: top; + border-top: 1px solid var(--dark); + border: 1px solid var(--dark); +} + +.md-div table thead th { + vertical-align: bottom; + border-bottom: 2px solid var(--dark); +} + +.md-div table tbody + tbody { + border-top: 2px solid var(--dark); +} + .vote-bar { margin-top: -6.5px; } diff --git a/src/shared/components/common/html-tags.tsx b/src/shared/components/common/html-tags.tsx index f32b0fc04..0e6cb2d03 100644 --- a/src/shared/components/common/html-tags.tsx +++ b/src/shared/components/common/html-tags.tsx @@ -2,8 +2,7 @@ import { htmlToText } from "html-to-text"; import { Component } from "inferno"; import { Helmet } from "inferno-helmet"; import { httpExternalPath } from "../../env"; -import { i18n } from "../../i18next"; -import { md } from "../../utils"; +import { getLanguages, md } from "../../utils"; interface HtmlTagsProps { title: string; @@ -18,10 +17,11 @@ export class HtmlTags extends Component { const url = httpExternalPath(this.props.path); const desc = this.props.description; const image = this.props.image; + const lang = getLanguages()[0]; return ( - + {["title", "og:title", "twitter:title"].map(t => ( diff --git a/src/shared/components/common/markdown-textarea.tsx b/src/shared/components/common/markdown-textarea.tsx index 4e1bca11f..c1e852433 100644 --- a/src/shared/components/common/markdown-textarea.tsx +++ b/src/shared/components/common/markdown-textarea.tsx @@ -183,6 +183,53 @@ export class MarkdownTextArea extends Component<
+ {this.props.buttonTitle && ( + + )} + {this.props.replyType && ( + + )} + {this.state.content && ( + + )} + {/* A flex expander */} +
+ + {this.props.showLanguage && ( + + )} {this.getFormatButton("bold", this.handleInsertBold)} {this.getFormatButton("italic", this.handleInsertItalic)} {this.getFormatButton("link", this.handleInsertLink)} @@ -235,57 +282,6 @@ export class MarkdownTextArea extends Component<
- -
- {this.props.showLanguage && ( - - )} - - {/* A flex expander */} -
- - {this.props.buttonTitle && ( - - )} - {this.props.replyType && ( - - )} - {this.state.content && ( - - )} -
); diff --git a/src/shared/components/common/moment-time.tsx b/src/shared/components/common/moment-time.tsx index 30c1682c9..10714f5bb 100644 --- a/src/shared/components/common/moment-time.tsx +++ b/src/shared/components/common/moment-time.tsx @@ -1,7 +1,7 @@ import { Component } from "inferno"; import moment from "moment"; import { i18n } from "../../i18next"; -import { capitalizeFirstLetter } from "../../utils"; +import { capitalizeFirstLetter, getLanguages } from "../../utils"; import { Icon } from "./icon"; interface MomentTimeProps { @@ -15,7 +15,9 @@ export class MomentTime extends Component { constructor(props: any, context: any) { super(props, context); - moment.locale([...i18n.languages]); + const lang = getLanguages(); + + moment.locale(lang); } createdAndModifiedTimes() { diff --git a/src/shared/components/modlog.tsx b/src/shared/components/modlog.tsx index cd0cfcb9c..99f15e501 100644 --- a/src/shared/components/modlog.tsx +++ b/src/shared/components/modlog.tsx @@ -33,7 +33,6 @@ import { FirstLoadService } from "../services/FirstLoadService"; import { HttpService, RequestState } from "../services/HttpService"; import { Choice, - debounce, fetchLimit, fetchUsers, getIdFromString, @@ -43,6 +42,7 @@ import { personToChoice, setIsoData, } from "../utils"; +import { debounce } from "../utils/helpers/debounce"; import { getQueryParams } from "../utils/helpers/get-query-params"; import { getQueryString } from "../utils/helpers/get-query-string"; import { amAdmin } from "../utils/roles/am-admin"; diff --git a/src/shared/components/person/settings.tsx b/src/shared/components/person/settings.tsx index 56d57a7a5..3c8e9fcdd 100644 --- a/src/shared/components/person/settings.tsx +++ b/src/shared/components/person/settings.tsx @@ -18,7 +18,6 @@ import { Choice, capitalizeFirstLetter, communityToChoice, - debounce, elementUrl, emDash, enableNsfw, @@ -37,6 +36,7 @@ import { updateCommunityBlock, updatePersonBlock, } from "../../utils"; +import { debounce } from "../../utils/helpers/debounce"; import { HtmlTags } from "../common/html-tags"; import { Icon, Spinner } from "../common/icon"; import { ImageUploadForm } from "../common/image-upload-form"; diff --git a/src/shared/components/post/post-form.tsx b/src/shared/components/post/post-form.tsx index 4640922d0..c21a6e2b8 100644 --- a/src/shared/components/post/post-form.tsx +++ b/src/shared/components/post/post-form.tsx @@ -18,7 +18,6 @@ import { archiveTodayUrl, capitalizeFirstLetter, communityToChoice, - debounce, fetchCommunities, getIdFromString, ghostArchiveUrl, @@ -33,6 +32,7 @@ import { validURL, webArchiveUrl, } from "../../utils"; +import { debounce } from "../../utils/helpers/debounce"; import { Icon, Spinner } from "../common/icon"; import { LanguageSelect } from "../common/language-select"; import { MarkdownTextArea } from "../common/markdown-textarea"; diff --git a/src/shared/components/post/post.tsx b/src/shared/components/post/post.tsx index 05e4d9b91..a471e6491 100644 --- a/src/shared/components/post/post.tsx +++ b/src/shared/components/post/post.tsx @@ -64,7 +64,6 @@ import { buildCommentsTree, commentsToFlatNodes, commentTreeMaxDepth, - debounce, editComment, editWith, enableDownvotes, @@ -84,6 +83,7 @@ import { updatePersonBlock, } from "../../utils"; import { isBrowser } from "../../utils/browser/is-browser"; +import { debounce } from "../../utils/helpers/debounce"; import { CommentForm } from "../comment/comment-form"; import { CommentNodes } from "../comment/comment-nodes"; import { HtmlTags } from "../common/html-tags"; diff --git a/src/shared/components/search.tsx b/src/shared/components/search.tsx index 59bbf616c..d32e40875 100644 --- a/src/shared/components/search.tsx +++ b/src/shared/components/search.tsx @@ -29,7 +29,6 @@ import { capitalizeFirstLetter, commentsToFlatNodes, communityToChoice, - debounce, enableDownvotes, enableNsfw, fetchCommunities, @@ -46,6 +45,7 @@ import { setIsoData, showLocal, } from "../utils"; +import { debounce } from "../utils/helpers/debounce"; import { getQueryParams } from "../utils/helpers/get-query-params"; import { getQueryString } from "../utils/helpers/get-query-string"; import type { QueryParams } from "../utils/types/query-params"; diff --git a/src/shared/i18next.ts b/src/shared/i18next.ts index 47ca65015..eaedbbf81 100644 --- a/src/shared/i18next.ts +++ b/src/shared/i18next.ts @@ -1,5 +1,4 @@ import i18next, { i18nTyped, Resource } from "i18next"; -import { UserService } from "./services"; import { ar } from "./translations/ar"; import { bg } from "./translations/bg"; import { ca } from "./translations/ca"; @@ -31,7 +30,7 @@ import { sv } from "./translations/sv"; import { vi } from "./translations/vi"; import { zh } from "./translations/zh"; import { zh_Hant } from "./translations/zh_Hant"; -import { isBrowser } from "./utils"; +import { getLanguages } from "./utils"; export const languages = [ { resource: ar, code: "ar", name: "العربية" }, @@ -74,31 +73,12 @@ function format(value: any, format: any): any { return format === "uppercase" ? value.toUpperCase() : value; } -class LanguageDetector { - static readonly type = "languageDetector"; - - detect() { - const langs: string[] = []; - - const myLang = - UserService.Instance.myUserInfo?.local_user_view.local_user - .interface_language ?? "browser"; - - if (myLang !== "browser") langs.push(myLang); - - if (isBrowser()) langs.push(...navigator.languages); - - return langs; - } -} - -i18next.use(LanguageDetector).init({ +i18next.init({ debug: false, compatibilityJSON: "v3", - supportedLngs: languages.map(l => l.code), - nonExplicitSupportedLngs: true, // load: 'languageOnly', // initImmediate: false, + lng: getLanguages()[0], fallbackLng: "en", resources, interpolation: { format }, diff --git a/src/shared/utils.ts b/src/shared/utils.ts index bc6e76f8c..c0caad88a 100644 --- a/src/shared/utils.ts +++ b/src/shared/utils.ts @@ -40,10 +40,11 @@ import moment from "moment"; import tippy from "tippy.js"; import Toastify from "toastify-js"; import { getHttpBase } from "./env"; -import { i18n } from "./i18next"; +import { i18n, languages } from "./i18next"; import { CommentNodeI, DataType, IsoData, VoteType } from "./interfaces"; import { HttpService, UserService } from "./services"; import { isBrowser } from "./utils/browser/is-browser"; +import { debounce } from "./utils/helpers/debounce"; import { groupBy } from "./utils/helpers/group-by"; let Tribute: any; @@ -230,7 +231,6 @@ export function futureDaysToUnixTime(days?: number): number | undefined { const imageRegex = /(http)?s?:?(\/\/[^"']*\.(?:jpg|jpeg|gif|png|svg|webp))/; const videoRegex = /(http)?s?:?(\/\/[^"']*\.(?:mp4|webm))/; -const tldRegex = /([a-z0-9]+\.)*[a-z0-9]+\.[a-z]+/; export function isImage(url: string) { return imageRegex.test(url); @@ -244,10 +244,6 @@ export function validURL(str: string) { return !!new URL(str); } -export function validInstanceTLD(str: string) { - return tldRegex.test(str); -} - export function communityRSSUrl(actorId: string, sort: string): string { const url = new URL(actorId); return `${url.origin}/feeds${url.pathname}.xml?sort=${sort}`; @@ -273,49 +269,29 @@ export function getDataTypeString(dt: DataType) { return dt === DataType.Post ? "Post" : "Comment"; } -export function debounce( - func: (...e: T) => R, - wait = 1000, - immediate = false -) { - // 'private' variable for instance - // The returned function will be able to reference this due to closure. - // Each call to the returned function will share this common timer. - let timeout: NodeJS.Timeout | null; - - // Calling debounce returns a new anonymous function - return function () { - // reference the context and args for the setTimeout function - const args = arguments; - - // Should the function be called now? If immediate is true - // and not already in a timeout then the answer is: Yes - const callNow = immediate && !timeout; - - // This is the basic debounce behavior where you can call this - // function several times, but it will only execute once - // [before or after imposing a delay]. - // Each time the returned function is called, the timer starts over. - clearTimeout(timeout ?? undefined); - - // Set the new timeout - timeout = setTimeout(function () { - // Inside the timeout function, clear the timeout variable - // which will let the next execution run when in 'immediate' mode - timeout = null; - - // Check if the function already ran with the immediate flag - if (!immediate) { - // Call the original function with apply - // apply lets you define the 'this' object as well as the arguments - // (both captured before setTimeout) - func.apply(this, args); - } - }, wait); +export function getLanguages( + override?: string, + myUserInfo = UserService.Instance.myUserInfo +): string[] { + const myLang = myUserInfo?.local_user_view.local_user.interface_language; + const lang = override || myLang || "browser"; - // Immediate mode and no wait timer? Execute the function.. - if (callNow) func.apply(this, args); - } as (...e: T) => R; + if (lang == "browser" && isBrowser()) { + return getBrowserLanguages(); + } else { + return [lang]; + } +} + +function getBrowserLanguages(): string[] { + // Intersect lemmy's langs, with the browser langs + const langs = languages ? languages.map(l => l.code) : ["en"]; + + // NOTE, mobile browsers seem to be missing this list, so append en + const allowedLangs = navigator.languages + .concat("en") + .filter(v => langs.includes(v)); + return allowedLangs; } export async function fetchThemeList(): Promise { @@ -633,7 +609,7 @@ function setupMarkdown() { defs: emojiDefs, }) .disable("image"); - const defaultRenderer = md.renderer.rules.image; + var defaultRenderer = md.renderer.rules.image; md.renderer.rules.image = function ( tokens: Token[], idx: number, @@ -652,9 +628,6 @@ function setupMarkdown() { const alt_text = item.content; return `${alt_text}`; }; - md.renderer.rules.table_open = function () { - return ''; - }; } export function getEmojiMart( @@ -1166,7 +1139,7 @@ export function personSelectName({ export function initializeSite(site?: GetSiteResponse) { UserService.Instance.myUserInfo = site?.my_user; - i18n.changeLanguage(); + i18n.changeLanguage(getLanguages()[0]); if (site) { setupEmojiDataModel(site.custom_emojis ?? []); } diff --git a/src/shared/utils/helpers/debounce.ts b/src/shared/utils/helpers/debounce.ts new file mode 100644 index 000000000..7a1e8b19b --- /dev/null +++ b/src/shared/utils/helpers/debounce.ts @@ -0,0 +1,44 @@ +export function debounce( + func: (...e: T) => R, + wait = 1000, + immediate = false +) { + // 'private' variable for instance + // The returned function will be able to reference this due to closure. + // Each call to the returned function will share this common timer. + let timeout: NodeJS.Timeout | null; + + // Calling debounce returns a new anonymous function + return function () { + // reference the context and args for the setTimeout function + const args = arguments; + + // Should the function be called now? If immediate is true + // and not already in a timeout then the answer is: Yes + const callNow = immediate && !timeout; + + // This is the basic debounce behavior where you can call this + // function several times, but it will only execute once + // [before or after imposing a delay]. + // Each time the returned function is called, the timer starts over. + clearTimeout(timeout ?? undefined); + + // Set the new timeout + timeout = setTimeout(function () { + // Inside the timeout function, clear the timeout variable + // which will let the next execution run when in 'immediate' mode + timeout = null; + + // Check if the function already ran with the immediate flag + if (!immediate) { + // Call the original function with apply + // apply lets you define the 'this' object as well as the arguments + // (both captured before setTimeout) + func.apply(this, args); + } + }, wait); + + // Immediate mode and no wait timer? Execute the function.. + if (callNow) func.apply(this, args); + } as (...e: T) => R; +} diff --git a/yarn.lock b/yarn.lock index 7cd644743..f783f07f8 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5615,10 +5615,10 @@ leac@^0.6.0: resolved "https://registry.yarnpkg.com/leac/-/leac-0.6.0.tgz#dcf136e382e666bd2475f44a1096061b70dc0912" integrity sha512-y+SqErxb8h7nE/fiEX07jsbuhrpO9lL8eca7/Y1nuWV2moNlXhyd59iDGcRf6moVyDMbmTNzL40SUyrFU/yDpg== -lemmy-js-client@0.18.0-rc.1: - version "0.18.0-rc.1" - resolved "https://registry.yarnpkg.com/lemmy-js-client/-/lemmy-js-client-0.18.0-rc.1.tgz#fd0c88810572d90413696011ebaed19e3b8162d8" - integrity sha512-lQe443Nr5UCSoY+IxmT7mBe0IRF6EAZ/4PJSRoPSL+U8A+egMMBPbuxnisHzLsC+eDOWRUIgOqZlwlaRnbmuig== +lemmy-js-client@0.17.2-rc.24: + version "0.17.2-rc.24" + resolved "https://registry.yarnpkg.com/lemmy-js-client/-/lemmy-js-client-0.17.2-rc.24.tgz#3b09233a6d89286e559be2e840d81c0c549562ad" + integrity sha512-aSHz7UTcwnwnNd9poY8tEXP7RA9ieZm9MAfSljcbCNU5ds9CASXYNodmraUVJiqCmT4HWnj7IeVmBC9r7nTHnw== dependencies: cross-fetch "^3.1.5" form-data "^4.0.0" From e164a3b9a1d0477cd8441072c4683c3fdaebb8e3 Mon Sep 17 00:00:00 2001 From: Alec Armbruster Date: Fri, 16 Jun 2023 19:10:25 -0400 Subject: [PATCH 06/47] attempt to fix crazy merge fiasco --- .github/CODEOWNERS | 2 +- .github/ISSUE_TEMPLATE/BUG_REPORT.yml | 2 +- .github/ISSUE_TEMPLATE/FEATURE_REQUEST.yml | 2 +- Dockerfile | 2 +- dev.dockerfile | 2 +- package.json | 2 +- src/assets/css/main.css | 24 ---------------------- src/shared/components/common/html-tags.tsx | 7 +++---- 8 files changed, 9 insertions(+), 34 deletions(-) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 6df17d57c..76916e604 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1 +1 @@ -* @dessalines @SleeplessOne1917 +* @dessalines @SleeplessOne1917 @alectrocute diff --git a/.github/ISSUE_TEMPLATE/BUG_REPORT.yml b/.github/ISSUE_TEMPLATE/BUG_REPORT.yml index 2273a1382..ae2d4e51f 100644 --- a/.github/ISSUE_TEMPLATE/BUG_REPORT.yml +++ b/.github/ISSUE_TEMPLATE/BUG_REPORT.yml @@ -21,7 +21,7 @@ body: - label: Is this only a single bug? Do not put multiple bugs in one issue. required: true - label: Is this a server side (not related to the UI) issue? Use the [Lemmy back end](https://github.com/LemmyNet/lemmy) repo. - required: true + required: false - type: textarea id: summary attributes: diff --git a/.github/ISSUE_TEMPLATE/FEATURE_REQUEST.yml b/.github/ISSUE_TEMPLATE/FEATURE_REQUEST.yml index 2f6f3fc1f..3c75050ab 100644 --- a/.github/ISSUE_TEMPLATE/FEATURE_REQUEST.yml +++ b/.github/ISSUE_TEMPLATE/FEATURE_REQUEST.yml @@ -19,7 +19,7 @@ body: - label: Is this only a feature request? Do not put multiple feature requests in one issue. required: true - label: Is this a server side (not related to the UI) issue? Use the [Lemmy back end](https://github.com/LemmyNet/lemmy) repo. - required: true + required: false - type: textarea id: problem attributes: diff --git a/Dockerfile b/Dockerfile index 3d6d6212d..2b36581d2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM node:alpine as builder +FROM node:20.2-alpine as builder RUN apk update && apk add curl yarn python3 build-base gcc wget git --no-cache RUN curl -sf https://gobinaries.com/tj/node-prune | sh diff --git a/dev.dockerfile b/dev.dockerfile index 0e925c0a9..3bfc10dae 100644 --- a/dev.dockerfile +++ b/dev.dockerfile @@ -1,4 +1,4 @@ -FROM node:alpine as builder +FROM node:20.2-alpine as builder RUN apk update && apk add curl yarn python3 build-base gcc wget git --no-cache WORKDIR /usr/src/app diff --git a/package.json b/package.json index 2298d9e14..b7c48c79b 100644 --- a/package.json +++ b/package.json @@ -54,7 +54,7 @@ "inferno-server": "^8.1.1", "isomorphic-cookie": "^1.2.4", "jwt-decode": "^3.1.2", - "lemmy-js-client": "0.17.2-rc.24", + "lemmy-js-client": "0.18.0-rc.1", "lodash": "^4.17.21", "markdown-it": "^13.0.1", "markdown-it-container": "^3.0.0", diff --git a/src/assets/css/main.css b/src/assets/css/main.css index e1adfc53e..82f8433e8 100644 --- a/src/assets/css/main.css +++ b/src/assets/css/main.css @@ -80,30 +80,6 @@ overflow-x: auto; } -.md-div table { - border-collapse: collapse; - width: 100%; - margin-bottom: 1rem; - border: 1px solid var(--dark); -} - -.md-div table th, -.md-div table td { - padding: 0.3rem; - vertical-align: top; - border-top: 1px solid var(--dark); - border: 1px solid var(--dark); -} - -.md-div table thead th { - vertical-align: bottom; - border-bottom: 2px solid var(--dark); -} - -.md-div table tbody + tbody { - border-top: 2px solid var(--dark); -} - .vote-bar { margin-top: -6.5px; } diff --git a/src/shared/components/common/html-tags.tsx b/src/shared/components/common/html-tags.tsx index 0e6cb2d03..387cd0413 100644 --- a/src/shared/components/common/html-tags.tsx +++ b/src/shared/components/common/html-tags.tsx @@ -2,8 +2,8 @@ import { htmlToText } from "html-to-text"; import { Component } from "inferno"; import { Helmet } from "inferno-helmet"; import { httpExternalPath } from "../../env"; -import { getLanguages, md } from "../../utils"; - +import { i18n } from "../../i18next"; +import { md } from "../../utils"; interface HtmlTagsProps { title: string; path: string; @@ -17,11 +17,10 @@ export class HtmlTags extends Component { const url = httpExternalPath(this.props.path); const desc = this.props.description; const image = this.props.image; - const lang = getLanguages()[0]; return ( - + {["title", "og:title", "twitter:title"].map(t => ( From 8fcde4bdd08280b2565a39bbb005bf49686c7295 Mon Sep 17 00:00:00 2001 From: Alec Armbruster Date: Fri, 16 Jun 2023 19:14:35 -0400 Subject: [PATCH 07/47] more cleanup --- src/shared/components/common/html-tags.tsx | 1 + .../components/common/markdown-textarea.tsx | 98 ++++++++++--------- src/shared/components/common/moment-time.tsx | 6 +- 3 files changed, 54 insertions(+), 51 deletions(-) diff --git a/src/shared/components/common/html-tags.tsx b/src/shared/components/common/html-tags.tsx index 387cd0413..f32b0fc04 100644 --- a/src/shared/components/common/html-tags.tsx +++ b/src/shared/components/common/html-tags.tsx @@ -4,6 +4,7 @@ import { Helmet } from "inferno-helmet"; import { httpExternalPath } from "../../env"; import { i18n } from "../../i18next"; import { md } from "../../utils"; + interface HtmlTagsProps { title: string; path: string; diff --git a/src/shared/components/common/markdown-textarea.tsx b/src/shared/components/common/markdown-textarea.tsx index 36f6283d4..55e73617f 100644 --- a/src/shared/components/common/markdown-textarea.tsx +++ b/src/shared/components/common/markdown-textarea.tsx @@ -184,53 +184,6 @@ export class MarkdownTextArea extends Component<
- {this.props.buttonTitle && ( - - )} - {this.props.replyType && ( - - )} - {this.state.content && ( - - )} - {/* A flex expander */} -
- - {this.props.showLanguage && ( - - )} {this.getFormatButton("bold", this.handleInsertBold)} {this.getFormatButton("italic", this.handleInsertItalic)} {this.getFormatButton("link", this.handleInsertLink)} @@ -283,6 +236,57 @@ export class MarkdownTextArea extends Component<
+ +
+ {this.props.showLanguage && ( + + )} + + {/* A flex expander */} +
+ + {this.props.buttonTitle && ( + + )} + {this.props.replyType && ( + + )} + {this.state.content && ( + + )} +
); diff --git a/src/shared/components/common/moment-time.tsx b/src/shared/components/common/moment-time.tsx index 10714f5bb..30c1682c9 100644 --- a/src/shared/components/common/moment-time.tsx +++ b/src/shared/components/common/moment-time.tsx @@ -1,7 +1,7 @@ import { Component } from "inferno"; import moment from "moment"; import { i18n } from "../../i18next"; -import { capitalizeFirstLetter, getLanguages } from "../../utils"; +import { capitalizeFirstLetter } from "../../utils"; import { Icon } from "./icon"; interface MomentTimeProps { @@ -15,9 +15,7 @@ export class MomentTime extends Component { constructor(props: any, context: any) { super(props, context); - const lang = getLanguages(); - - moment.locale(lang); + moment.locale([...i18n.languages]); } createdAndModifiedTimes() { From 768ed8ea94ffcd418ff4644a312e9b904af37a7e Mon Sep 17 00:00:00 2001 From: Alec Armbruster Date: Fri, 16 Jun 2023 19:16:00 -0400 Subject: [PATCH 08/47] even more cleanup --- src/shared/i18next.ts | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/src/shared/i18next.ts b/src/shared/i18next.ts index eaedbbf81..0a705ae64 100644 --- a/src/shared/i18next.ts +++ b/src/shared/i18next.ts @@ -1,4 +1,5 @@ import i18next, { i18nTyped, Resource } from "i18next"; +import { UserService } from "./services"; import { ar } from "./translations/ar"; import { bg } from "./translations/bg"; import { ca } from "./translations/ca"; @@ -30,7 +31,7 @@ import { sv } from "./translations/sv"; import { vi } from "./translations/vi"; import { zh } from "./translations/zh"; import { zh_Hant } from "./translations/zh_Hant"; -import { getLanguages } from "./utils"; +import { isBrowser } from "./utils/browser/is-browser"; export const languages = [ { resource: ar, code: "ar", name: "العربية" }, @@ -73,12 +74,31 @@ function format(value: any, format: any): any { return format === "uppercase" ? value.toUpperCase() : value; } -i18next.init({ +class LanguageDetector { + static readonly type = "languageDetector"; + + detect() { + const langs: string[] = []; + + const myLang = + UserService.Instance.myUserInfo?.local_user_view.local_user + .interface_language ?? "browser"; + + if (myLang !== "browser") langs.push(myLang); + + if (isBrowser()) langs.push(...navigator.languages); + + return langs; + } +} + +i18next.use(LanguageDetector).init({ debug: false, compatibilityJSON: "v3", + supportedLngs: languages.map(l => l.code), + nonExplicitSupportedLngs: true, // load: 'languageOnly', // initImmediate: false, - lng: getLanguages()[0], fallbackLng: "en", resources, interpolation: { format }, From fbc13249ca2add7be9608402841b5a85f740065d Mon Sep 17 00:00:00 2001 From: Alec Armbruster Date: Fri, 16 Jun 2023 19:18:06 -0400 Subject: [PATCH 09/47] more cleanup --- src/shared/utils.ts | 32 ++++++-------------------------- 1 file changed, 6 insertions(+), 26 deletions(-) diff --git a/src/shared/utils.ts b/src/shared/utils.ts index c0caad88a..6019e4d62 100644 --- a/src/shared/utils.ts +++ b/src/shared/utils.ts @@ -40,7 +40,7 @@ import moment from "moment"; import tippy from "tippy.js"; import Toastify from "toastify-js"; import { getHttpBase } from "./env"; -import { i18n, languages } from "./i18next"; +import { i18n } from "./i18next"; import { CommentNodeI, DataType, IsoData, VoteType } from "./interfaces"; import { HttpService, UserService } from "./services"; import { isBrowser } from "./utils/browser/is-browser"; @@ -231,6 +231,7 @@ export function futureDaysToUnixTime(days?: number): number | undefined { const imageRegex = /(http)?s?:?(\/\/[^"']*\.(?:jpg|jpeg|gif|png|svg|webp))/; const videoRegex = /(http)?s?:?(\/\/[^"']*\.(?:mp4|webm))/; +const tldRegex = /([a-z0-9]+\.)*[a-z0-9]+\.[a-z]+/; export function isImage(url: string) { return imageRegex.test(url); @@ -244,6 +245,10 @@ export function validURL(str: string) { return !!new URL(str); } +export function validInstanceTLD(str: string) { + return tldRegex.test(str); +} + export function communityRSSUrl(actorId: string, sort: string): string { const url = new URL(actorId); return `${url.origin}/feeds${url.pathname}.xml?sort=${sort}`; @@ -269,31 +274,6 @@ export function getDataTypeString(dt: DataType) { return dt === DataType.Post ? "Post" : "Comment"; } -export function getLanguages( - override?: string, - myUserInfo = UserService.Instance.myUserInfo -): string[] { - const myLang = myUserInfo?.local_user_view.local_user.interface_language; - const lang = override || myLang || "browser"; - - if (lang == "browser" && isBrowser()) { - return getBrowserLanguages(); - } else { - return [lang]; - } -} - -function getBrowserLanguages(): string[] { - // Intersect lemmy's langs, with the browser langs - const langs = languages ? languages.map(l => l.code) : ["en"]; - - // NOTE, mobile browsers seem to be missing this list, so append en - const allowedLangs = navigator.languages - .concat("en") - .filter(v => langs.includes(v)); - return allowedLangs; -} - export async function fetchThemeList(): Promise { return fetch("/css/themelist").then(res => res.json()); } From b3a25a3bb38ca6b80922a3472cfb96d91211c42c Mon Sep 17 00:00:00 2001 From: Alec Armbruster Date: Fri, 16 Jun 2023 19:20:43 -0400 Subject: [PATCH 10/47] hopefully last merge fiasco cleanup --- src/shared/utils.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/shared/utils.ts b/src/shared/utils.ts index 6019e4d62..6f6e61c74 100644 --- a/src/shared/utils.ts +++ b/src/shared/utils.ts @@ -589,7 +589,7 @@ function setupMarkdown() { defs: emojiDefs, }) .disable("image"); - var defaultRenderer = md.renderer.rules.image; + const defaultRenderer = md.renderer.rules.image; md.renderer.rules.image = function ( tokens: Token[], idx: number, @@ -608,6 +608,9 @@ function setupMarkdown() { const alt_text = item.content; return `${alt_text}`; }; + md.renderer.rules.table_open = function () { + return '
'; + }; } export function getEmojiMart( @@ -1119,7 +1122,7 @@ export function personSelectName({ export function initializeSite(site?: GetSiteResponse) { UserService.Instance.myUserInfo = site?.my_user; - i18n.changeLanguage(getLanguages()[0]); + i18n.changeLanguage(); if (site) { setupEmojiDataModel(site.custom_emojis ?? []); } From b0c39ad5f5960cbf8f332f963fcb67846a6fe66e Mon Sep 17 00:00:00 2001 From: Alec Armbruster Date: Fri, 16 Jun 2023 19:22:12 -0400 Subject: [PATCH 11/47] and of course, yarn.lock --- yarn.lock | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/yarn.lock b/yarn.lock index f783f07f8..7cd644743 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5615,10 +5615,10 @@ leac@^0.6.0: resolved "https://registry.yarnpkg.com/leac/-/leac-0.6.0.tgz#dcf136e382e666bd2475f44a1096061b70dc0912" integrity sha512-y+SqErxb8h7nE/fiEX07jsbuhrpO9lL8eca7/Y1nuWV2moNlXhyd59iDGcRf6moVyDMbmTNzL40SUyrFU/yDpg== -lemmy-js-client@0.17.2-rc.24: - version "0.17.2-rc.24" - resolved "https://registry.yarnpkg.com/lemmy-js-client/-/lemmy-js-client-0.17.2-rc.24.tgz#3b09233a6d89286e559be2e840d81c0c549562ad" - integrity sha512-aSHz7UTcwnwnNd9poY8tEXP7RA9ieZm9MAfSljcbCNU5ds9CASXYNodmraUVJiqCmT4HWnj7IeVmBC9r7nTHnw== +lemmy-js-client@0.18.0-rc.1: + version "0.18.0-rc.1" + resolved "https://registry.yarnpkg.com/lemmy-js-client/-/lemmy-js-client-0.18.0-rc.1.tgz#fd0c88810572d90413696011ebaed19e3b8162d8" + integrity sha512-lQe443Nr5UCSoY+IxmT7mBe0IRF6EAZ/4PJSRoPSL+U8A+egMMBPbuxnisHzLsC+eDOWRUIgOqZlwlaRnbmuig== dependencies: cross-fetch "^3.1.5" form-data "^4.0.0" From 571b1faf70c3ed7d5dc1a086c491c63ea7dfbede Mon Sep 17 00:00:00 2001 From: Alec Armbruster Date: Sat, 17 Jun 2023 08:46:19 -0400 Subject: [PATCH 12/47] remove comments --- src/shared/utils/helpers/debounce.ts | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/src/shared/utils/helpers/debounce.ts b/src/shared/utils/helpers/debounce.ts index 7a1e8b19b..d5cd7017c 100644 --- a/src/shared/utils/helpers/debounce.ts +++ b/src/shared/utils/helpers/debounce.ts @@ -3,42 +3,22 @@ export function debounce( wait = 1000, immediate = false ) { - // 'private' variable for instance - // The returned function will be able to reference this due to closure. - // Each call to the returned function will share this common timer. let timeout: NodeJS.Timeout | null; - // Calling debounce returns a new anonymous function return function () { - // reference the context and args for the setTimeout function const args = arguments; - - // Should the function be called now? If immediate is true - // and not already in a timeout then the answer is: Yes const callNow = immediate && !timeout; - // This is the basic debounce behavior where you can call this - // function several times, but it will only execute once - // [before or after imposing a delay]. - // Each time the returned function is called, the timer starts over. clearTimeout(timeout ?? undefined); - // Set the new timeout timeout = setTimeout(function () { - // Inside the timeout function, clear the timeout variable - // which will let the next execution run when in 'immediate' mode timeout = null; - // Check if the function already ran with the immediate flag if (!immediate) { - // Call the original function with apply - // apply lets you define the 'this' object as well as the arguments - // (both captured before setTimeout) func.apply(this, args); } }, wait); - // Immediate mode and no wait timer? Execute the function.. if (callNow) func.apply(this, args); } as (...e: T) => R; } From f8fd90cc2edc77af4dc6d463da8adb499a77b971 Mon Sep 17 00:00:00 2001 From: Alec Armbruster Date: Sat, 17 Jun 2023 08:47:43 -0400 Subject: [PATCH 13/47] fix accidental changes --- src/shared/components/common/markdown-textarea.tsx | 1 + src/shared/components/community/community.tsx | 1 + 2 files changed, 2 insertions(+) diff --git a/src/shared/components/common/markdown-textarea.tsx b/src/shared/components/common/markdown-textarea.tsx index 094a8dd3e..c03c68ebe 100644 --- a/src/shared/components/common/markdown-textarea.tsx +++ b/src/shared/components/common/markdown-textarea.tsx @@ -26,6 +26,7 @@ import { Icon, Spinner } from "./icon"; import { LanguageSelect } from "./language-select"; import NavigationPrompt from "./navigation-prompt"; import ProgressBar from "./progress-bar"; + interface MarkdownTextAreaProps { initialContent?: string; initialLanguageId?: number; diff --git a/src/shared/components/community/community.tsx b/src/shared/components/community/community.tsx index 5f1b37af4..54ecfcd7a 100644 --- a/src/shared/components/community/community.tsx +++ b/src/shared/components/community/community.tsx @@ -62,6 +62,7 @@ import { UserService } from "../../services"; import { FirstLoadService } from "../../services/FirstLoadService"; import { HttpService, RequestState } from "../../services/HttpService"; import { + RouteDataResponse, commentsToFlatNodes, communityRSSUrl, editComment, From ec1d3726eda1fcfcc8fa08706c1bb42409e60974 Mon Sep 17 00:00:00 2001 From: Jay Sitter Date: Sat, 17 Jun 2023 13:08:56 -0400 Subject: [PATCH 14/47] fix(a11y): Add aria-label to fetaured pins --- src/shared/components/post/post-listing.tsx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/shared/components/post/post-listing.tsx b/src/shared/components/post/post-listing.tsx index b9d412507..36d96a967 100644 --- a/src/shared/components/post/post-listing.tsx +++ b/src/shared/components/post/post-listing.tsx @@ -582,7 +582,8 @@ export class PostListing extends Component { {post.featured_community && ( @@ -590,7 +591,8 @@ export class PostListing extends Component { {post.featured_local && ( From b5d6eda2d6e94eb02d6dca33516a9ddaf9b46b54 Mon Sep 17 00:00:00 2001 From: Jay Sitter Date: Sat, 17 Jun 2023 14:27:46 -0400 Subject: [PATCH 15/47] Empty commit to re-trigger Woodpecker job From 7c264916a3f5ac329d4003abc5ce7068f0fd05ba Mon Sep 17 00:00:00 2001 From: Jay Sitter Date: Sat, 17 Jun 2023 18:03:12 -0400 Subject: [PATCH 16/47] feat: Move advanced post menu into dropdown --- src/shared/components/post/post-listing.tsx | 214 +++++++++++--------- 1 file changed, 121 insertions(+), 93 deletions(-) diff --git a/src/shared/components/post/post-listing.tsx b/src/shared/components/post/post-listing.tsx index 36d96a967..99bec6297 100644 --- a/src/shared/components/post/post-listing.tsx +++ b/src/shared/components/post/post-listing.tsx @@ -661,6 +661,17 @@ export class PostListing extends Component { ); } + get hasAdvancedButtons() { + return ( + this.myPost || + (this.showBody && this.postView.post.body) || + amMod(this.props.moderators) || + amAdmin() || + this.canMod_ || + this.canAdmin_ + ); + } + postActions(mobile = false) { // Possible enhancement: Priority+ pattern instead of just hard coding which get hidden behind the show more button. // Possible enhancement: Make each button a component. @@ -669,37 +680,52 @@ export class PostListing extends Component { <> {this.saveButton} {this.crossPostButton} - {mobile && this.showMoreButton} - {(!mobile || this.state.showAdvanced) && ( - <> - {!this.myPost && ( - <> - {this.reportButton} - {this.blockButton} - - )} - {this.myPost && (this.showBody || this.state.showAdvanced) && ( - <> - {this.editButton} - {this.deleteButton} - - )} - - )} - {this.state.showAdvanced && ( - <> - {this.showBody && post_view.post.body && this.viewSourceButton} - {/* Any mod can do these, not limited to hierarchy*/} - {(amMod(this.props.moderators) || amAdmin()) && ( - <> - {this.lockButton} - {this.featureButton} - - )} - {(this.canMod_ || this.canAdmin_) && <>{this.modRemoveButton}} - + + {this.showBody && post_view.post.body && this.viewSourceButton} + + {this.hasAdvancedButtons && ( +
+ + +
    + {!this.myPost ? ( + <> +
  • {this.reportButton}
  • +
  • {this.blockButton}
  • + + ) : ( + <> +
  • {this.editButton}
  • +
  • {this.deleteButton}
  • + + )} + + {/* Any mod can do these, not limited to hierarchy*/} + {(amMod(this.props.moderators) || amAdmin()) && ( + <> +
  • +
    +
  • +
  • {this.lockButton}
  • + {this.featureButtons} + + )} + + {(this.canMod_ || this.canAdmin_) && ( +
  • {this.modRemoveButton}
  • + )} +
+
)} - {!mobile && this.showMoreButton} ); } @@ -848,7 +874,7 @@ export class PostListing extends Component { get reportButton() { return ( ); } @@ -889,7 +916,7 @@ export class PostListing extends Component { const label = !deleted ? i18n.t("delete") : i18n.t("restore"); return ( ); } - get showMoreButton() { - return ( - - ); - } - get viewSourceButton() { return ( ); } - get featureButton() { + get featureButtons() { const featuredCommunity = this.postView.post.featured_community; const labelCommunity = featuredCommunity ? i18n.t("unfeature_from_community") @@ -971,48 +991,56 @@ export class PostListing extends Component { ? i18n.t("unfeature_from_local") : i18n.t("feature_in_local"); return ( - - - {amAdmin() && ( + <> +
  • - )} - +
  • +
  • + {amAdmin() && ( + + )} +
  • + ); } @@ -1020,7 +1048,7 @@ export class PostListing extends Component { const removed = this.postView.post.removed; return ( @@ -961,7 +959,6 @@ export class PostListing extends Component { From fb2c9f74916cd61cc738c92c15b29f15ecf106f8 Mon Sep 17 00:00:00 2001 From: Jay Sitter Date: Sat, 17 Jun 2023 19:10:53 -0400 Subject: [PATCH 20/47] fix(a11y): Add aria-controls for advanced button dropdown --- src/shared/components/post/post-listing.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/shared/components/post/post-listing.tsx b/src/shared/components/post/post-listing.tsx index 1ba9bb1c1..afe7f89bf 100644 --- a/src/shared/components/post/post-listing.tsx +++ b/src/shared/components/post/post-listing.tsx @@ -691,12 +691,13 @@ export class PostListing extends Component { data-tippy-content={i18n.t("more")} data-bs-toggle="dropdown" aria-expanded="false" + aria-controls="advancedButtonsDropdown" aria-label={i18n.t("more")} > -
      +
        {!this.myPost ? ( <>
      • {this.reportButton}
      • From b4c83b214b3ca1a5f0f9930d469f6b6602f54c5d Mon Sep 17 00:00:00 2001 From: Jay Sitter Date: Sat, 17 Jun 2023 21:02:58 -0400 Subject: [PATCH 21/47] fix: Fix vertical alignment and border radius of advanced dropdown menu items --- src/shared/components/post/post-listing.tsx | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/shared/components/post/post-listing.tsx b/src/shared/components/post/post-listing.tsx index afe7f89bf..319c8b507 100644 --- a/src/shared/components/post/post-listing.tsx +++ b/src/shared/components/post/post-listing.tsx @@ -875,7 +875,7 @@ export class PostListing extends Component { get reportButton() { return ( - ))} - {post.removed && ( - - {i18n.t("removed")} - - )} - {post.deleted && ( - - - - )} - {post.locked && ( - - - - )} - {post.featured_community && ( - - - - )} - {post.featured_local && ( - - - - )} - {post.nsfw && ( - - {i18n.t("nsfw")} - - )} + {(url && isImage(url)) || + (post.thumbnail_url && ( + + ))} + {post.removed && ( + + {i18n.t("removed")} + + )} + {post.deleted && ( + + + + )} + {post.locked && ( + + + + )} + {post.featured_community && ( + + + + )} + {post.featured_local && ( + + + + )} + {post.nsfw && ( + + {i18n.t("nsfw")} + + )} ); } From 3e0ad0d56de0f9ef528c502e8c1427247a637a96 Mon Sep 17 00:00:00 2001 From: Jay Sitter Date: Sun, 18 Jun 2023 00:41:47 -0400 Subject: [PATCH 25/47] fix: Fix display inline of post title --- src/shared/components/post/post-listing.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/shared/components/post/post-listing.tsx b/src/shared/components/post/post-listing.tsx index 1120de1c8..222e4857a 100644 --- a/src/shared/components/post/post-listing.tsx +++ b/src/shared/components/post/post-listing.tsx @@ -497,7 +497,7 @@ export class PostListing extends Component { const post = this.postView.post; return ( { to={`/post/${post.id}`} title={i18n.t("comments")} > -
        From c444b3f0c0a3e910e205d860ceb65dd977c0b56f Mon Sep 17 00:00:00 2001 From: Dessalines Date: Mon, 19 Jun 2023 11:52:00 -0400 Subject: [PATCH 26/47] Updating translations. --- lemmy-translations | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lemmy-translations b/lemmy-translations index c9a07885f..7fc71d086 160000 --- a/lemmy-translations +++ b/lemmy-translations @@ -1 +1 @@ -Subproject commit c9a07885f35cf334d3cf167cb57587a8177fc3fb +Subproject commit 7fc71d0860bbe5c6d620ec27112350ffe5b9229c From b7da6851aad9af080838d6d3e5a4c1f05a4cab95 Mon Sep 17 00:00:00 2001 From: Dessalines Date: Mon, 19 Jun 2023 11:53:18 -0400 Subject: [PATCH 27/47] Fixing missing class for language select. --- src/shared/components/common/language-select.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/shared/components/common/language-select.tsx b/src/shared/components/common/language-select.tsx index 09e9c968d..e80c345ec 100644 --- a/src/shared/components/common/language-select.tsx +++ b/src/shared/components/common/language-select.tsx @@ -100,8 +100,8 @@ export class LanguageSelect extends Component { return ( { onSubmit={linkEvent(this, this.handleReportComment)} >
      {this.state.showRemoveDialog && (
      -
      +
      {/* TODO hold off on expires for now */} - {/*
      */} + {/*
      */} {/* */} - {/* */} + {/* */} {/*
      */} -
      +

    - +
    +
    ); diff --git a/src/shared/components/home/setup.tsx b/src/shared/components/home/setup.tsx index b658bd243..b72dd3c54 100644 --- a/src/shared/components/home/setup.tsx +++ b/src/shared/components/home/setup.tsx @@ -86,7 +86,7 @@ export class Setup extends Component { return (
    {i18n.t("setup_admin")}
    -
    +
    @@ -103,7 +103,7 @@ export class Setup extends Component { />
    -
    +
    @@ -120,7 +120,7 @@ export class Setup extends Component { />
    -
    +
    @@ -138,7 +138,7 @@ export class Setup extends Component { />
    -
    +
    @@ -156,7 +156,7 @@ export class Setup extends Component { />
    -
    +
    -
    +
    - + {i18n.t("cake_day_title")}{" "} {moment .utc(pv.person.published) @@ -636,14 +637,14 @@ export class Profile extends Component< return ( showBanDialog && ( -
    +
    -
    +
    {/* TODO hold off on expires until later */} - {/*
    */} + {/*
    */} {/* */} - {/* */} + {/* */} {/*
    */} -
    +
    ); } diff --git a/src/shared/components/person/reports.tsx b/src/shared/components/person/reports.tsx index 99a033364..d9ac7a3d5 100644 --- a/src/shared/components/person/reports.tsx +++ b/src/shared/components/person/reports.tsx @@ -193,6 +193,7 @@ export class Reports extends Component { > { > { > { > { > { > { selects() { return (
    - {this.unreadOrAllRadios()} - {this.messageTypeRadios()} + {this.unreadOrAllRadios()} + {this.messageTypeRadios()}
    ); } diff --git a/src/shared/components/person/settings.tsx b/src/shared/components/person/settings.tsx index 34303cb27..0ea623d82 100644 --- a/src/shared/components/person/settings.tsx +++ b/src/shared/components/person/settings.tsx @@ -110,7 +110,7 @@ const Filter = ({ onChange: (choice: Choice) => void; loading: boolean; }) => ( -
    +
    +
    )} @@ -316,7 +316,7 @@ export class PostForm extends Component { )}
    -
    +
    @@ -342,7 +342,7 @@ export class PostForm extends Component {
    -
    +
    {
    {!this.props.post_view && ( -
    +
    @@ -378,7 +378,7 @@ export class PostForm extends Component {
    )} {this.props.enableNsfw && ( -
    +
    {i18n.t("nsfw")} @@ -412,12 +412,12 @@ export class PostForm extends Component { value={this.state.form.honeypot} onInput={linkEvent(this, this.handleHoneyPotChange)} /> -
    +
    ))} {post.removed && ( - + {i18n.t("removed")} )} {post.deleted && ( @@ -535,7 +535,7 @@ export class PostListing extends Component { )} {post.locked && ( @@ -543,7 +543,7 @@ export class PostListing extends Component { )} {post.featured_community && ( @@ -552,7 +552,7 @@ export class PostListing extends Component { )} {post.featured_local && ( @@ -560,7 +560,7 @@ export class PostListing extends Component { )} {post.nsfw && ( - + {i18n.t("nsfw")} )} @@ -595,9 +595,9 @@ export class PostListing extends Component { return dupes && dupes.length > 0 ? (