Skip to content

Commit a65bfc8

Browse files
Filip-Lfilip-neti
andauthored
Add loader during renew cache (#168)
Co-authored-by: Filip Lelek <[email protected]>
1 parent d3f85a3 commit a65bfc8

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

src/app/page.tsx

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,12 @@ export default function Home(): JSX.Element {
4242
const { allocators, selectedAllocator, setSelectedAllocator } = useAllocator()
4343
const session = useSession()
4444

45-
const { data, isLoading, error } = useQuery({
45+
const {
46+
data,
47+
isLoading: isDataLoading,
48+
error,
49+
refetch,
50+
} = useQuery({
4651
queryKey: ['application', selectedAllocator, session.status],
4752
queryFn: async () => {
4853
if (
@@ -84,6 +89,8 @@ export default function Home(): JSX.Element {
8489
const [searchResults, setSearchResults] = useState<Application[]>([])
8590

8691
const [openDialog, setOpenDialog] = useState(false)
92+
const [isModalLoading, setIsModalLoading] = useState(false)
93+
const [isLoading, setIsLoading] = useState(false)
8794

8895
const searchParams = useSearchParams()
8996
const notification = searchParams.get('notification')
@@ -123,7 +130,7 @@ export default function Home(): JSX.Element {
123130
}, [notification, router, searchParams, pathName])
124131

125132
useEffect(() => {
126-
if (isLoading || data == null) return
133+
if (isDataLoading || data == null) return
127134

128135
const debounceTimeout = setTimeout(() => {
129136
const filteredData = data?.filter(
@@ -150,17 +157,22 @@ export default function Home(): JSX.Element {
150157
return () => {
151158
clearTimeout(debounceTimeout)
152159
}
153-
}, [searchTerm, filter, data, isLoading])
160+
}, [searchTerm, filter, data, isDataLoading])
154161

155162
const handleRenewal = async (): Promise<void> => {
156163
try {
157164
if (selectedAllocator && selectedAllocator !== 'all') {
165+
setIsModalLoading(true)
158166
const { owner, repo } = selectedAllocator
159167
const data = await cacheRenewal(owner, repo)
160168

161169
if (data) {
162170
toast.success('Renewal successful')
171+
setIsModalLoading(false)
163172
setOpenDialog(false)
173+
setIsLoading(true)
174+
await refetch()
175+
setIsLoading(false)
164176
}
165177
}
166178
} catch (error) {
@@ -169,7 +181,7 @@ export default function Home(): JSX.Element {
169181
}
170182
}
171183

172-
if (isLoading)
184+
if (isDataLoading || isLoading)
173185
return (
174186
<div className="fixed inset-0 flex items-center justify-center z-50 bg-black bg-opacity-20">
175187
<Spinner />
@@ -317,7 +329,12 @@ export default function Home(): JSX.Element {
317329
<DialogTrigger asChild>
318330
<Button variant="default">Renew cache</Button>
319331
</DialogTrigger>
320-
<DialogContent className="sm:max-w-[500px]">
332+
<DialogContent className="sm:max-w-[500px] border-none">
333+
{isModalLoading && (
334+
<div className="fixed inset-0 flex items-center justify-center z-50 bg-black bg-opacity-50">
335+
<Spinner />
336+
</div>
337+
)}
321338
<DialogHeader>
322339
<DialogTitle>Renew cache</DialogTitle>
323340
<DialogDescription>

0 commit comments

Comments
 (0)