Repository navigation
feat(web): static Danbooru-style frontend (home, gallery, post, upload) #3
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 hidden or 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 hidden or 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,3 @@ | ||
| # Process Tailwind CSS when the dev server bundles static assets. | ||
| [serve.static] | ||
| plugins = ["bun-plugin-tailwind"] |
This file contains hidden or 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 hidden or 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,18 @@ | ||
| /** | ||
| * Importing an image asset yields its served URL (Bun's bundler resolves it to | ||
| * a content-addressed path). | ||
| */ | ||
| declare module "*.gif" { | ||
| const src: string; | ||
| export default src; | ||
| } | ||
|
|
||
| declare module "*.png" { | ||
| const src: string; | ||
| export default src; | ||
| } | ||
|
|
||
| declare module "*.svg" { | ||
| const src: string; | ||
| export default src; | ||
| } |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 hidden or 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,47 @@ | ||
| import d0 from "../assets/counters/0.gif"; | ||
| import d1 from "../assets/counters/1.gif"; | ||
| import d2 from "../assets/counters/2.gif"; | ||
| import d3 from "../assets/counters/3.gif"; | ||
| import d4 from "../assets/counters/4.gif"; | ||
| import d5 from "../assets/counters/5.gif"; | ||
| import d6 from "../assets/counters/6.gif"; | ||
| import d7 from "../assets/counters/7.gif"; | ||
| import d8 from "../assets/counters/8.gif"; | ||
| import d9 from "../assets/counters/9.gif"; | ||
|
|
||
| /** Digit glyph GIFs indexed 0-9. */ | ||
| const DIGITS = [d0, d1, d2, d3, d4, d5, d6, d7, d8, d9] as const; | ||
|
|
||
| /** | ||
| * Odometer-style counter: renders each digit of `value` as its moe-counter GIF. | ||
| * Non-digit characters are rendered as plain text. `digitClass` controls the | ||
| * glyph height (default `h-12`). | ||
| */ | ||
| export function Counter({ | ||
| value, | ||
| className, | ||
| digitClass = "h-12", | ||
| }: { | ||
| value: string; | ||
| className?: string; | ||
| digitClass?: string; | ||
| }) { | ||
| return ( | ||
| <span | ||
| role="img" | ||
| aria-label={value} | ||
| className={`inline-flex items-end gap-px ${className ?? ""}`} | ||
| > | ||
| {[...value].map((ch, i) => { | ||
| const digit = DIGITS[ch.charCodeAt(0) - 48]; | ||
| return digit ? ( | ||
| <img key={i} src={digit} alt="" aria-hidden className={`${digitClass} w-auto`} /> | ||
| ) : ( | ||
| <span key={i} aria-hidden> | ||
| {ch} | ||
| </span> | ||
| ); | ||
| })} | ||
| </span> | ||
| ); | ||
| } | ||
This file contains hidden or 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 ReactNode, useState } from "react"; | ||
|
|
||
| import { | ||
| FloatingFocusManager, | ||
| FloatingPortal, | ||
| type Placement, | ||
| autoUpdate, | ||
| flip, | ||
| offset, | ||
| shift, | ||
| useClick, | ||
| useDismiss, | ||
| useFloating, | ||
| useInteractions, | ||
| } from "@floating-ui/react"; | ||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||
| import { ChevronDown } from "lucide-react"; | ||
|
|
||
| /** | ||
| * Click-toggled dropdown menu (Danbooru-style "Size" / "Options" menus). | ||
| * The trigger is a labelled button; the panel renders `children`. | ||
| */ | ||
| export function DropdownMenu({ | ||
| label, | ||
| children, | ||
| placement = "bottom-end", | ||
| }: { | ||
| label: ReactNode; | ||
| children: ReactNode; | ||
| placement?: Placement; | ||
| }) { | ||
| const [open, setOpen] = useState(false); | ||
|
|
||
| const { refs, floatingStyles, context } = useFloating({ | ||
| open, | ||
| onOpenChange: setOpen, | ||
| placement, | ||
| middleware: [offset(4), flip({ padding: 8 }), shift({ padding: 8 })], | ||
| whileElementsMounted: autoUpdate, | ||
| }); | ||
|
|
||
| const click = useClick(context); | ||
| const dismiss = useDismiss(context); | ||
| const { getReferenceProps, getFloatingProps } = useInteractions([click, dismiss]); | ||
|
|
||
| return ( | ||
| <> | ||
| <button | ||
| ref={refs.setReference} | ||
| {...getReferenceProps()} | ||
| type="button" | ||
| className="flex items-center gap-0.5 rounded px-1 hover:text-link" | ||
| > | ||
| {label} | ||
| <ChevronDown className="h-3 w-3" /> | ||
| </button> | ||
| {open && ( | ||
| <FloatingPortal> | ||
| <FloatingFocusManager context={context} modal={false}> | ||
| <div | ||
| ref={refs.setFloating} | ||
| style={floatingStyles} | ||
| {...getFloatingProps()} | ||
| className="z-50 min-w-40 rounded-md border border-line bg-surface p-2 text-[12px] shadow-lg" | ||
| > | ||
| {children} | ||
| </div> | ||
| </FloatingFocusManager> | ||
| </FloatingPortal> | ||
| )} | ||
| </> | ||
| ); | ||
| } | ||
This file contains hidden or 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,90 @@ | ||
| import { type ReactNode, useState } from "react"; | ||
|
|
||
| import { | ||
| FloatingPortal, | ||
| type Placement, | ||
| autoUpdate, | ||
| flip, | ||
| offset, | ||
| safePolygon, | ||
| shift, | ||
| useDismiss, | ||
| useFloating, | ||
| useFocus, | ||
| useHover, | ||
| useInteractions, | ||
| useRole, | ||
| } from "@floating-ui/react"; | ||
|
|
||
| interface HoverPopoverProps { | ||
| /** Trigger content (wrapped in an element that carries the floating ref). */ | ||
| children: ReactNode; | ||
| /** Renders the floating content; only called while open. */ | ||
| render: () => ReactNode; | ||
| /** | ||
| * Interactive popovers (clickable content) keep open while the cursor travels | ||
| * toward them (safePolygon) and use a dialog role. Default true. | ||
| */ | ||
| interactive?: boolean; | ||
| placement?: Placement; | ||
| /** Class for the trigger wrapper (e.g. to make it a grid cell). */ | ||
| className?: string; | ||
| } | ||
|
|
||
| /** | ||
| * Generic hover/focus popover built on Floating UI. Opens on pointer hover and | ||
| * keyboard focus, flips/shifts to stay in view, and dismisses on Escape or | ||
| * outside interaction. Content-agnostic — see docs/POPOVER.md. | ||
| */ | ||
| export function HoverPopover({ | ||
| children, | ||
| render, | ||
| interactive = true, | ||
| placement = "top", | ||
| className, | ||
| }: HoverPopoverProps) { | ||
| const [open, setOpen] = useState(false); | ||
|
|
||
| const { refs, floatingStyles, context } = useFloating({ | ||
| open, | ||
| onOpenChange: setOpen, | ||
| placement, | ||
| middleware: [offset(8), flip({ padding: 8 }), shift({ padding: 8 })], | ||
| whileElementsMounted: autoUpdate, | ||
| }); | ||
|
|
||
| const hover = useHover(context, { | ||
| delay: { open: 150, close: 0 }, | ||
| handleClose: interactive ? safePolygon() : null, | ||
| }); | ||
| const focus = useFocus(context); | ||
| const dismiss = useDismiss(context); | ||
| const role = useRole(context, { role: interactive ? "dialog" : "tooltip" }); | ||
|
|
||
| const { getReferenceProps, getFloatingProps } = useInteractions([ | ||
| hover, | ||
| focus, | ||
| dismiss, | ||
| role, | ||
| ]); | ||
|
|
||
| return ( | ||
| <> | ||
| <span ref={refs.setReference} className={className} {...getReferenceProps()}> | ||
| {children} | ||
| </span> | ||
| {open && ( | ||
| <FloatingPortal> | ||
| <div | ||
| ref={refs.setFloating} | ||
| style={floatingStyles} | ||
| className="z-50" | ||
| {...getFloatingProps()} | ||
| > | ||
| {render()} | ||
| </div> | ||
| </FloatingPortal> | ||
| )} | ||
| </> | ||
| ); | ||
| } |
This file contains hidden or 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,27 @@ | ||
| import { CATEGORY_ORDER, TAG_TEXT_CLASS, groupByCategory } from "../../lib/tags"; | ||
|
|
||
| /** | ||
| * Gallery-tile popover content: a post's tags grouped by category. Shown when | ||
| * hovering a thumbnail. Phase 0 takes the tags directly; Phase 1 fetches the | ||
| * post DTO via `usePostPreview(id)`. | ||
| */ | ||
| export function PostTagsCard({ postId, tags }: { postId: number; tags: string[] }) { | ||
| const grouped = groupByCategory(tags); | ||
|
|
||
| return ( | ||
| <div className="w-60 rounded-md border border-line bg-surface p-3 text-[13px] shadow-lg"> | ||
| <div className="mb-2 border-b border-line pb-1 font-bold">post #{postId}</div> | ||
| <div className="space-y-1.5"> | ||
| {CATEGORY_ORDER.filter((c) => grouped.has(c)).map((category) => ( | ||
| <ul key={category} className="flex flex-wrap gap-x-3 gap-y-0.5"> | ||
| {grouped.get(category)?.map((name) => ( | ||
| <li key={name}> | ||
| <span className={TAG_TEXT_CLASS[category]}>{name}</span> | ||
| </li> | ||
| ))} | ||
| </ul> | ||
| ))} | ||
| </div> | ||
| </div> | ||
| ); | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.