|
1 |
| -import { useCallback, useContext, useEffect, useMemo } from "react" |
| 1 | +import { useCallback, useContext, useEffect, useMemo, useState } from "react" |
2 | 2 | import { RFS_GlobalModalContext } from "@/components/RFS_GlobalModalContext"
|
3 | 3 | import { FairDOSearchContext } from "@/components/FairDOSearchContext"
|
4 | 4 | import { useStore } from "zustand/index"
|
5 | 5 | import { resultCache } from "@/lib/ResultCache"
|
6 | 6 | import { autoUnwrap, autoUnwrapArray, toArray } from "@/components/result/utils"
|
7 | 7 | import { DateTime } from "luxon"
|
8 |
| -import { ChevronDown, Download, GitFork, ImageOff, Microscope, Pencil, PlusIcon, SearchIcon } from "lucide-react" |
| 8 | +import { ChevronDown, Download, GitFork, ImageOff, LoaderCircle, Microscope, Pencil, PlusIcon, SearchIcon } from "lucide-react" |
9 | 9 | import { Badge } from "@/components/ui/badge"
|
10 | 10 | import { Button } from "@/components/ui/button"
|
11 | 11 | import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from "@/components/ui/dropdown-menu"
|
@@ -123,6 +123,7 @@ export function GenericResultView({
|
123 | 123 | const { openRelationGraph } = useContext(RFS_GlobalModalContext)
|
124 | 124 | const { searchTerm, elasticConnector, searchFor } = useContext(FairDOSearchContext)
|
125 | 125 | const addToResultCache = useStore(resultCache, (s) => s.set)
|
| 126 | + const [loadingRelatedItems, setLoadingRelatedItems] = useState(false) |
126 | 127 |
|
127 | 128 | const getField = useCallback(
|
128 | 129 | (field: string) => {
|
@@ -277,8 +278,10 @@ export function GenericResultView({
|
277 | 278 |
|
278 | 279 | const showRelatedItemsGraph = useCallback(async () => {
|
279 | 280 | if (!pid) return
|
| 281 | + setLoadingRelatedItems(true) |
280 | 282 | if (isMetadataFor) await fetchRelatedItems(isMetadataFor.join(" "), isMetadataFor.length)
|
281 | 283 | if (hasMetadata) await fetchRelatedItems(hasMetadata.join(" "), hasMetadata.length)
|
| 284 | + setLoadingRelatedItems(false) |
282 | 285 |
|
283 | 286 | openRelationGraph(hasMetadata ?? [], pid, isMetadataFor ?? [])
|
284 | 287 | }, [fetchRelatedItems, hasMetadata, isMetadataFor, openRelationGraph, pid])
|
@@ -368,8 +371,19 @@ export function GenericResultView({
|
368 | 371 | <div className="rfs-mt-8 rfs-flex rfs-flex-col rfs-flex-wrap rfs-justify-end rfs-gap-2 md:rfs-flex-row md:rfs-items-center md:rfs-gap-4">
|
369 | 372 | {showRelatedItemsButton && (
|
370 | 373 | <div className="rfs-flex rfs-items-center">
|
371 |
| - <Button className="rfs-grow rfs-rounded-r-none" size="sm" variant="secondary" onClick={showRelatedItemsGraph}> |
372 |
| - <GitFork className="rfs-mr-1 rfs-size-4" /> Show Related Items |
| 374 | + <Button |
| 375 | + className="rfs-grow rfs-rounded-r-none" |
| 376 | + disabled={loadingRelatedItems} |
| 377 | + size="sm" |
| 378 | + variant="secondary" |
| 379 | + onClick={showRelatedItemsGraph} |
| 380 | + > |
| 381 | + {loadingRelatedItems ? ( |
| 382 | + <LoaderCircle className="rfs-mr-1 rfs-size-4 rfs-animate-spin" /> |
| 383 | + ) : ( |
| 384 | + <GitFork className="rfs-mr-1 rfs-size-4" /> |
| 385 | + )} |
| 386 | + Show Related Items |
373 | 387 | </Button>
|
374 | 388 | <Button
|
375 | 389 | className="rfs-rounded-l-none rfs-border-l rfs-border-l-border rfs-text-xs rfs-font-bold"
|
|
0 commit comments