Skip to content

Commit

Permalink
move utils to lib
Browse files Browse the repository at this point in the history
  • Loading branch information
Essential Randomness authored and essential-randomness committed Oct 21, 2023
1 parent 51fa81f commit 8888a3c
Show file tree
Hide file tree
Showing 60 changed files with 116 additions and 111 deletions.
2 changes: 1 addition & 1 deletion src/components/boards/BoardBottomBar.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BoardMetadata, RealmPermissions } from "types/Types";
import { BoardOptions, useBoardOptions } from "../hooks/useBoardOptions";
import { BoardPageDetails, usePageDetails } from "utils/router-utils";
import { BoardPageDetails, usePageDetails } from "lib/router";
import {
EditorActions,
useEditorsDispatch,
Expand Down
2 changes: 1 addition & 1 deletion src/components/core/editors/withEditors.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { addCommentInCache } from "lib/api/cache/comment";
import debug from "debug";
import { useAuth } from "components/Auth";
import { useCachedLinks } from "components/hooks/useCachedLinks";
import { usePageDetails } from "utils/router-utils";
import { usePageDetails } from "lib/router";
import { usePreventPageChange } from "components/hooks/usePreventPageChange";
import { useQueryClient } from "react-query";
import { useRefetchBoardActivity } from "lib/api/hooks/board-feed";
Expand Down
2 changes: 1 addition & 1 deletion src/components/core/feeds/FilterableContext.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ArrayParam } from "use-query-params";
import React from "react";
// import debug from "debug";
import { isNotNull } from "utils/typescript-utils";
import { isNotNull } from "lib/typescript";
import { useQueryParams } from "use-query-params";

//const log = debug("bobafrontend:contexts:RealmContext-log");
Expand Down
26 changes: 16 additions & 10 deletions src/components/core/feeds/ThreadPreview.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { Post, PostHandler, TagType, TagsType, HiddenThread } from "@bobaboard/ui-components";
import {
HiddenThread,
Post,
PostHandler,
TagType,
TagsType,
} from "@bobaboard/ui-components";
import { PostData, ThreadSummaryType } from "types/Types";
import { PostOptions, usePostOptions } from "components/options/usePostOptions";
import {
addThreadHandlerRef,
removeThreadHandlerRef,
} from "utils/scroll-utils";
import { addThreadHandlerRef, removeThreadHandlerRef } from "lib/scroll";

