-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Stephan Moerman
committed
Aug 24, 2023
1 parent
1809027
commit 65fef02
Showing
7 changed files
with
156 additions
and
14 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
"use client"; | ||
|
||
import { useEffect, useState } from "react"; | ||
import Image from "next/image"; | ||
|
||
import { Progress } from "@/components/ui/progress"; | ||
|
||
type Props = { | ||
finished: boolean; | ||
}; | ||
|
||
const loadingTexts = [ | ||
"Generating questions...", | ||
"Unleashing the power of curiosity...", | ||
"Diving deep into the ocean of questions...", | ||
"Harnessing the collective knowledge of the cosmos...", | ||
"Igniting the flame of wonder and exploration...", | ||
]; | ||
|
||
const LoadingQuestions = ({ finished }: Props) => { | ||
const [progress, setProgress] = useState(0); | ||
const [loadingText, setLoadingText] = useState(loadingTexts[0]); | ||
|
||
useEffect(() => { | ||
const interval = setInterval(() => { | ||
const randomIndex = Math.floor(Math.random() * loadingTexts.length); | ||
setLoadingText(loadingTexts[randomIndex]); | ||
}, 2000); | ||
return () => clearInterval(interval); | ||
}, []); | ||
|
||
useEffect(() => { | ||
const interval = setInterval(() => { | ||
setProgress((prev) => { | ||
if (finished) return 100; | ||
if (prev === 100) { | ||
return 0; | ||
} | ||
if (Math.random() < 0.1) { | ||
return prev + 2; | ||
} | ||
return prev + 0.5; | ||
}); | ||
}, 100); | ||
return () => clearInterval(interval); | ||
}, [finished]); | ||
|
||
return ( | ||
<div className="absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 w-[70vw] md:w-[60vw] flex flex-col items-center"> | ||
<Image | ||
src="/loading.gif" | ||
width={400} | ||
height={400} | ||
alt="Loading animation" | ||
/> | ||
<Progress value={progress} className="w-full mt-4" /> | ||
<h1 className="mt-2 text-xl">{loadingText}</h1> | ||
</div> | ||
); | ||
}; | ||
|
||
export default LoadingQuestions; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
"use client" | ||
|
||
import * as React from "react" | ||
import * as ProgressPrimitive from "@radix-ui/react-progress" | ||
|
||
import { cn } from "@/lib/utils" | ||
|
||
const Progress = React.forwardRef< | ||
React.ElementRef<typeof ProgressPrimitive.Root>, | ||
React.ComponentPropsWithoutRef<typeof ProgressPrimitive.Root> | ||
>(({ className, value, ...props }, ref) => ( | ||
<ProgressPrimitive.Root | ||
ref={ref} | ||
className={cn( | ||
"relative h-2 w-full overflow-hidden rounded-full bg-primary/20", | ||
className | ||
)} | ||
{...props} | ||
> | ||
<ProgressPrimitive.Indicator | ||
className="h-full w-full flex-1 bg-primary transition-all" | ||
style={{ transform: `translateX(-${100 - (value || 0)}%)` }} | ||
/> | ||
</ProgressPrimitive.Root> | ||
)) | ||
Progress.displayName = ProgressPrimitive.Root.displayName | ||
|
||
export { Progress } |