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";
import {
concurrentImageUpload,
customEmojisLookup,
- isBrowser,
markdownFieldCharacterLimit,
markdownHelpUrl,
maxUploadImages,
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;
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";
import { FirstLoadService } from "../../services/FirstLoadService";
import { HttpService, RequestState } from "../../services/HttpService";
import {
- QueryParams,
commentsToFlatNodes,
communityRSSUrl,
editComment,
getCommentParentId,
getDataTypeString,
getPageFromString,
- getQueryParams,
- getQueryString,
myAuth,
postToCommentSortType,
relTags,
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";
import { SiteSidebar } from "../home/site-sidebar";
import { PostListings } from "../post/post-listings";
import { CommunityLink } from "./community-link";
-
interface State {
communityRes: RequestState<GetCommunityResponse>;
postsRes: RequestState<GetPostsResponse>;
getCommentParentId,
getDataTypeString,
getPageFromString,
- getQueryParams,
- getQueryString,
getRandomFromList,
mdToHtml,
myAuth,
postToCommentSortType,
- QueryParams,
relTags,
restoreScrollPosition,
saveScrollPosition,
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";
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";
import { UserService } from "../../services";
import { HttpService, RequestState } from "../../services/HttpService";
import {
- isBrowser,
joinLemmyUrl,
mdToHtml,
myAuth,
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";
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";
import { FirstLoadService } from "../../services/FirstLoadService";
import { HttpService, RequestState } from "../../services/HttpService";
import {
- QueryParams,
capitalizeFirstLetter,
editComment,
editPost,
futureDaysToUnixTime,
getCommentParentId,
getPageFromString,
- getQueryParams,
- getQueryString,
mdToHtml,
myAuth,
myAuthRequired,
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";
} 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";
import { BanType, PostFormParams, PurgeType, VoteType } from "../../interfaces";
import { UserService } from "../../services";
import {
- canShare,
futureDaysToUnixTime,
hostname,
isImage,
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";
getCommentParentId,
getDepthFromComment,
getIdFromProps,
- isBrowser,
isImage,
myAuth,
restoreScrollPosition,
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";
import { HttpService, RequestState } from "../services/HttpService";
import {
Choice,
- QueryParams,
capitalizeFirstLetter,
commentsToFlatNodes,
communityToChoice,
fetchUsers,
getIdFromString,
getPageFromString,
- getQueryParams,
- getQueryString,
getUpdatedSearchId,
myAuth,
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 { CommentNodes } from "./comment/comment-nodes";
import { HtmlTags } from "./common/html-tags";
import { Spinner } from "./common/icon";
-import { isBrowser } from "./utils";
+import { isBrowser } from "./utils/browser/is-browser";
const testHost = "0.0.0.0:8536";
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;
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()) {
`;
}
-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()) {
src: string;
}
-const groupBy = <T>(
- 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<T extends Record<string, any>> = {
- [key in keyof T]?: string;
-};
-
-export function getQueryParams<T extends Record<string, any>>(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<T extends Record<string, string | undefined>>(
- 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;
return myVote == -1 ? 0 : -1;
}
}
-
-function sleep(millis: number): Promise<void> {
- 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);
-}
--- /dev/null
+import { isBrowser } from "./is-browser";
+
+export function canShare() {
+ return isBrowser() && !!navigator.canShare;
+}
--- /dev/null
+export function isBrowser() {
+ return typeof window !== "undefined";
+}
--- /dev/null
+import { isBrowser } from "./is-browser";
+
+export function share(shareData: ShareData) {
+ if (isBrowser()) {
+ navigator.share(shareData);
+ }
+}
--- /dev/null
+import { isBrowser } from "../browser/is-browser";
+
+export function getQueryParams<T extends Record<string, any>>(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;
+}
--- /dev/null
+export function getQueryString<T extends Record<string, string | undefined>>(
+ obj: T
+) {
+ return Object.entries(obj)
+ .filter(([, val]) => val !== undefined && val !== null)
+ .reduce(
+ (acc, [key, val], index) => `${acc}${index > 0 ? "&" : ""}${key}=${val}`,
+ "?"
+ );
+}
--- /dev/null
+export const groupBy = <T>(
+ 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[] });
--- /dev/null
+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);
+}
--- /dev/null
+export function sleep(millis: number): Promise<void> {
+ return new Promise(resolve => setTimeout(resolve, millis));
+}
--- /dev/null
+export type QueryParams<T extends Record<string, any>> = {
+ [key in keyof T]?: string;
+};