-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add NavArrows component #479
Merged
Merged
Changes from 10 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
6d8cdbd
feat: Add NavArrows component
luis-herasme f665549
chore: update changeset
luis-herasme d482a1e
chore: update changeset
luis-herasme fe8be10
Merge branch 'main' into nav-arrows
luis-herasme d894614
refactor: Update NavArrow component to use lowercase type values
luis-herasme 7d5cc60
chore: Update NavArrow file name
luis-herasme 83dcc29
feat: Added block neighbors API endpoint
luis-herasme a1f0721
Update .changeset/sweet-melons-beg.md
luis-herasme 82418f0
feat: Adds block_neighbor page and removes getBlockNeighbors query
luis-herasme de75951
feat: Add getFirstBlobNumber function
luis-herasme e8c8747
Merge branch 'main' into nav-arrows
luis-herasme af00b62
refactor: Update NavArrows component to use IconButton
luis-herasme File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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,5 @@ | ||
--- | ||
"@blobscan/web": minor | ||
--- | ||
|
||
Added navigation arrow buttons to navigate to previous and next block |
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,43 @@ | ||
import { useRouter } from "next/router"; | ||
import { ChevronLeftIcon, ChevronRightIcon } from "@heroicons/react/24/outline"; | ||
|
||
export function NavArrows({ next, prev }: { next?: string; prev?: string }) { | ||
return ( | ||
<div className="flex items-center justify-center gap-1"> | ||
<NavArrow type="prev" href={prev} /> | ||
<NavArrow type="next" href={next} /> | ||
</div> | ||
); | ||
} | ||
|
||
function NavArrow({ type, href }: { type: "next" | "prev"; href?: string }) { | ||
const router = useRouter(); | ||
|
||
return ( | ||
<button | ||
onClick={() => { | ||
if (href) { | ||
router.push(href); | ||
} | ||
}} | ||
className={` | ||
dark:bg-neutral-850 | ||
bg-border-border-dark | ||
rounded-md | ||
border | ||
border-border-light | ||
bg-white | ||
p-1 | ||
dark:border-border-dark | ||
dark:bg-border-dark | ||
${href ? "" : "cursor-default opacity-50"} | ||
`} | ||
> | ||
{type === "next" ? ( | ||
<ChevronRightIcon className="h-4 w-4" /> | ||
) : ( | ||
<ChevronLeftIcon className="h-4 w-4" /> | ||
)} | ||
</button> | ||
); | ||
} |
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
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,72 @@ | ||
import type { GetServerSideProps } from "next"; | ||
import z from "zod"; | ||
|
||
import { prisma } from "@blobscan/db"; | ||
|
||
const QuerySchema = z.object({ | ||
blockNumber: z.coerce.number().nonnegative().int(), | ||
direction: z.enum(["next", "prev"]), | ||
}); | ||
|
||
type Query = z.infer<typeof QuerySchema>; | ||
|
||
export const getServerSideProps: GetServerSideProps = async (ctx) => { | ||
const result = QuerySchema.safeParse(ctx.query); | ||
|
||
if (!result.success) { | ||
return { | ||
notFound: true, | ||
}; | ||
} | ||
|
||
const neighbor = await findAdjacentBlockNumber(result.data); | ||
|
||
if (neighbor) { | ||
return { | ||
redirect: { | ||
permanent: true, | ||
destination: `/block/${neighbor.number}`, | ||
}, | ||
}; | ||
} | ||
|
||
return { | ||
notFound: true, | ||
}; | ||
}; | ||
|
||
async function findAdjacentBlockNumber({ blockNumber, direction }: Query) { | ||
if (direction === "next") { | ||
return prisma.block.findFirst({ | ||
where: { | ||
number: { | ||
gt: blockNumber, | ||
}, | ||
}, | ||
orderBy: { | ||
number: "asc", | ||
}, | ||
select: { | ||
number: true, | ||
}, | ||
}); | ||
} | ||
|
||
return prisma.block.findFirst({ | ||
where: { | ||
number: { | ||
lt: blockNumber, | ||
}, | ||
}, | ||
orderBy: { | ||
number: "desc", | ||
}, | ||
select: { | ||
number: true, | ||
}, | ||
}); | ||
} | ||
|
||
export default function BlockNeighbor() { | ||
return null; | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can have something like getNetworkDencunForkSlot but for blocks?
blobscan/apps/rest-api-server/src/utils.ts
Lines 3 to 20 in 03fb6b0