From e4f9c31cfa17196a908d98757319e83353ed6639 Mon Sep 17 00:00:00 2001 From: Alec Armbruster <35377827+alectrocute@users.noreply.github.com> Date: Tue, 20 Jun 2023 10:17:16 -0400 Subject: [PATCH] make suggested changes --- src/shared/components/app/navbar.tsx | 7 +++--- .../components/comment/comment-node.tsx | 14 ++++++----- .../components/community/communities.tsx | 5 ++-- src/shared/components/community/community.tsx | 5 ++-- src/shared/components/community/sidebar.tsx | 4 +-- src/shared/components/home/home.tsx | 11 ++++---- src/shared/components/home/login.tsx | 2 +- src/shared/components/home/signup.tsx | 2 +- src/shared/components/modlog.tsx | 9 +++---- src/shared/components/person/profile.tsx | 9 +++---- src/shared/components/person/reports.tsx | 2 +- src/shared/components/person/settings.tsx | 2 +- src/shared/components/post/create-post.tsx | 4 +-- src/shared/components/post/post-listing.tsx | 21 ++++++++-------- src/shared/components/post/post.tsx | 4 +-- src/shared/components/search.tsx | 6 ++--- src/shared/utils/browser/can-share.ts | 2 +- src/shared/utils/browser/index.ts | 5 ++++ src/shared/utils/browser/share.ts | 2 +- src/shared/utils/helpers/get-query-params.ts | 2 +- src/shared/utils/helpers/index.ts | 8 ++++++ src/shared/utils/roles/am-mod.ts | 2 +- src/shared/utils/roles/can-admin.ts | 2 +- .../utils/roles/can-create-community.ts | 2 +- src/shared/utils/roles/index.ts | 25 +++++++++++++++++++ src/shared/utils/types/index.ts | 3 +++ tsconfig.json | 8 +++++- 27 files changed, 102 insertions(+), 66 deletions(-) create mode 100644 src/shared/utils/browser/index.ts create mode 100644 src/shared/utils/helpers/index.ts create mode 100644 src/shared/utils/roles/index.ts create mode 100644 src/shared/utils/types/index.ts diff --git a/src/shared/components/app/navbar.tsx b/src/shared/components/app/navbar.tsx index 9f68656a..d412e006 100644 --- a/src/shared/components/app/navbar.tsx +++ b/src/shared/components/app/navbar.tsx @@ -1,3 +1,6 @@ +import { isBrowser } from "@utils/browser"; +import { poll } from "@utils/helpers"; +import { amAdmin, canCreateCommunity } from "@utils/roles"; import { Component, createRef, linkEvent } from "inferno"; import { NavLink } from "inferno-router"; import { @@ -17,10 +20,6 @@ import { 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"; 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 bcbd6050..e60ad437 100644 --- a/src/shared/components/comment/comment-node.tsx +++ b/src/shared/components/comment/comment-node.tsx @@ -1,3 +1,11 @@ +import { + amCommunityCreator, + canAdmin, + canMod, + isAdmin, + isBanned, + isMod, +} from "@utils/roles"; import classNames from "classnames"; import { Component, InfernoNode, linkEvent } from "inferno"; import { Link } from "inferno-router"; @@ -53,12 +61,6 @@ 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/communities.tsx b/src/shared/components/community/communities.tsx index 6a2ae6ad..a64b9e96 100644 --- a/src/shared/components/community/communities.tsx +++ b/src/shared/components/community/communities.tsx @@ -1,3 +1,5 @@ +import { getQueryParams, getQueryString } from "@utils/helpers"; +import type { QueryParams } from "@utils/types"; import { Component, linkEvent } from "inferno"; import { CommunityResponse, @@ -20,9 +22,6 @@ 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 { 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 42a77836..203288c5 100644 --- a/src/shared/components/community/community.tsx +++ b/src/shared/components/community/community.tsx @@ -1,3 +1,5 @@ +import { getQueryParams, getQueryString } from "@utils/helpers"; +import type { QueryParams } from "@utils/types"; import { Component, linkEvent } from "inferno"; import { RouteComponentProps } from "inferno-router/dist/Route"; import { @@ -86,9 +88,6 @@ 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"; diff --git a/src/shared/components/community/sidebar.tsx b/src/shared/components/community/sidebar.tsx index 72c94c09..2396b527 100644 --- a/src/shared/components/community/sidebar.tsx +++ b/src/shared/components/community/sidebar.tsx @@ -1,3 +1,4 @@ +import { amAdmin, amMod, amTopMod } from "@utils/roles"; import { Component, InfernoNode, linkEvent } from "inferno"; import { T } from "inferno-i18next-dess"; import { Link } from "inferno-router"; @@ -17,9 +18,6 @@ import { import { i18n } from "../../i18next"; import { UserService } from "../../services"; import { getUnixTime, hostname, mdToHtml, myAuthRequired } 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 { Badges } from "../common/badges"; import { BannerIconHeader } from "../common/banner-icon-header"; import { Icon, PurgeWarning, Spinner } from "../common/icon"; diff --git a/src/shared/components/home/home.tsx b/src/shared/components/home/home.tsx index 4a1e9d70..deca4589 100644 --- a/src/shared/components/home/home.tsx +++ b/src/shared/components/home/home.tsx @@ -1,5 +1,8 @@ +import { getQueryParams, getQueryString } from "@utils/helpers"; +import { canCreateCommunity } from "@utils/roles"; +import type { QueryParams } from "@utils/types"; import { NoOptionI18nKeys } from "i18next"; -import { Component, linkEvent, MouseEventHandler } from "inferno"; +import { Component, MouseEventHandler, linkEvent } from "inferno"; import { T } from "inferno-i18next-dess"; import { Link } from "inferno-router"; import { @@ -57,6 +60,7 @@ import { UserService } from "../../services"; import { FirstLoadService } from "../../services/FirstLoadService"; import { HttpService, RequestState } from "../../services/HttpService"; import { + RouteDataResponse, commentsToFlatNodes, editComment, editPost, @@ -73,7 +77,6 @@ import { postToCommentSortType, relTags, restoreScrollPosition, - RouteDataResponse, saveScrollPosition, setIsoData, setupTippy, @@ -82,10 +85,6 @@ 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 e25222e0..d1b3abd0 100644 --- a/src/shared/components/home/login.tsx +++ b/src/shared/components/home/login.tsx @@ -1,10 +1,10 @@ +import { isBrowser } from "@utils/browser"; import { Component, linkEvent } from "inferno"; import { GetSiteResponse, LoginResponse } from "lemmy-js-client"; import { i18n } from "../../i18next"; import { UserService } from "../../services"; import { HttpService, RequestState } from "../../services/HttpService"; 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 287bdb7b..6961a14a 100644 --- a/src/shared/components/home/signup.tsx +++ b/src/shared/components/home/signup.tsx @@ -1,3 +1,4 @@ +import { isBrowser } from "@utils/browser"; import { Options, passwordStrength } from "check-password-strength"; import { NoOptionI18nKeys } from "i18next"; import { Component, linkEvent } from "inferno"; @@ -20,7 +21,6 @@ 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 3ea910c5..a37486f9 100644 --- a/src/shared/components/modlog.tsx +++ b/src/shared/components/modlog.tsx @@ -1,3 +1,6 @@ +import { debounce, getQueryParams, getQueryString } from "@utils/helpers"; +import { amAdmin, amMod } from "@utils/roles"; +import type { QueryParams } from "@utils/types"; import { NoOptionI18nKeys } from "i18next"; import { Component, linkEvent } from "inferno"; import { T } from "inferno-i18next-dess"; @@ -44,12 +47,6 @@ 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"; -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 d99ab124..b4bec066 100644 --- a/src/shared/components/person/profile.tsx +++ b/src/shared/components/person/profile.tsx @@ -1,3 +1,6 @@ +import { getQueryParams, getQueryString } from "@utils/helpers"; +import { canMod, isAdmin, isBanned } from "@utils/roles"; +import type { QueryParams } from "@utils/types"; import classNames from "classnames"; import { NoOptionI18nKeys } from "i18next"; import { Component, linkEvent } from "inferno"; @@ -76,12 +79,6 @@ 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/person/reports.tsx b/src/shared/components/person/reports.tsx index ce9d215a..de303a87 100644 --- a/src/shared/components/person/reports.tsx +++ b/src/shared/components/person/reports.tsx @@ -1,3 +1,4 @@ +import { amAdmin } from "@utils/roles"; import { Component, linkEvent } from "inferno"; import { CommentReportResponse, @@ -31,7 +32,6 @@ 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/person/settings.tsx b/src/shared/components/person/settings.tsx index 7cb9308c..08567dcb 100644 --- a/src/shared/components/person/settings.tsx +++ b/src/shared/components/person/settings.tsx @@ -1,3 +1,4 @@ +import { debounce } from "@utils/helpers"; import { NoOptionI18nKeys } from "i18next"; import { Component, linkEvent } from "inferno"; import { @@ -35,7 +36,6 @@ 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/create-post.tsx b/src/shared/components/post/create-post.tsx index 4f367712..ad231346 100644 --- a/src/shared/components/post/create-post.tsx +++ b/src/shared/components/post/create-post.tsx @@ -1,3 +1,5 @@ +import { getQueryParams } from "@utils/helpers"; +import type { QueryParams } from "@utils/types"; import { Component } from "inferno"; import { RouteComponentProps } from "inferno-router/dist/Route"; import { @@ -24,8 +26,6 @@ import { 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 914c16d3..928c1ece 100644 --- a/src/shared/components/post/post-listing.tsx +++ b/src/shared/components/post/post-listing.tsx @@ -1,3 +1,14 @@ +import { canShare, share } from "@utils/browser"; +import { + amAdmin, + amCommunityCreator, + amMod, + canAdmin, + canMod, + isAdmin, + isBanned, + isMod, +} from "@utils/roles"; import classNames from "classnames"; import { Component, linkEvent } from "inferno"; import { Link } from "inferno-router"; @@ -42,16 +53,6 @@ import { setupTippy, 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"; -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/components/post/post.tsx b/src/shared/components/post/post.tsx index 8b10c058..60059fee 100644 --- a/src/shared/components/post/post.tsx +++ b/src/shared/components/post/post.tsx @@ -1,3 +1,5 @@ +import { isBrowser } from "@utils/browser"; +import { debounce } from "@utils/helpers"; import autosize from "autosize"; import { Component, createRef, linkEvent, RefObject } from "inferno"; import { @@ -83,8 +85,6 @@ import { updateCommunityBlock, 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 844737cc..0dc4eb77 100644 --- a/src/shared/components/search.tsx +++ b/src/shared/components/search.tsx @@ -1,3 +1,5 @@ +import { debounce, getQueryParams, getQueryString } from "@utils/helpers"; +import type { QueryParams } from "@utils/types"; import type { NoOptionI18nKeys } from "i18next"; import { Component, linkEvent } from "inferno"; import { @@ -46,10 +48,6 @@ 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"; import { CommentNodes } from "./comment/comment-nodes"; import { HtmlTags } from "./common/html-tags"; import { Spinner } from "./common/icon"; diff --git a/src/shared/utils/browser/can-share.ts b/src/shared/utils/browser/can-share.ts index f141fe50..77de9838 100644 --- a/src/shared/utils/browser/can-share.ts +++ b/src/shared/utils/browser/can-share.ts @@ -1,4 +1,4 @@ -import isBrowser from "./is-browser"; +import { isBrowser } from "@utils/browser"; export default function canShare() { return isBrowser() && !!navigator.canShare; diff --git a/src/shared/utils/browser/index.ts b/src/shared/utils/browser/index.ts new file mode 100644 index 00000000..a7a08a50 --- /dev/null +++ b/src/shared/utils/browser/index.ts @@ -0,0 +1,5 @@ +import canShare from "./can-share"; +import isBrowser from "./is-browser"; +import share from "./share"; + +export { canShare, isBrowser, share }; diff --git a/src/shared/utils/browser/share.ts b/src/shared/utils/browser/share.ts index 9ae94974..98d17712 100644 --- a/src/shared/utils/browser/share.ts +++ b/src/shared/utils/browser/share.ts @@ -1,4 +1,4 @@ -import isBrowser from "./is-browser"; +import { isBrowser } from "@utils/browser"; export default function share(shareData: ShareData) { if (isBrowser()) { diff --git a/src/shared/utils/helpers/get-query-params.ts b/src/shared/utils/helpers/get-query-params.ts index 5488c6ea..627341e4 100644 --- a/src/shared/utils/helpers/get-query-params.ts +++ b/src/shared/utils/helpers/get-query-params.ts @@ -1,4 +1,4 @@ -import isBrowser from "../browser/is-browser"; +import { isBrowser } from "@utils/browser"; export default function getQueryParams< T extends Record diff --git a/src/shared/utils/helpers/index.ts b/src/shared/utils/helpers/index.ts new file mode 100644 index 00000000..663afbf9 --- /dev/null +++ b/src/shared/utils/helpers/index.ts @@ -0,0 +1,8 @@ +import debounce from "./debounce"; +import getQueryParams from "./get-query-params"; +import getQueryString from "./get-query-string"; +import { groupBy } from "./group-by"; +import poll from "./poll"; +import sleep from "./sleep"; + +export { debounce, getQueryParams, getQueryString, groupBy, poll, sleep }; diff --git a/src/shared/utils/roles/am-mod.ts b/src/shared/utils/roles/am-mod.ts index 85483dae..c0632f78 100644 --- a/src/shared/utils/roles/am-mod.ts +++ b/src/shared/utils/roles/am-mod.ts @@ -1,6 +1,6 @@ +import { isMod } from "@utils/roles"; import { CommunityModeratorView } from "lemmy-js-client"; import { UserService } from "../../services"; -import isMod from "./is-mod"; export default function amMod( mods?: CommunityModeratorView[], diff --git a/src/shared/utils/roles/can-admin.ts b/src/shared/utils/roles/can-admin.ts index cac451e9..55bfd1cf 100644 --- a/src/shared/utils/roles/can-admin.ts +++ b/src/shared/utils/roles/can-admin.ts @@ -1,6 +1,6 @@ +import { canMod } from "@utils/roles"; import { PersonView } from "lemmy-js-client"; import { UserService } from "../../services"; -import canMod from "./can-mod"; export default function canAdmin( creatorId: number, diff --git a/src/shared/utils/roles/can-create-community.ts b/src/shared/utils/roles/can-create-community.ts index b0bfeddc..1b5cf05c 100644 --- a/src/shared/utils/roles/can-create-community.ts +++ b/src/shared/utils/roles/can-create-community.ts @@ -1,6 +1,6 @@ +import { amAdmin } from "@utils/roles"; import { GetSiteResponse } from "lemmy-js-client"; import { UserService } from "../../services"; -import amAdmin from "./am-admin"; export default function canCreateCommunity( siteRes: GetSiteResponse, diff --git a/src/shared/utils/roles/index.ts b/src/shared/utils/roles/index.ts new file mode 100644 index 00000000..4762637a --- /dev/null +++ b/src/shared/utils/roles/index.ts @@ -0,0 +1,25 @@ +import amAdmin from "./am-admin"; +import amCommunityCreator from "./am-community-creator"; +import amMod from "./am-mod"; +import amSiteCreator from "./am-site-creator"; +import amTopMod from "./am-top-mod"; +import canAdmin from "./can-admin"; +import canCreateCommunity from "./can-create-community"; +import canMod from "./can-mod"; +import isAdmin from "./is-admin"; +import isBanned from "./is-banned"; +import isMod from "./is-mod"; + +export { + amAdmin, + amCommunityCreator, + amMod, + amSiteCreator, + amTopMod, + canAdmin, + canCreateCommunity, + canMod, + isAdmin, + isBanned, + isMod, +}; diff --git a/src/shared/utils/types/index.ts b/src/shared/utils/types/index.ts new file mode 100644 index 00000000..9b4a1cec --- /dev/null +++ b/src/shared/utils/types/index.ts @@ -0,0 +1,3 @@ +import { QueryParams } from "./query-params"; + +export { QueryParams }; diff --git a/tsconfig.json b/tsconfig.json index 3b7d3e41..600d33aa 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -18,7 +18,13 @@ "noImplicitReturns": true, "experimentalDecorators": true, "strictNullChecks": true, - "noFallthroughCasesInSwitch": true + "noFallthroughCasesInSwitch": true, + "paths": { + "@utils/roles": ["./shared/utils/roles/index"], + "@utils/browser": ["./shared/utils/browser/index"], + "@utils/helpers": ["./shared/utils/helpers/index"], + "@utils/types": ["./shared/utils/types/index"], + } }, "include": [ "src/**/*.ts",