-
Notifications
You must be signed in to change notification settings - Fork 0
Feat/dashboard url management phase 3 4 #30
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
4 commits
Select commit
Hold shift + click to select a range
a9f736c
feat: phase 3 & 4 — URL management list/detail/create/bulk and analytics
NehanAhmed a7b11d1
chore: add phase 3-4 spec doc and opencode config
NehanAhmed 4034e40
fix: resolve async import race in index.test.ts with resetModules + w…
NehanAhmed 4057b24
fix: address all code review findings — auth, a11y, abort controllers…
NehanAhmed 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
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,51 @@ | ||
| import { useState, useCallback } from "react" | ||
| import { Button } from "@/components/ui/button" | ||
| import { Check, Copy } from "lucide-react" | ||
| import { cn } from "@/lib/utils" | ||
|
|
||
| interface CopyButtonProps { | ||
| text: string | ||
| className?: string | ||
| variant?: "primary" | "outline" | "ghost" | ||
| size?: "default" | "sm" | "lg" | "icon" | ||
| } | ||
|
|
||
| export default function CopyButton({ text, className, variant = "outline", size = "icon" }: CopyButtonProps) { | ||
| const [copied, setCopied] = useState(false) | ||
|
|
||
| const handleCopy = useCallback(async () => { | ||
| try { | ||
| await navigator.clipboard.writeText(text) | ||
| setCopied(true) | ||
| setTimeout(() => setCopied(false), 1500) | ||
| } catch { | ||
| const input = document.createElement("input") | ||
| input.value = text | ||
| input.style.position = "fixed" | ||
| input.style.opacity = "0" | ||
| document.body.appendChild(input) | ||
| try { | ||
| input.select() | ||
| if (document.execCommand("copy")) { | ||
| setCopied(true) | ||
| setTimeout(() => setCopied(false), 1500) | ||
| } | ||
| } finally { | ||
| document.body.removeChild(input) | ||
| } | ||
| } | ||
| }, [text]) | ||
|
|
||
| return ( | ||
| <Button | ||
| variant={variant} | ||
| size={size} | ||
| onClick={handleCopy} | ||
| className={cn("gap-1.5", className)} | ||
| title="Copy to clipboard" | ||
| > | ||
| {copied ? <Check className="h-3.5 w-3.5 text-emerald-500" /> : <Copy className="h-3.5 w-3.5" />} | ||
| {copied ? "Copied" : "Copy"} | ||
| </Button> | ||
| ) | ||
| } |
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,44 @@ | ||
| import { Badge } from "@/components/ui/badge" | ||
| import { cn } from "@/lib/utils" | ||
|
|
||
| interface StatusBadgeProps { | ||
| status: string | ||
| className?: string | ||
| } | ||
|
|
||
| const statusConfig: Record<string, { label: string; variant: "default" | "secondary" | "success" | "destructive" | "outline" }> = { | ||
| active: { label: "Active", variant: "success" }, | ||
| expired: { label: "Expired", variant: "destructive" }, | ||
| scheduled: { label: "Scheduled", variant: "outline" }, | ||
| "password-protected": { label: "Password", variant: "default" }, | ||
| "blocked-bots": { label: "Bots Blocked", variant: "secondary" }, | ||
| inactive: { label: "Inactive", variant: "secondary" }, | ||
| } | ||
|
|
||
| export default function StatusBadge({ status, className }: StatusBadgeProps) { | ||
| const config = statusConfig[status] ?? { label: status, variant: "outline" as const } | ||
|
|
||
| return ( | ||
| <Badge variant={config.variant} className={cn("capitalize", className)}> | ||
| {config.label} | ||
| </Badge> | ||
| ) | ||
| } | ||
|
|
||
| export function getLinkStatus(link: { expiresAt: string | null; activeAt: string | null; hasPassword: boolean; blockBots: boolean }): string { | ||
| const now = new Date() | ||
|
|
||
| if (link.activeAt && new Date(link.activeAt) > now) { | ||
| return "scheduled" | ||
| } | ||
| if (link.expiresAt && new Date(link.expiresAt) < now) { | ||
| return "expired" | ||
| } | ||
| if (link.hasPassword) { | ||
| return "password-protected" | ||
| } | ||
| if (link.blockBots) { | ||
| return "blocked-bots" | ||
| } | ||
| return "active" | ||
| } |
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,136 @@ | ||
| import { cn } from "@/lib/utils" | ||
| import { createContext, useContext, useState, useRef, useEffect, type ReactNode } from "react" | ||
|
|
||
| interface CommandContextValue { | ||
| search: string | ||
| setSearch: (search: string) => void | ||
| filter?: (value: string, search: string) => boolean | ||
| inputRef: React.RefObject<HTMLInputElement | null> | ||
| } | ||
|
|
||
| const CommandContext = createContext<CommandContextValue | undefined>(undefined) | ||
|
|
||
| function useCommand() { | ||
| const ctx = useContext(CommandContext) | ||
| if (!ctx) throw new Error("Command components must be used within Command") | ||
| return ctx | ||
| } | ||
|
|
||
| interface CommandProps { | ||
| children: ReactNode | ||
| className?: string | ||
| filter?: (value: string, search: string) => boolean | ||
| } | ||
|
|
||
| export function Command({ children, className, filter }: CommandProps) { | ||
| const [search, setSearch] = useState("") | ||
| const inputRef = useRef<HTMLInputElement>(null) | ||
|
|
||
| useEffect(() => { | ||
| setTimeout(() => inputRef.current?.focus(), 50) | ||
| }, []) | ||
|
|
||
| return ( | ||
| <CommandContext.Provider value={{ search, setSearch, filter, inputRef }}> | ||
| <div className={cn("", className)}> | ||
| {children} | ||
| </div> | ||
| </CommandContext.Provider> | ||
| ) | ||
| } | ||
|
|
||
| interface CommandInputProps { | ||
| placeholder?: string | ||
| className?: string | ||
| } | ||
|
|
||
| export function CommandInput({ placeholder = "Search...", className }: CommandInputProps) { | ||
| const { search, setSearch, inputRef } = useCommand() | ||
| return ( | ||
| <div className="flex items-center border-b border-border px-3"> | ||
| <input | ||
| ref={inputRef} | ||
| value={search} | ||
| onChange={(e) => setSearch(e.target.value)} | ||
| placeholder={placeholder} | ||
| className={cn( | ||
| "flex h-9 w-full rounded-md bg-transparent py-2 text-sm text-foreground outline-none placeholder:text-muted-foreground", | ||
| className | ||
| )} | ||
| /> | ||
| </div> | ||
| ) | ||
| } | ||
|
|
||
| interface CommandListProps { | ||
| children: ReactNode | ||
| className?: string | ||
| } | ||
|
|
||
| export function CommandList({ children, className }: CommandListProps) { | ||
| return ( | ||
| <div className={cn("max-h-60 overflow-y-auto py-1", className)}> | ||
| {children} | ||
| </div> | ||
| ) | ||
| } | ||
|
|
||
| interface CommandEmptyProps { | ||
| children: ReactNode | ||
| className?: string | ||
| } | ||
|
|
||
| export function CommandEmpty({ children, className }: CommandEmptyProps) { | ||
| return ( | ||
| <div className={cn("py-6 text-center text-sm text-muted-foreground", className)}> | ||
| {children} | ||
| </div> | ||
| ) | ||
| } | ||
|
|
||
| interface CommandItemProps { | ||
| children: ReactNode | ||
| value?: string | ||
| onSelect?: () => void | ||
| disabled?: boolean | ||
| className?: string | ||
| } | ||
|
|
||
| export function CommandItem({ children, value, onSelect, disabled, className }: CommandItemProps) { | ||
| const { search, filter } = useCommand() | ||
| if (search) { | ||
| const match = filter ? filter(value ?? "", search) : value?.toLowerCase().includes(search.toLowerCase()) | ||
| if (!match) return null | ||
| } | ||
|
|
||
| return ( | ||
| <button | ||
| type="button" | ||
| disabled={disabled} | ||
| onClick={onSelect} | ||
| className={cn( | ||
| "relative flex w-full cursor-default select-none items-center rounded-md px-2 py-1.5 text-sm text-foreground outline-none transition-colors hover:bg-muted aria-selected:bg-muted data-[disabled]:pointer-events-none data-[disabled]:opacity-50", | ||
| className | ||
| )} | ||
| > | ||
| {children} | ||
| </button> | ||
| ) | ||
| } | ||
|
|
||
| interface CommandGroupProps { | ||
| children: ReactNode | ||
| heading?: string | ||
| className?: string | ||
| } | ||
|
|
||
| export function CommandGroup({ children, heading, className }: CommandGroupProps) { | ||
| return ( | ||
| <div className={cn("", className)}> | ||
| {heading && ( | ||
| <div className="px-2 py-1.5 text-xs font-medium text-muted-foreground">{heading}</div> | ||
| )} | ||
| {children} | ||
| </div> | ||
| ) | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.