Skip to content

Commit

Permalink
Merge pull request #1332 from alectrocute/breakout-role-utils
Browse files Browse the repository at this point in the history
Organize `utils.ts` into folder, update imports
  • Loading branch information
SleeplessOne1917 authored Jun 20, 2023
2 parents 91908d2 + 4da34c1 commit 94bc909
Show file tree
Hide file tree
Showing 52 changed files with 376 additions and 303 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@
"sortpack": "^2.3.4",
"style-loader": "^3.3.2",
"terser": "^5.17.3",
"tsconfig-paths-webpack-plugin": "^4.0.1",
"typescript": "^5.0.4",
"webpack-dev-server": "4.15.0"
},
Expand Down
6 changes: 3 additions & 3 deletions src/client/index.tsx
Original file line number Diff line number Diff line change
@@ -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 = (
<Router history={HistoryService.history}>
Expand All @@ -17,6 +16,7 @@ const wrapper = (
);

const root = document.getElementById("root");

if (root) {
hydrate(wrapper, root);
}
7 changes: 3 additions & 4 deletions src/shared/components/app/navbar.tsx
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -10,13 +13,9 @@ import { i18n } from "../../i18next";
import { UserService } from "../../services";
import { HttpService, RequestState } from "../../services/HttpService";
import {
amAdmin,
canCreateCommunity,
donateLemmyUrl,
isBrowser,
myAuth,
numToSI,
poll,
showAvatars,
toast,
updateUnreadCountsInterval,
Expand Down
14 changes: 8 additions & 6 deletions src/shared/components/comment/comment-node.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -40,16 +48,10 @@ import {
} from "../../interfaces";
import { UserService } from "../../services";
import {
amCommunityCreator,
canAdmin,
canMod,
colorList,
commentTreeMaxDepth,
futureDaysToUnixTime,
getCommentParentId,
isAdmin,
isBanned,
isMod,
mdToHtml,
mdToHtmlNoImages,
myAuth,
Expand Down
2 changes: 1 addition & 1 deletion src/shared/components/common/markdown-textarea.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { isBrowser } from "@utils/browser";
import autosize from "autosize";
import classNames from "classnames";
import { NoOptionI18nKeys } from "i18next";
Expand All @@ -8,7 +9,6 @@ import { HttpService, UserService } from "../../services";
import {
concurrentImageUpload,
customEmojisLookup,
isBrowser,
markdownFieldCharacterLimit,
markdownHelpUrl,
maxUploadImages,
Expand Down
5 changes: 2 additions & 3 deletions src/shared/components/community/communities.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { getQueryParams, getQueryString } from "@utils/helpers";
import type { QueryParams } from "@utils/types";
import { Component, linkEvent } from "inferno";
import {
CommunityResponse,
Expand All @@ -11,12 +13,9 @@ import { InitialFetchRequest } from "../../interfaces";
import { FirstLoadService } from "../../services/FirstLoadService";
import { HttpService, RequestState } from "../../services/HttpService";
import {
QueryParams,
RouteDataResponse,
editCommunity,
getPageFromString,
getQueryParams,
getQueryString,
myAuth,
myAuthRequired,
numToSI,
Expand Down
5 changes: 2 additions & 3 deletions src/shared/components/community/community.tsx
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -62,7 +64,6 @@ import { UserService } from "../../services";
import { FirstLoadService } from "../../services/FirstLoadService";
import { HttpService, RequestState } from "../../services/HttpService";
import {
QueryParams,
RouteDataResponse,
commentsToFlatNodes,
communityRSSUrl,
Expand All @@ -75,8 +76,6 @@ import {
getCommentParentId,
getDataTypeString,
getPageFromString,
getQueryParams,
getQueryString,
myAuth,
postToCommentSortType,
relTags,
Expand Down
11 changes: 2 additions & 9 deletions src/shared/components/community/sidebar.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -16,15 +17,7 @@ import {
} from "lemmy-js-client";
import { i18n } from "../../i18next";
import { UserService } from "../../services";
import {
amAdmin,
amMod,
amTopMod,
getUnixTime,
hostname,
mdToHtml,
myAuthRequired,
} from "../../utils";
import { getUnixTime, hostname, mdToHtml, myAuthRequired } from "../../utils";
import { Badges } from "../common/badges";
import { BannerIconHeader } from "../common/banner-icon-header";
import { Icon, PurgeWarning, Spinner } from "../common/icon";
Expand Down
11 changes: 5 additions & 6 deletions src/shared/components/home/home.tsx
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -57,7 +60,7 @@ import { UserService } from "../../services";
import { FirstLoadService } from "../../services/FirstLoadService";
import { HttpService, RequestState } from "../../services/HttpService";
import {
canCreateCommunity,
RouteDataResponse,
commentsToFlatNodes,
editComment,
editPost,
Expand All @@ -68,16 +71,12 @@ import {
getCommentParentId,
getDataTypeString,
getPageFromString,
getQueryParams,
getQueryString,
getRandomFromList,
mdToHtml,
myAuth,
postToCommentSortType,
QueryParams,
relTags,
restoreScrollPosition,
RouteDataResponse,
saveScrollPosition,
setIsoData,
setupTippy,
Expand Down
3 changes: 2 additions & 1 deletion src/shared/components/home/login.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +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 { isBrowser, myAuth, setIsoData, toast, validEmail } from "../../utils";
import { myAuth, setIsoData, toast, validEmail } from "../../utils";
import { HtmlTags } from "../common/html-tags";
import { Spinner } from "../common/icon";

Expand Down
2 changes: 1 addition & 1 deletion src/shared/components/home/signup.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -13,7 +14,6 @@ import { i18n } from "../../i18next";
import { UserService } from "../../services";
import { HttpService, RequestState } from "../../services/HttpService";
import {
isBrowser,
joinLemmyUrl,
mdToHtml,
myAuth,
Expand Down
9 changes: 3 additions & 6 deletions src/shared/components/modlog.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -34,17 +37,11 @@ import { FirstLoadService } from "../services/FirstLoadService";
import { HttpService, RequestState } from "../services/HttpService";
import {
Choice,
QueryParams,
RouteDataResponse,
amAdmin,
amMod,
debounce,
fetchLimit,
fetchUsers,
getIdFromString,
getPageFromString,
getQueryParams,
getQueryString,
getUpdatedSearchId,
myAuth,
personToChoice,
Expand Down
9 changes: 3 additions & 6 deletions src/shared/components/person/profile.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -53,9 +56,7 @@ import { UserService } from "../../services";
import { FirstLoadService } from "../../services/FirstLoadService";
import { HttpService, RequestState } from "../../services/HttpService";
import {
QueryParams,
RouteDataResponse,
canMod,
capitalizeFirstLetter,
editComment,
editPost,
Expand All @@ -66,10 +67,6 @@ import {
futureDaysToUnixTime,
getCommentParentId,
getPageFromString,
getQueryParams,
getQueryString,
isAdmin,
isBanned,
mdToHtml,
myAuth,
myAuthRequired,
Expand Down
2 changes: 1 addition & 1 deletion src/shared/components/person/reports.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { amAdmin } from "@utils/roles";
import { Component, linkEvent } from "inferno";
import {
CommentReportResponse,
Expand All @@ -24,7 +25,6 @@ import { FirstLoadService } from "../../services/FirstLoadService";
import { RequestState } from "../../services/HttpService";
import {
RouteDataResponse,
amAdmin,
editCommentReport,
editPostReport,
editPrivateMessageReport,
Expand Down
2 changes: 1 addition & 1 deletion src/shared/components/person/settings.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { debounce } from "@utils/helpers";
import { NoOptionI18nKeys } from "i18next";
import { Component, linkEvent } from "inferno";
import {
Expand All @@ -18,7 +19,6 @@ import {
Choice,
capitalizeFirstLetter,
communityToChoice,
debounce,
elementUrl,
emDash,
fetchCommunities,
Expand Down
4 changes: 2 additions & 2 deletions src/shared/components/post/create-post.tsx
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -17,12 +19,10 @@ import {
} from "../../services/HttpService";
import {
Choice,
QueryParams,
RouteDataResponse,
enableDownvotes,
enableNsfw,
getIdFromString,
getQueryParams,
myAuth,
setIsoData,
} from "../../utils";
Expand Down
2 changes: 1 addition & 1 deletion src/shared/components/post/post-form.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { debounce } from "@utils/helpers";
import autosize from "autosize";
import { Component, InfernoNode, linkEvent } from "inferno";
import {
Expand All @@ -18,7 +19,6 @@ import {
archiveTodayUrl,
capitalizeFirstLetter,
communityToChoice,
debounce,
fetchCommunities,
getIdFromString,
ghostArchiveUrl,
Expand Down
21 changes: 11 additions & 10 deletions src/shared/components/post/post-listing.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -28,18 +39,9 @@ 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,
Expand All @@ -49,7 +51,6 @@ import {
numToSI,
relTags,
setupTippy,
share,
showScores,
} from "../../utils";
import { Icon, PurgeWarning, Spinner } from "../common/icon";
Expand Down
4 changes: 2 additions & 2 deletions src/shared/components/post/post.tsx
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -64,7 +66,6 @@ import {
buildCommentsTree,
commentsToFlatNodes,
commentTreeMaxDepth,
debounce,
editComment,
editWith,
enableDownvotes,
Expand All @@ -73,7 +74,6 @@ import {
getCommentParentId,
getDepthFromComment,
getIdFromProps,
isBrowser,
isImage,
myAuth,
restoreScrollPosition,
Expand Down
Loading

0 comments on commit 94bc909

Please sign in to comment.