From a79a11faeb4133af927ad67bf41c82fd0cefadb9 Mon Sep 17 00:00:00 2001
From: robertu <4065233+robertu7@users.noreply.github.com>
Date: Thu, 7 Dec 2023 20:31:53 +0800
Subject: [PATCH] feat(admin): use dynamic imports
---
.../ToggleRecommendArticle/Dialog.tsx | 10 ---
.../ArticleDigest/DropdownActions/index.tsx | 70 ++++++++-----------
.../Comment/DropdownActions/index.tsx | 20 +++---
src/views/TagDetail/DropdownActions/index.tsx | 37 +++++-----
.../UserProfile/DropdownActions/index.tsx | 68 ++++++++++--------
5 files changed, 95 insertions(+), 110 deletions(-)
diff --git a/src/components/ArticleDigest/DropdownActions/ToggleRecommendArticle/Dialog.tsx b/src/components/ArticleDigest/DropdownActions/ToggleRecommendArticle/Dialog.tsx
index 717a8bb67b..0a16c5e0d1 100644
--- a/src/components/ArticleDigest/DropdownActions/ToggleRecommendArticle/Dialog.tsx
+++ b/src/components/ArticleDigest/DropdownActions/ToggleRecommendArticle/Dialog.tsx
@@ -134,13 +134,3 @@ const ToggleRecommendArticleDialog = ({
}
export default ToggleRecommendArticleDialog
-
-// const LazyToggleRecommendArticleDialog = (
-// props: ToggleRecommendArticleDialogProps
-// ) => (
-// }>
-// {({ openDialog }) => <>{props.children({ openDialog })}>}
-//
-// )
-
-// export default LazyToggleRecommendArticleDialog
diff --git a/src/components/ArticleDigest/DropdownActions/index.tsx b/src/components/ArticleDigest/DropdownActions/index.tsx
index 6ec9db44e6..838e04071f 100644
--- a/src/components/ArticleDigest/DropdownActions/index.tsx
+++ b/src/components/ArticleDigest/DropdownActions/index.tsx
@@ -49,7 +49,6 @@ import SetTagUnselectedButton from './SetTagUnselectedButton'
import SetTopCollectionButton from './SetTopCollectionButton'
import ShareButton from './ShareButton'
import styles from './styles.module.css'
-import ToggleRecommendArticle from './ToggleRecommendArticle'
import type {
OpenToggleRecommendArticleDialogWithProps,
ToggleRecommendArticleDialogProps,
@@ -57,11 +56,14 @@ import type {
const isAdminView = process.env.NEXT_PUBLIC_ADMIN_VIEW === 'true'
+const DynamicToggleRecommendArticleButton = dynamic(
+ () => import('./ToggleRecommendArticle/Button'),
+ { loading: () => }
+)
+
const DynamicToggleRecommendArticleDialog = dynamic(
() => import('./ToggleRecommendArticle/Dialog'),
- {
- loading: () => ,
- }
+ { loading: () => }
)
export interface DropdownActionsControls {
@@ -269,12 +271,12 @@ const BaseDropdownActions = ({
{isAdminView && viewer.isAdmin && (
<>
-
- {
return null
}
- const DropdownActionsWithShareDialog = withDialog<
- Omit
- >(
+ const WithShareDialog = withDialog>(
BaseDropdownActions,
ShareDialog,
{ path: props.sharePath },
({ openDialog }) => ({ ...props, ...controls, openShareDialog: openDialog })
)
- const DropdownActionsWithFingerprint = withDialog<
- Omit
- >(
- DropdownActionsWithShareDialog,
+ const WithFingerprint = withDialog>(
+ WithShareDialog,
FingerprintDialog,
{ article },
({ openDialog }) => ({ openFingerprintDialog: openDialog })
)
- const DropdownActionsWithAppreciators = withDialog<
+ const WithAppreciators = withDialog<
Omit
- >(
- DropdownActionsWithFingerprint,
- AppreciatorsDialog,
- { article },
- ({ openDialog }) => ({ openAppreciatorsDialog: openDialog })
- )
- const DropdownActionsWithSupporters = withDialog<
- Omit
- >(
- DropdownActionsWithAppreciators,
+ >(WithFingerprint, AppreciatorsDialog, { article }, ({ openDialog }) => ({
+ openAppreciatorsDialog: openDialog,
+ }))
+ const WithSupporters = withDialog>(
+ WithAppreciators,
SupportersDialog,
{ article },
({ openDialog }) => ({ openSupportersDialog: openDialog })
)
- const DropdownActionsWithArchiveArticle = withDialog<
+ const WithArchiveArticle = withDialog<
Omit
- >(
- DropdownActionsWithSupporters,
- ArchiveArticle.Dialog,
- { article },
- ({ openDialog }) => ({
- openArchiveDialog: viewer.isFrozen ? forbid : openDialog,
- })
- )
- const DropdownActionsWithAddCollectionsArticle = withDialog<
+ >(WithSupporters, ArchiveArticle.Dialog, { article }, ({ openDialog }) => ({
+ openArchiveDialog: viewer.isFrozen ? forbid : openDialog,
+ }))
+ const WithAddCollectionsArticle = withDialog<
Omit
>(
- DropdownActionsWithArchiveArticle,
+ WithArchiveArticle,
AddCollectionsArticleDialog,
{ articleId: article.id },
({ openDialog }) => ({ openAddCollectionsArticleDialog: openDialog })
)
- const DropdownActionsWithRemoveArticleCollection = withDialog<
+ const WithRemoveArticleCollection = withDialog<
Omit
>(
- DropdownActionsWithAddCollectionsArticle,
+ WithAddCollectionsArticle,
RemoveArticleCollectionDialog,
{
articleId: article.id,
@@ -457,16 +445,16 @@ const DropdownActions = (props: DropdownActionsProps) => {
// exclude admin code on build
if (!isAdminView || !viewer.isAdmin) {
- return
+ return
}
/**
* ADMIN ONLY
*/
- const DropdownActionsWithToggleRecommend = withDialog<
+ const WithToggleRecommend = withDialog<
Omit
>(
- DropdownActionsWithRemoveArticleCollection,
+ WithRemoveArticleCollection,
DynamicToggleRecommendArticleDialog,
{ article },
({ openDialog }) => ({
@@ -474,7 +462,7 @@ const DropdownActions = (props: DropdownActionsProps) => {
})
)
- return
+ return
}
DropdownActions.fragments = fragments
diff --git a/src/components/Comment/DropdownActions/index.tsx b/src/components/Comment/DropdownActions/index.tsx
index 5f77065af0..453bbd6a17 100644
--- a/src/components/Comment/DropdownActions/index.tsx
+++ b/src/components/Comment/DropdownActions/index.tsx
@@ -231,9 +231,7 @@ const DropdownActions = (props: DropdownActionsProps) => {
return null
}
- const DropdownActionsWithEditComment = withDialog<
- Omit
- >(
+ const WithEditComment = withDialog>(
BaseDropdownActions,
CommentFormDialog,
{
@@ -252,10 +250,10 @@ const DropdownActions = (props: DropdownActionsProps) => {
}
}
)
- const DropdownActionsWithDeleteComment = withDialog<
+ const WithDeleteComment = withDialog<
Omit
>(
- DropdownActionsWithEditComment,
+ WithEditComment,
DeleteComment.Dialog,
{
comment,
@@ -267,10 +265,8 @@ const DropdownActions = (props: DropdownActionsProps) => {
}
}
)
- const DropdownActionsWithBlockUser = withDialog<
- Omit
- >(
- DropdownActionsWithDeleteComment,
+ const WithBlockUser = withDialog>(
+ WithDeleteComment,
BlockUser.Dialog,
{
user: comment.author,
@@ -281,10 +277,10 @@ const DropdownActions = (props: DropdownActionsProps) => {
}
}
)
- const DropdownActionsWithCollapseComment = withDialog<
+ const WithCollapseComment = withDialog<
Omit
>(
- DropdownActionsWithBlockUser,
+ WithBlockUser,
CollapseComment.Dialog,
{
comment,
@@ -297,7 +293,7 @@ const DropdownActions = (props: DropdownActionsProps) => {
}
)
- return
+ return
}
DropdownActions.fragments = fragments
diff --git a/src/views/TagDetail/DropdownActions/index.tsx b/src/views/TagDetail/DropdownActions/index.tsx
index 8db609a4f2..ca4f161ab7 100644
--- a/src/views/TagDetail/DropdownActions/index.tsx
+++ b/src/views/TagDetail/DropdownActions/index.tsx
@@ -214,19 +214,22 @@ const DropdownActions = (props: DropdownActionsProps) => {
return null
}
- const DropdownActionsWithEditTag = withDialog<
- Omit
- >(BaseDropdownActions, EditTagDialog, { ...props.tag }, ({ openDialog }) => {
- return {
- ...props,
- ...controls,
- openEditTagDialog: viewer.isFrozen ? forbid : openDialog,
+ const WithEditTag = withDialog>(
+ BaseDropdownActions,
+ EditTagDialog,
+ { ...props.tag },
+ ({ openDialog }) => {
+ return {
+ ...props,
+ ...controls,
+ openEditTagDialog: viewer.isFrozen ? forbid : openDialog,
+ }
}
- })
- const DropdownActionsWithSearchSelect = withDialog<
+ )
+ const WithSearchSelect = withDialog<
Omit
>(
- DropdownActionsWithEditTag,
+ WithEditTag,
SearchSelectDialog,
{
title: (
@@ -245,20 +248,16 @@ const DropdownActions = (props: DropdownActionsProps) => {
openTagAddSelectedArticlesDialog: viewer.isFrozen ? forbid : openDialog,
})
)
- const DropdownActionsWithTagLeave = withDialog<
- Omit
- >(
- DropdownActionsWithSearchSelect,
+ const WithTagLeave = withDialog>(
+ WithSearchSelect,
TagLeaveDialog,
{ ...props, id: tag.id },
({ openDialog }) => ({
openTagLeaveDialog: viewer.isFrozen ? forbid : openDialog,
})
)
- const DropdownActionsWithTagEditor = withDialog<
- Omit
- >(
- DropdownActionsWithTagLeave,
+ const WithTagEditor = withDialog>(
+ WithTagLeave,
TagEditorDialog,
{ ...props, id: tag.id },
({ openDialog }) => ({
@@ -266,7 +265,7 @@ const DropdownActions = (props: DropdownActionsProps) => {
})
)
- return
+ return
}
export default DropdownActions
diff --git a/src/views/User/UserProfile/DropdownActions/index.tsx b/src/views/User/UserProfile/DropdownActions/index.tsx
index 3714c663b1..cf415aefa5 100644
--- a/src/views/User/UserProfile/DropdownActions/index.tsx
+++ b/src/views/User/UserProfile/DropdownActions/index.tsx
@@ -1,6 +1,7 @@
import gql from 'graphql-tag'
import _isEmpty from 'lodash/isEmpty'
import _pickBy from 'lodash/pickBy'
+import dynamic from 'next/dynamic'
import { useContext } from 'react'
import { FormattedMessage, useIntl } from 'react-intl'
@@ -17,6 +18,7 @@ import {
RssFeedDialogProps,
ShareDialog,
ShareDialogProps,
+ Spinner,
Translate,
ViewerContext,
withDialog,
@@ -29,16 +31,29 @@ import {
DropdownActionsUserPublicFragment,
} from '~/gql/graphql'
-import ArchiveUser from './ArchiveUser'
-import { ArchiveUserDialogProps } from './ArchiveUser/Dialog'
-import ToggleRestrictUser from './ToggleRestrictUser'
-import {
+import type { ArchiveUserDialogProps } from './ArchiveUser/Dialog'
+import type {
OpenToggleRestrictUserDialogWithProps,
ToggleRestrictUserDialogProps,
} from './ToggleRestrictUser/Dialog'
const isAdminView = process.env.NEXT_PUBLIC_ADMIN_VIEW === 'true'
+const DynamicToggleRestrictUserButton = dynamic(
+ () => import('./ToggleRestrictUser/Button'),
+ { loading: () => }
+)
+const DynamicToggleRestrictUserDialog = dynamic(
+ () => import('./ToggleRestrictUser/Dialog'),
+ { loading: () => }
+)
+const DynamicArchiveUserButton = dynamic(() => import('./ArchiveUser/Button'), {
+ loading: () => ,
+})
+const DynamicArchiveUserDialog = dynamic(() => import('./ArchiveUser/Dialog'), {
+ loading: () => ,
+})
+
interface DropdownActionsProps {
user: DropdownActionsUserPublicFragment &
AuthorRssFeedFragment &
@@ -142,11 +157,11 @@ const BaseDropdownActions = ({
{isAdminView && viewer.isAdmin && (
<>
-
-
+
>
)}
@@ -227,9 +242,7 @@ const DropdownActions = ({ user, isMe, isInAside }: DropdownActionsProps) => {
return null
}
- const DropdownActionsWithShare = withDialog<
- Omit
- >(
+ const WithShare = withDialog>(
BaseDropdownActions,
ShareDialog,
{ tags: [user.displayName, user.userName].filter(Boolean) as string[] },
@@ -241,15 +254,16 @@ const DropdownActions = ({ user, isMe, isInAside }: DropdownActionsProps) => {
openShareDialog: openDialog,
})
)
- const DropdownActionsWithRssFeed = withDialog<
- Omit
- >(DropdownActionsWithShare, RssFeedDialog, { user }, ({ openDialog }) => ({
- openRssFeedDialog: openDialog,
- }))
- const DropdownActionsWithBlockUser = withDialog<
- Omit
- >(
- DropdownActionsWithRssFeed,
+ const WithRssFeed = withDialog>(
+ WithShare,
+ RssFeedDialog,
+ { user },
+ ({ openDialog }) => ({
+ openRssFeedDialog: openDialog,
+ })
+ )
+ const WithBlockUser = withDialog>(
+ WithRssFeed,
BlockUser.Dialog,
{ user },
({ openDialog }) => ({ openBlockUserDialog: openDialog })
@@ -257,30 +271,28 @@ const DropdownActions = ({ user, isMe, isInAside }: DropdownActionsProps) => {
// exclude admin code on build
if (!isAdminView || !viewer.isAdmin) {
- return
+ return
}
/**
* ADMIN ONLY
*/
- const DropdownActionsWithToggleRestrict = withDialog<
+ const WithToggleRestrict = withDialog<
Omit
>(
- DropdownActionsWithBlockUser,
- ToggleRestrictUser.Dialog,
+ WithBlockUser,
+ DynamicToggleRestrictUserDialog,
{ id: user.id, userName: user.userName! },
({ openDialog }) => ({ openToggleRestrictDialog: openDialog })
)
- const DropdownActionsWithArchiveUser = withDialog<
- Omit
- >(
- DropdownActionsWithToggleRestrict,
- ArchiveUser.Dialog,
+ const WithArchiveUser = withDialog>(
+ WithToggleRestrict,
+ DynamicArchiveUserDialog,
{ id: user.id, userName: user.userName! },
({ openDialog }) => ({ openArchiveDialog: openDialog })
)
- return
+ return
}
DropdownActions.fragments = fragments