refactor: unify loading component (#1184)
This commit is contained in:
@@ -6,6 +6,7 @@ import { useEffect } from "react"
|
||||
import { Virtuoso } from "react-virtuoso"
|
||||
|
||||
import { CommentItem } from "~/components/common/CommentItem"
|
||||
import { Loading } from "~/components/common/Loading"
|
||||
import { DashboardMain } from "~/components/dashboard/DashboardMain"
|
||||
import { UniLink } from "~/components/ui/UniLink"
|
||||
import { getSiteLink } from "~/lib/helpers"
|
||||
@@ -65,7 +66,7 @@ export default function CommentsPage() {
|
||||
comments.hasNextPage && comments.fetchNextPage()
|
||||
}
|
||||
components={{
|
||||
Footer: comments.isLoading ? Loader : undefined,
|
||||
Footer: comments.isLoading ? Loading : undefined,
|
||||
}}
|
||||
itemContent={(_, p) =>
|
||||
p?.list?.map((comment, idx) => {
|
||||
@@ -125,15 +126,3 @@ export default function CommentsPage() {
|
||||
</DashboardMain>
|
||||
)
|
||||
}
|
||||
|
||||
const Loader = () => {
|
||||
const t = useTranslations()
|
||||
return (
|
||||
<div
|
||||
className="relative mt-4 w-full text-sm text-center py-4"
|
||||
key={"loading"}
|
||||
>
|
||||
{t("Loading")}...
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import toast from "react-hot-toast"
|
||||
|
||||
import { useQueryClient } from "@tanstack/react-query"
|
||||
|
||||
import { Loading } from "~/components/common/Loading"
|
||||
import { DashboardMain } from "~/components/dashboard/DashboardMain"
|
||||
import EditorAutofill from "~/components/dashboard/editor-properties/EditorAutofill"
|
||||
import EditorCover from "~/components/dashboard/editor-properties/EditorCover"
|
||||
@@ -247,9 +248,7 @@ export default function PortfolioEditor() {
|
||||
<>
|
||||
<DashboardMain className="max-w-screen-lg" title="Edit portfolio">
|
||||
{page.isLoading ? (
|
||||
<div className="flex justify-center items-center min-h-[300px]">
|
||||
{t("Loading")}...
|
||||
</div>
|
||||
<Loading className="min-h-[300px]" />
|
||||
) : (
|
||||
<>
|
||||
<EditorExtraProperties updateValue={updateValue} />
|
||||
|
||||
@@ -9,6 +9,7 @@ import toast from "react-hot-toast"
|
||||
import type { EditorView } from "@codemirror/view"
|
||||
import { useQueryClient } from "@tanstack/react-query"
|
||||
|
||||
import { Loading } from "~/components/common/Loading"
|
||||
import { DashboardMain } from "~/components/dashboard/DashboardMain"
|
||||
import DualColumnEditor from "~/components/dashboard/DualColumnEditor"
|
||||
import EditorCover from "~/components/dashboard/editor-properties/EditorCover"
|
||||
@@ -385,9 +386,7 @@ export default function PostEditor() {
|
||||
<>
|
||||
<DashboardMain fullWidth>
|
||||
{page.isLoading ? (
|
||||
<div className="flex justify-center items-center min-h-[300px]">
|
||||
{t("Loading")}...
|
||||
</div>
|
||||
<Loading className="min-h-[300px]" />
|
||||
) : (
|
||||
<>
|
||||
<header
|
||||
|
||||
@@ -8,6 +8,7 @@ import toast from "react-hot-toast"
|
||||
|
||||
import { useQueryClient } from "@tanstack/react-query"
|
||||
|
||||
import { Loading } from "~/components/common/Loading"
|
||||
import { DashboardMain } from "~/components/dashboard/DashboardMain"
|
||||
import EditorContent from "~/components/dashboard/editor-properties/EditorContent"
|
||||
import EditorImages from "~/components/dashboard/editor-properties/EditorImages"
|
||||
@@ -249,9 +250,7 @@ export default function ShortEditor() {
|
||||
<>
|
||||
<DashboardMain className="max-w-screen-lg" title="Edit short">
|
||||
{page.isLoading ? (
|
||||
<div className="flex justify-center items-center min-h-[300px]">
|
||||
{t("Loading")}...
|
||||
</div>
|
||||
<Loading className="min-h-[300px]" />
|
||||
) : (
|
||||
<>
|
||||
<EditorExtraProperties updateValue={updateValue} />
|
||||
|
||||
@@ -16,6 +16,7 @@ import {
|
||||
} from "@crossbell/notification"
|
||||
|
||||
import { ConnectButton } from "~/components/common/ConnectButton"
|
||||
import { Loading } from "~/components/common/Loading"
|
||||
import { Logo } from "~/components/common/Logo"
|
||||
import { DashboardTopbar } from "~/components/dashboard/DashboardTopbar"
|
||||
import { Avatar } from "~/components/ui/Avatar"
|
||||
@@ -444,8 +445,6 @@ export default function DashboardLayout({
|
||||
</div>
|
||||
)
|
||||
) : (
|
||||
<div className="w-screen h-screen flex justify-center items-center">
|
||||
Loading...
|
||||
</div>
|
||||
<Loading className="w-screen h-screen" />
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import { Loading } from "~/components/common/Loading"
|
||||
|
||||
import PageComponent from "./page-component"
|
||||
|
||||
export default function Dashboard() {
|
||||
return (
|
||||
<>
|
||||
<PageComponent />
|
||||
<div className="flex items-center justify-center w-full h-60">
|
||||
Loading...
|
||||
</div>
|
||||
<Loading className="h-60" />
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import { ExpandedCharacter } from "~/lib/types"
|
||||
|
||||
import { Button } from "../ui/Button"
|
||||
import CharacterListItem from "./CharacterListItem"
|
||||
import { Loading } from "./Loading"
|
||||
import { PortalProvider } from "./Portal"
|
||||
|
||||
export const CharacterList = ({
|
||||
@@ -57,7 +58,7 @@ export const CharacterList = ({
|
||||
className="max-h-screen"
|
||||
endReached={() => hasMore && loadMore()}
|
||||
components={{
|
||||
Footer: hasMore ? Loader : undefined,
|
||||
Footer: hasMore ? Loading : undefined,
|
||||
}}
|
||||
data={flattenList}
|
||||
itemContent={(index, sub) => {
|
||||
@@ -89,12 +90,3 @@ export const CharacterList = ({
|
||||
</Modal>
|
||||
)
|
||||
}
|
||||
|
||||
const Loader = () => {
|
||||
const t = useTranslations()
|
||||
return (
|
||||
<div className="text-sm py-3 text-center" key={0}>
|
||||
{t("Loading")} ...
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -11,6 +11,8 @@ import { ExpandedNote } from "~/lib/types"
|
||||
import { cn } from "~/lib/utils"
|
||||
import { useGetComments } from "~/queries/page"
|
||||
|
||||
import { Loading } from "./Loading"
|
||||
|
||||
const Comment = ({
|
||||
page,
|
||||
className,
|
||||
@@ -64,7 +66,7 @@ const Comment = ({
|
||||
data={data}
|
||||
endReached={() => comments.hasNextPage && comments.fetchNextPage()}
|
||||
components={{
|
||||
Footer: comments.isLoading ? Loader : undefined,
|
||||
Footer: comments.isLoading ? Loading : undefined,
|
||||
}}
|
||||
totalListHeightChanged={(height) => {
|
||||
if (fixHeight && height > 0) {
|
||||
@@ -89,23 +91,7 @@ const Comment = ({
|
||||
))
|
||||
}
|
||||
></Virtuoso>
|
||||
{comments.isLoading && (
|
||||
<div className="relative mt-4 w-full text-sm text-center py-4">
|
||||
{t("Loading")}...
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
const Loader = () => {
|
||||
const t = useTranslations()
|
||||
return (
|
||||
<div
|
||||
className="relative mt-4 w-full text-sm text-center py-4"
|
||||
key={"loading"}
|
||||
>
|
||||
{t("Loading")}...
|
||||
{comments.isLoading && <Loading />}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
import { useTranslations } from "next-intl"
|
||||
|
||||
import { cn } from "~/lib/utils"
|
||||
|
||||
export const Loading = ({
|
||||
className,
|
||||
}: {
|
||||
className?: string
|
||||
context?: unknown
|
||||
}) => {
|
||||
const t = useTranslations()
|
||||
return (
|
||||
<div
|
||||
className={cn(
|
||||
"flex gap-2 justify-center items-center w-full my-6",
|
||||
className,
|
||||
)}
|
||||
>
|
||||
<div className="i-mingcute-loading-3-fill animate-spin text-xl"></div>
|
||||
{t("Loading")}...
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -17,6 +17,7 @@ import { ModalContentProps, useModalStack } from "../ui/ModalStack"
|
||||
import { Tabs } from "../ui/Tabs"
|
||||
import { UniLink } from "../ui/UniLink"
|
||||
import { CharacterFloatCard } from "./CharacterFloatCard"
|
||||
import { Loading } from "./Loading"
|
||||
|
||||
export const usePatronModal = () => {
|
||||
const { present } = useModalStack()
|
||||
@@ -179,7 +180,7 @@ const PatronModal = ({
|
||||
</div>
|
||||
<div className="text-zinc-500 text-sm mt-2">
|
||||
{tips.isLoading ? (
|
||||
"Loading..."
|
||||
<Loading />
|
||||
) : tips.data?.pages?.[0]?.list?.length ? (
|
||||
<>
|
||||
<ul className="flex items-center justify-center">
|
||||
|
||||
@@ -13,15 +13,13 @@ import { useUploadFile } from "~/hooks/useUploadFile"
|
||||
import { cn } from "~/lib/utils"
|
||||
import { Rendered, renderPageContent } from "~/markdown"
|
||||
|
||||
import { Loading } from "../common/Loading"
|
||||
|
||||
const DynamicCodeMirrorEditor = dynamic(
|
||||
() => import("~/components/ui/CodeMirror"),
|
||||
{
|
||||
ssr: false,
|
||||
loading: () => (
|
||||
<div className="flex-1 h-12 flex items-center justify-center">
|
||||
Loading...
|
||||
</div>
|
||||
),
|
||||
loading: () => <Loading className="flex-1 h-12" />,
|
||||
},
|
||||
)
|
||||
|
||||
@@ -29,11 +27,7 @@ const DynamicPageContent = dynamic(
|
||||
() => import("~/components/common/PageContent"),
|
||||
{
|
||||
ssr: false,
|
||||
loading: () => (
|
||||
<div className="flex-1 h-12 flex items-center justify-center">
|
||||
Loading...
|
||||
</div>
|
||||
),
|
||||
loading: () => <Loading className="flex-1 h-12" />,
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ import { cn } from "~/lib/utils"
|
||||
import { useGetPagesBySite, usePinnedPage } from "~/queries/page"
|
||||
import { useGetSite } from "~/queries/site"
|
||||
|
||||
import { Loading } from "../common/Loading"
|
||||
import { PlatformsSyncMap } from "../site/Platform"
|
||||
import { Button } from "../ui/Button"
|
||||
import { EmptyState } from "../ui/EmptyState"
|
||||
@@ -317,7 +318,7 @@ export const PagesManager = ({ type }: { type: NoteType }) => {
|
||||
)}
|
||||
|
||||
<div className="-mt-3">
|
||||
{pages.isLoading && <p className="py-4 px-3">{t("Loading")}...</p>}
|
||||
{pages.isLoading && <Loading />}
|
||||
{!pages.isLoading && !pages.data?.pages?.[0].count && (
|
||||
<EmptyState resource={type} />
|
||||
)}
|
||||
|
||||
@@ -8,6 +8,7 @@ import { VirtuosoGrid } from "react-virtuoso"
|
||||
import { useAccountState, useConnectModal } from "@crossbell/connect-kit"
|
||||
import { Switch } from "@headlessui/react"
|
||||
|
||||
import { Loading } from "~/components/common/Loading"
|
||||
import PostCard from "~/components/common/PostCard"
|
||||
import { EmptyState } from "~/components/ui/EmptyState"
|
||||
import { Skeleton } from "~/components/ui/Skeleton"
|
||||
@@ -245,7 +246,7 @@ export const HomeFeed = ({ type }: { type?: FeedType }) => {
|
||||
}}
|
||||
></VirtuosoGrid>
|
||||
|
||||
{feed.isFetching && feed.hasNextPage && isMounted && <Loader />}
|
||||
{feed.isFetching && feed.hasNextPage && isMounted && <Loading />}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
@@ -253,18 +254,6 @@ export const HomeFeed = ({ type }: { type?: FeedType }) => {
|
||||
)
|
||||
}
|
||||
|
||||
const Loader = () => {
|
||||
const t = useTranslations()
|
||||
return (
|
||||
<div
|
||||
className="relative w-full text-sm text-center py-4 mt-12"
|
||||
key={"loading"}
|
||||
>
|
||||
{t("Loading")} ...
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
const FeedSkeleton = () => {
|
||||
return (
|
||||
<Skeleton.Container
|
||||
|
||||
@@ -12,6 +12,8 @@ import { getSiteLink } from "~/lib/helpers"
|
||||
import { cn } from "~/lib/utils"
|
||||
import { useGetShowcase } from "~/queries/home"
|
||||
|
||||
import { Loading } from "../common/Loading"
|
||||
|
||||
export function ShowCase() {
|
||||
const showcaseSites = useGetShowcase()
|
||||
const [showcaseMore, setShowcaseMore] = useState(false)
|
||||
@@ -28,7 +30,7 @@ export function ShowCase() {
|
||||
.map(Number)}
|
||||
siteIds={showcaseSites.data?.map((s: { handle: string }) => s.handle)}
|
||||
/>
|
||||
{showcaseSites.isLoading && <p className="mt-10">{t("Loading")}...</p>}
|
||||
{showcaseSites.isLoading && <Loading className="mt-10" />}
|
||||
<ul
|
||||
className={`pt-10 grid grid-cols-2 md:grid-cols-3 gap-10 overflow-y-hidden relative text-left ${
|
||||
showcaseMore ? "" : "max-h-[540px]"
|
||||
|
||||
@@ -8,6 +8,8 @@ import { NoteType, PagesSortTypes, PageVisibilityEnum } from "~/lib/types"
|
||||
import { useGetPagesBySiteLite, usePinnedPage } from "~/queries/page"
|
||||
import { useGetSite } from "~/queries/site"
|
||||
|
||||
import { Loading } from "../common/Loading"
|
||||
|
||||
export default function SiteHome({
|
||||
handle,
|
||||
type,
|
||||
@@ -70,7 +72,7 @@ export default function SiteHome({
|
||||
return (
|
||||
<>
|
||||
<Tabs items={tabs} className="mb-6" type="rounded" />
|
||||
{!posts.data?.pages?.length && posts.isLoading && <>Loading...</>}
|
||||
{!posts.data?.pages?.length && posts.isLoading && <Loading />}
|
||||
<PostList
|
||||
posts={posts}
|
||||
pinnedNoteId={pinnedPage.noteId}
|
||||
|
||||
@@ -7,6 +7,8 @@ import PostList from "~/components/site/PostList"
|
||||
import { useGetSearchPagesBySite } from "~/queries/page"
|
||||
import { useGetSite } from "~/queries/site"
|
||||
|
||||
import { Loading } from "../common/Loading"
|
||||
|
||||
export const SiteSearch = () => {
|
||||
const t = useTranslations()
|
||||
|
||||
@@ -24,7 +26,7 @@ export const SiteSearch = () => {
|
||||
<h2 className="mb-8 mt-5 text-zinc-500">
|
||||
{posts.data?.pages?.[0].count || "0"} {t("results")}
|
||||
</h2>
|
||||
{posts.isLoading && <>{t("Loading")}...</>}
|
||||
{posts.isLoading && <Loading />}
|
||||
<PostList posts={posts} keyword={keyword} />
|
||||
</>
|
||||
)
|
||||
|
||||
@@ -50,13 +50,7 @@ import { useIsDark } from "~/hooks/useDarkMode"
|
||||
import { useGetState } from "~/hooks/useGetState"
|
||||
import { useIsUnmounted } from "~/hooks/useLifecycle"
|
||||
|
||||
const LoadingHolder = () => {
|
||||
return (
|
||||
<div className="flex-1 h-12 flex items-center justify-center">
|
||||
Loading...
|
||||
</div>
|
||||
)
|
||||
}
|
||||
import { Loading } from "../common/Loading"
|
||||
|
||||
interface XLogCodeMirrorEditorProps {
|
||||
value?: string
|
||||
@@ -229,7 +223,7 @@ const CodeMirrorEditor = forwardRef<
|
||||
(props.LoadingComponent ? (
|
||||
createElement(props.LoadingComponent)
|
||||
) : (
|
||||
<LoadingHolder />
|
||||
<Loading className="flex-1 h-12" />
|
||||
))}
|
||||
</>
|
||||
)
|
||||
|
||||
@@ -8,6 +8,7 @@ import { cn, isMobileDevice } from "~/lib/utils"
|
||||
import { useGetPage } from "~/queries/page"
|
||||
import { useGetSite } from "~/queries/site"
|
||||
|
||||
import { Loading } from "../common/Loading"
|
||||
import { Time } from "../common/Time"
|
||||
import PostCover from "../home/PostCover"
|
||||
import { Avatar } from "./Avatar"
|
||||
@@ -53,7 +54,7 @@ const XLogShorts: FC<Props> = ({ slug, handle, url }) => {
|
||||
window.open(url, "_blank")
|
||||
}, [url])
|
||||
|
||||
if (page.isLoading) return <div>Loading...</div>
|
||||
if (page.isLoading) return <Loading />
|
||||
|
||||
if (!isShort) return <UniLink href={url}>{url}</UniLink>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user