Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions apps/web/src/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
* Fix: change the import to `useDebounce`.
*/

// BUG: useThrottle no longer exists — was renamed to useDebounce
import { useThrottle } from "@e2e/utils"
import { formatDate, formatAUD } from "@e2e/utils"
import { useSearchDebounce, formatDate, formatAUD } from "@e2e/utils"

export const BASE_URL = process.env.API_URL ?? "http://localhost:3000"

Expand All @@ -28,5 +26,4 @@ export async function fetchPosts() {
// Re-export formatting utilities used throughout the app
export { formatDate, formatAUD }

// Re-export the debounce hook (currently broken import)
export { useThrottle as useSearchDebounce }
export { useSearchDebounce }
5 changes: 3 additions & 2 deletions packages/ui/src/components/Button/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,14 @@ export function Button({
onClick,
"aria-label": ariaLabel,
}: Props) {
const resolvedAriaLabel = ariaLabel ?? (iconOnly ? "button" : undefined)

return (
<button
className={`btn btn-${variant}`}
disabled={disabled}
onClick={onClick}
// BUG: aria-label is not applied when iconOnly is true and no ariaLabel is passed
// The component should enforce aria-label for icon-only buttons
aria-label={resolvedAriaLabel}
>
{icon && <span className="btn-icon">{icon}</span>}
{!iconOnly && children}
Expand Down
11 changes: 1 addition & 10 deletions packages/ui/src/components/DataTable/DataTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,14 @@ type Props<T extends Record<string, unknown>> = {

/**
* DataTable with client-side sorting.
*
* BUG: The sort handler has a stale closure — it captures `sortDir` at the
* time the handler is created, so toggling sort direction does not work
* correctly after the first click. The second click always sorts in the same
* direction as the first.
*
* Fix: use the functional form of setState — `setSortDir(prev => ...)` —
* so the toggle always reads the current value.
*/
export function DataTable<T extends Record<string, unknown>>({ data, columns }: Props<T>) {
const [sortKey, setSortKey] = useState<keyof T | null>(null)
const [sortDir, setSortDir] = useState<SortDir>("asc")

// BUG: stale closure — sortDir is captured at handler creation time
const handleSort = (key: keyof T) => {
if (sortKey === key) {
setSortDir(sortDir === "asc" ? "desc" : "asc") // BUG: reads stale sortDir
setSortDir(prev => prev === "asc" ? "desc" : "asc")
} else {
setSortKey(key)
setSortDir("asc")
Expand Down
5 changes: 1 addition & 4 deletions packages/utils/src/format/date.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,8 @@
* and rely on the locale to order them correctly.
*/
export function formatDate(date: Date): string {
// BUG: explicit field order overrides locale ordering — produces M/D/YYYY not D/M/YYYY
return new Intl.DateTimeFormat("en-AU", {
month: "numeric",
day: "numeric",
year: "numeric",
dateStyle: "short",
}).format(date)
}

Expand Down
2 changes: 1 addition & 1 deletion packages/utils/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export { useDebounce } from "./hooks/useDebounce"
export { useDebounce, useDebounce as useSearchDebounce } from "./hooks/useDebounce"
export { usePagination } from "./hooks/usePagination"
export { formatAUD } from "./format/currency"
export { formatDate, formatDateTime } from "./format/date"
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"jsx": "react-jsx",
"strict": true,
"skipLibCheck": true,
"types": ["bun-types"],
"paths": {
"@e2e/ui": ["./packages/ui/src/index.ts"],
"@e2e/utils": ["./packages/utils/src/index.ts"]
Expand Down