Skip to content

Commit

Permalink
Improve spinner, markdown rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
vrde committed Nov 6, 2024
1 parent ac53859 commit 4818114
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 27 deletions.
16 changes: 16 additions & 0 deletions web/src/CenteredSpinner.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Box, Spinner } from "@chakra-ui/react";

const CenteredSpinner = () => (
<Box
display="flex"
alignItems="center"
justifyContent="center"
width="100%"
height="100%"
minHeight="200px" // Adjust the min height as needed
>
<Spinner size="xl" />
</Box>
);

export default CenteredSpinner;
8 changes: 3 additions & 5 deletions web/src/Leaderboard.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import {
Heading,
Spinner,
Table,
TableContainer,
Tbody,
Td,
Th,
Thead,
Text,
Thead,
Tr,
} from "@chakra-ui/react";
import { formatDistance } from "date-fns";
Expand All @@ -22,6 +21,7 @@ import metadata from "./metadata.json";
import { CHAIN_ID } from "./env";
import { LeaderboardEntry, processLeaderboard } from "./lib";
import { useBurnerWallet } from "./hooks/useBurnerWallet";
import CenteredSpinner from "./CenteredSpinner";

const EMOJIS = metadata.keys.map((k) => k.emoji);

Expand Down Expand Up @@ -59,8 +59,6 @@ function LeaderboardComponent() {
return `${address?.slice(0, 6)}...${address?.slice(address?.length - 3, address?.length)}`;
}

console.log(leaderboardEntries);

return (
<>
<Heading>Leaderboard</Heading>
Expand Down Expand Up @@ -107,7 +105,7 @@ function LeaderboardComponent() {
</Tbody>
</Table>
</TableContainer>
{status === "pending" && <Spinner />}
{status === "pending" && <CenteredSpinner />}
</>
);
}
Expand Down
2 changes: 1 addition & 1 deletion web/src/Puzzle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function Puzzle(props: PuzzleProps) {
);

useEffect(() => {
console.log(gelatoStatus);
console.log("Gelato status", gelatoStatus);
if (gelatoStatus === "error") {
toast.closeAll();
toast({
Expand Down
40 changes: 26 additions & 14 deletions web/src/Quest.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { Heading, VStack } from "@chakra-ui/react";
import { Box, Heading, VStack } from "@chakra-ui/react";
import { useChapter } from "./hooks/useChapter";
import Markdown from "react-markdown";
import ChakraUIRenderer from "chakra-ui-markdown-renderer";
import Puzzle from "./Puzzle";
import rehypeRaw from "rehype-raw";
import { checkSolutionMatch } from "./lib";
import CenteredSpinner from "./CenteredSpinner";
import "./markdown.css";

function Quest() {
const {
Expand All @@ -14,6 +15,10 @@ function Quest() {
isLast,
} = useChapter();

const isLoading =
currentSmartContractChapterIndex === undefined ||
currentChapterContent.length === 0;

return (
<Puzzle
isLast={isLast}
Expand All @@ -24,18 +29,25 @@ function Quest() {
checkSolutionMatch(solution, currentSmartContractChapterIndex)
}
>
<VStack align="flex-start">
<Heading variant="h2">
Chapter {currentSmartContractChapterIndex}
</Heading>
<Markdown
components={ChakraUIRenderer()}
urlTransform={(value: string) => value}
rehypePlugins={[rehypeRaw]}
>
{currentChapterContent}
</Markdown>
</VStack>
{isLoading ? (
<CenteredSpinner />
) : (
<VStack align="flex-start">
<Heading variant="h3">
Chapter {currentSmartContractChapterIndex}
</Heading>
<Box as="article" fontSize="md" lineHeight="tall" color="gray.700">
<div className="markdown">
<Markdown
urlTransform={(value: string) => value}
rehypePlugins={[rehypeRaw]}
>
{currentChapterContent}
</Markdown>
</div>
</Box>
</VStack>
)}
</Puzzle>
);
}
Expand Down
10 changes: 3 additions & 7 deletions web/src/hooks/gelato.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export function useSubmitSolution(
function handleTaskStateChange() {
const taskState = taskStatus?.taskState as string;

console.log(taskState);
console.log("Task state change", taskState);
if (
["CheckPending", "ExecPending", "WaitingForConfirmation"].includes(
taskState
Expand All @@ -62,7 +62,7 @@ export function useSubmitSolution(
}

async function relay() {
console.log(`relay ${solution}`);
console.log("Relay", solution);
if (!address || !signer) {
throw "missing account";
}
Expand All @@ -78,7 +78,6 @@ export function useSubmitSolution(
const response = await relayRequest(encodedCall, address, signer);
setTaskId(response.taskId);
await fetchTaskStatus(response.taskId);
console.log(`set ${index} to taskId ${response.taskId}`);
}

async function poll() {
Expand Down Expand Up @@ -112,7 +111,7 @@ export function useSubmitSolution(
status: Status | undefined,
info?: { data?: string; error?: string }
) {
console.log(`status ${status}`);
console.log("Task status", status);
setStatus(status);
setError(info?.error);
setData(info?.data);
Expand All @@ -123,9 +122,6 @@ export function useSubmitSolution(
}

useEffect(() => {
console.log(index);
console.log(solution);
console.log(address);
if (
solution !== "" &&
address &&
Expand Down
13 changes: 13 additions & 0 deletions web/src/markdown.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.markdown h1 {
font-size: 2em;
font-weight: bold;
}

.markdown h2 {
font-size: 1.5em;
font-weight: bold;
}

.markdown p {
margin-bottom: 1em;
}

0 comments on commit 4818114

Please sign in to comment.