import React from "react";
import { THREAD_VIEW_OPTIONS } from "components/core/editors/utils";
Expand Down Expand Up @@ -105,11 +108,14 @@ const ThreadPreview: React.FC<{

// If the thread is hidden, use a special placeholder to represent it.
if (thread.hidden) {
return <HiddenThread
hidden={thread.hidden}
onThreadHidden={(hide: boolean) =>
setThreadHidden({threadId, boardId, hide})}
/>;
return (
<HiddenThread
hidden={thread.hidden}
onThreadHidden={(hide: boolean) =>
setThreadHidden({ threadId, boardId, hide })
}
/>
);
}

return (
Expand Down
2 changes: 1 addition & 1 deletion src/components/core/layouts/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
DefaultTheme,
Layout as LibraryLayout,
} from "@bobaboard/ui-components";
import { PageTypes, usePageDetails } from "utils/router-utils";
import { PageTypes, usePageDetails } from "lib/router";
import {
useInvalidateNotifications,
useNotifications,
Expand Down
2 changes: 1 addition & 1 deletion src/components/core/layouts/PinnedMenu.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PageTypes, usePageDetails } from "utils/router-utils";
import { PageTypes, usePageDetails } from "lib/router";
import { faInbox, faRss, faThumbtack } from "@fortawesome/free-solid-svg-icons";
import {
useInvalidateNotifications,
Expand Down
4 changes: 2 additions & 2 deletions src/components/core/layouts/SideMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ import React from "react";
import { THREAD_QUERY_KEY } from "lib/api/hooks/thread";
import debug from "debug";
import { dismissRealmNotifications } from "lib/api/queries/user";
import { processBoardsUpdates } from "utils/boards-utils";
import { processBoardsUpdates } from "lib/boards";
import { useAuth } from "components/Auth";
import { useBoardSummaryBySlug } from "lib/api/hooks/board";
import { useCachedLinks } from "components/hooks/useCachedLinks";
import { usePageDetails } from "utils/router-utils";
import { usePageDetails } from "lib/router";
import { useRefetchBoardActivity } from "lib/api/hooks/board-feed";

const log = debug("bobafrontend:SideMenu-log");
Expand Down
3 changes: 1 addition & 2 deletions src/components/core/useIsChangingRoute.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React from "react";

import { usePageDetails } from "lib/router";
import { useRouter } from "next/router";
import { usePageDetails } from "utils/router-utils";

export const useIsChangingRoute = (props?: { onRouteChange?: () => void }) => {
const router = useRouter();
Expand Down
2 changes: 1 addition & 1 deletion src/components/hooks/useBeamToFeedElement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React from "react";
import type { UseInfiniteQueryResult } from "react-query";
import debug from "debug";
import { getNextElementInViewIndex } from "./useBeamToThreadElement";
import { tryScrollToElement } from "utils/scroll-utils";
import { tryScrollToElement } from "lib/scroll";

const log = debug("bobafrontend:useBeamToThreadElement-log");
const info = debug("bobafrontend:useBeamToThreadElement-info");
Expand Down
4 changes: 2 additions & 2 deletions src/components/hooks/useBeamToThreadElement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import {
TIMELINE_VIEW_SUB_MODE,
useThreadViewContext,
} from "contexts/ThreadViewContext";
import { isScrolledPast, tryScrollToElement } from "utils/scroll-utils";
import { isScrolledPast, tryScrollToElement } from "lib/scroll";

import { DisplayManager } from "./useDisplayMananger";
import React from "react";
import debug from "debug";
import { extractRepliesSequence } from "utils/thread-utils";
import { extractRepliesSequence } from "lib/thread";
import { useStateWithCallback } from "components/core/useStateWithCallback";
import { useThreadContext } from "../thread/ThreadContext";

Expand Down
2 changes: 1 addition & 1 deletion src/components/hooks/useCachedLinks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
REALM_ADMIN_PATH,
THREAD_PATH,
createLinkTo,
} from "utils/router-utils";
} from "lib/router";

import { PostData } from "types/Types";
import { ThreadViewQueryParams } from "types/ThreadQueryParams";
Expand Down
6 changes: 3 additions & 3 deletions src/components/hooks/useDisplayMananger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ import {
ThreadViewMode,
useThreadViewContext,
} from "contexts/ThreadViewContext";
import { ThreadPageDetails, usePageDetails } from "utils/router-utils";
import { ThreadPageDetails, usePageDetails } from "lib/router";
import {
UNCATEGORIZED_LABEL,
findFirstLevelParent,
findNextSibling,
findPreviousSibling,
} from "utils/thread-utils";
} from "lib/thread";
import {
useActiveCategories,
useFilterableContext,
Expand All @@ -27,7 +27,7 @@ import {
import { CollapseManager } from "components/thread/useCollapseManager";
import React from "react";
import debug from "debug";
import { getElementId } from "utils/thread-utils";
import { getElementId } from "lib/thread";
import { useStateWithCallback } from "components/core/useStateWithCallback";
import { useThreadContext } from "components/thread/ThreadContext";

Expand Down
7 changes: 4 additions & 3 deletions src/components/hooks/useServerCssVariables.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { useRealmSettings } from "contexts/RealmContext";
import React from "react";
import { PageTypes, usePageDetails } from "lib/router";

import { CssVariableSetting } from "types/Types";
import { PageTypes, usePageDetails } from "utils/router-utils";
import React from "react";
import { useRealmSettings } from "contexts/RealmContext";

export const useServerCssVariables = (ref: React.RefObject<HTMLDivElement>) => {
const {
Expand Down
2 changes: 1 addition & 1 deletion src/components/options/comment/useDebugOptions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { CommentType } from "types/Types";
import React from "react";
import { copyText } from "utils/text-utils";
import { copyText } from "lib/text";
import { faBug } from "@fortawesome/free-solid-svg-icons";
import { faCopy } from "@fortawesome/free-regular-svg-icons";
import { toast } from "@bobaboard/ui-components";
Expand Down
2 changes: 1 addition & 1 deletion src/components/options/post/useDebugOptions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { PostType } from "types/Types";
import React from "react";
import { copyText } from "utils/text-utils";
import { copyText } from "lib/text";
import { faBug } from "@fortawesome/free-solid-svg-icons";
import { faCopy } from "@fortawesome/free-regular-svg-icons";
import { toast } from "@bobaboard/ui-components";
Expand Down
2 changes: 1 addition & 1 deletion src/components/options/post/useEditTagsOption.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { EditorActions } from "components/core/editors/types";
import { PostType } from "types/Types";
import React from "react";
import { faEdit } from "@fortawesome/free-solid-svg-icons";
import { isPostEditPermission } from "utils/permissions-utils";
import { isPostEditPermission } from "lib/permissions";
import { useAuth } from "components/Auth";
import { useBoardMetadata } from "lib/api/hooks/board";
import { useEditorsDispatch } from "components/core/editors/EditorsContext";
Expand Down
6 changes: 3 additions & 3 deletions src/components/options/useCommentOptions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CommentType, RealmPermissions } from "types/Types";
import { ThreadPageDetails, usePageDetails } from "utils/router-utils";
import { ThreadPageDetails, usePageDetails } from "lib/router";
import { faArrowRight, faLink } from "@fortawesome/free-solid-svg-icons";
import {
useCurrentRealmBoardId,
Expand All @@ -8,10 +8,10 @@ import {

import { DropdownProps } from "@bobaboard/ui-components/dist/common/DropdownListMenu";
import React from "react";
import { copyText } from "utils/text-utils";
import { copyText } from "lib/text";
import { faComment } from "@fortawesome/free-regular-svg-icons";
import { getCommentsChain } from "components/thread/CommentsThread";
import { isNotNull } from "utils/typescript-utils";
import { isNotNull } from "lib/typescript";
import { toast } from "@bobaboard/ui-components";
import { useBoardMetadata } from "lib/api/hooks/board";
import { useCachedLinks } from "components/hooks/useCachedLinks";
Expand Down
9 changes: 3 additions & 6 deletions src/components/options/useLoggedInOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,16 @@ import {
import { useRealmContext, useRealmPermissions } from "contexts/RealmContext";

import React from "react";
import { hasAdminPanelAccess } from "utils/permissions-utils";
import { hasAdminPanelAccess } from "lib/permissions";
import { useCachedLinks } from "../hooks/useCachedLinks";
import { useForceHideIdentity } from "../hooks/useForceHideIdentity";

// TODO: make the login component have its own context, then use that function
// here instead of passing it as an argument
export const useLoggedInOptions = (openLogin: () => void) => {
const { forceHideIdentity, toggleForceHideIdentity } = useForceHideIdentity();
const {
linkToPersonalSettings,
linkToLogs,
linkToRealmAdmin,
} = useCachedLinks();
const { linkToPersonalSettings, linkToLogs, linkToRealmAdmin } =
useCachedLinks();
const userRealmPermissions = useRealmPermissions();
const realmData = useRealmContext();

Expand Down
2 changes: 1 addition & 1 deletion src/components/options/usePostOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
import { DropdownProps } from "@bobaboard/ui-components/dist/common/DropdownListMenu";
import { LinkWithAction } from "@bobaboard/ui-components/dist/types";
import React from "react";
import { copyText } from "utils/text-utils";
import { copyText } from "lib/text";
import { toast } from "@bobaboard/ui-components";
import { useBoardMetadata } from "lib/api/hooks/board";
import { useCachedLinks } from "../hooks/useCachedLinks";
Expand Down
2 changes: 1 addition & 1 deletion src/components/options/useTagsOptions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { GetPropsFromForwardedRef, isNotNull } from "utils/typescript-utils";
import { GetPropsFromForwardedRef, isNotNull } from "lib/typescript";
import type { Post, TagsType } from "@bobaboard/ui-components";

import React from "react";
Expand Down
2 changes: 1 addition & 1 deletion src/components/realm/InvitesPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { AdminPanelIds } from "pages/realms/admin/[[...panelId]]";
import CreateInvitePanel from "./CreateInvitePanel";
import InvitesTable from "./InvitesTable";
import React from "react";
import { copyText } from "utils/text-utils";
import { copyText } from "lib/text";
import debug from "debug";
import { toast } from "@bobaboard/ui-components";
import { useHotkeys } from "react-hotkeys-hook";
Expand Down
2 changes: 1 addition & 1 deletion src/components/settings/UserSettings.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BobaDex, UserDetails } from "@bobaboard/ui-components";
import React, { useEffect } from "react";
import { extractImageExtension, uploadImage } from "utils/image-upload";
import { extractImageExtension, uploadImage } from "lib/image-upload";
import { getBobadex, updateUserData } from "lib/api/queries/user";
import { useMutation, useQuery } from "react-query";

Expand Down
4 changes: 2 additions & 2 deletions src/components/thread/CommentsThread.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ import {
RealmPermissions,
ThreadCommentInfoType,
} from "types/Types";
import { ThreadPageDetails, usePageDetails } from "utils/router-utils";
import { ThreadPageDetails, usePageDetails } from "lib/router";
import {
addCommentHandlerRef,
removeCommentHandlerRef,
scrollToComment,
} from "utils/scroll-utils";
} from "lib/scroll";
import {
useBoardSummary,
useCurrentRealmBoardId,
Expand Down
4 changes: 2 additions & 2 deletions src/components/thread/GalleryThreadView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
NewThread,
SegmentedButton,
} from "@bobaboard/ui-components";
import { ThreadPageDetails, usePageDetails } from "utils/router-utils";
import { ThreadPageDetails, usePageDetails } from "lib/router";
import {
extractPostId,
getCommentThreadId,
Expand All @@ -20,7 +20,7 @@ import EmptyView from "./EmptyView";
import { PostType } from "types/Types";
import React from "react";
import ThreadPost from "./ThreadPost";
import { scrollToPost } from "utils/scroll-utils";
import { scrollToPost } from "lib/scroll";
import { useBoardSummaryBySlug } from "lib/api/hooks/board";
import { useStemOptions } from "components/hooks/useStemOptions";
import { useThreadContext } from "components/thread/ThreadContext";
Expand Down
2 changes: 1 addition & 1 deletion src/components/thread/ThreadBottomBar.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { PostOptions, usePostOptions } from "components/options/usePostOptions";
import { ThreadPageDetails, usePageDetails } from "utils/router-utils";
import { ThreadPageDetails, usePageDetails } from "lib/router";
import {
faAnglesDown,
faAnglesUp,
Expand Down
2 changes: 1 addition & 1 deletion src/components/thread/ThreadContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
getCommentFromId,
makeCommentsTree,
makePostsTree,
} from "utils/thread-utils";
} from "lib/thread";

import React from "react";
import { compareAsc as compareDatesAsc } from "date-fns";
Expand Down
13 changes: 5 additions & 8 deletions src/components/thread/ThreadPost.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@ import {
TagsOptions,
useGetTagOptions,
} from "components/options/useTagsOptions";
import { ThreadPageDetails, usePageDetails } from "utils/router-utils";
import {
getTotalContributions,
getTotalNewContributions,
} from "utils/thread-utils";
import { ThreadPageDetails, usePageDetails } from "lib/router";
import { getTotalContributions, getTotalNewContributions } from "lib/thread";
import {
isCommentEditorState,
isReplyContribution,
Expand All @@ -20,12 +17,12 @@ import {
useRealmPermissions,
} from "contexts/RealmContext";

import { GetPropsFromForwardedRef } from "utils/typescript-utils";
import { GetPropsFromForwardedRef } from "lib/typescript";
import React from "react";
import { addPostHandlerRef } from "utils/scroll-utils";
import { addPostHandlerRef } from "lib/scroll";
import classNames from "classnames";
import { formatDistanceToNow } from "date-fns";
import { getCurrentSearchParams } from "utils/location-utils";
import { getCurrentSearchParams } from "lib/location";
import { useAuth } from "components/Auth";
import { useCachedLinks } from "components/hooks/useCachedLinks";
import { useEditorsState } from "components/core/editors/EditorsContext";
Expand Down
Loading

0 comments on commit 8888a3c

Please sign in to comment.