Skip to content
Merged
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
21 changes: 3 additions & 18 deletions packages/web/src/views/Life/LifeQuote.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,11 @@
import { ShuffleIcon } from "@phosphor-icons/react";
import { useState } from "react";
import { TooltipWrapper } from "@web/components/Tooltip/TooltipWrapper";
import { getRandomLifeQuote } from "./life-quotes";

export function LifeQuote() {
const [quote, setQuote] = useState(getRandomLifeQuote);
const quote = getRandomLifeQuote();

return (
<section className="flex items-start gap-1 text-text-muted">
<blockquote aria-live="polite" className="min-w-0 flex-1 italic">
{quote}
</blockquote>
<TooltipWrapper description="Show another quote">
<button
aria-label="Shuffle life quote"
className="flex size-8 items-center justify-center rounded-full text-text-muted transition-colors hover:bg-surface-panel hover:text-text focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent"
onClick={() => setQuote((current) => getRandomLifeQuote(current))}
type="button"
>
<ShuffleIcon aria-hidden="true" size={17} />
</button>
</TooltipWrapper>
<section className="text-text-muted">
<blockquote className="italic">{quote}</blockquote>
</section>
);
}
3 changes: 3 additions & 0 deletions packages/web/src/views/Life/LifeView.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ describe("LifeView", () => {
screen.queryByRole("button", { name: /zoom/i }),
).not.toBeInTheDocument();
expect(screen.queryByText(/ctrl\+scroll|pinch/i)).not.toBeInTheDocument();
expect(
screen.queryByRole("button", { name: "Shuffle life quote" }),
).not.toBeInTheDocument();
});

it("opens the birth date picker when Enter is pressed on the focused field", async () => {
Expand Down
9 changes: 1 addition & 8 deletions packages/web/src/views/Life/life-quotes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,6 @@ import { describe, expect, it } from "bun:test";

describe("life quotes", () => {
it("chooses from the supplied quotes", () => {
expect(getRandomLifeQuote(undefined, () => 0)).toBe(LIFE_QUOTES[0]);
});

it("chooses a different quote when shuffled", () => {
expect(getRandomLifeQuote(LIFE_QUOTES[0], () => 0)).toBe(LIFE_QUOTES[1]);
expect(getRandomLifeQuote(LIFE_QUOTES[0], () => 1)).not.toBe(
LIFE_QUOTES[0],
);
expect(getRandomLifeQuote(() => 0)).toBe(LIFE_QUOTES[0]);
});
});
14 changes: 4 additions & 10 deletions packages/web/src/views/Life/life-quotes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,10 @@ export const LIFE_QUOTES = [
"“Life moves pretty fast. If you don’t stop and look around once in a while, you could miss it.” (Ferris Bueller’s Day Off)",
] as const;

export function getRandomLifeQuote(
currentQuote?: string,
random = getSecureRandomNumber,
) {
const quotes = currentQuote
? LIFE_QUOTES.filter((quote) => quote !== currentQuote)
: LIFE_QUOTES;
export function getRandomLifeQuote(random = getSecureRandomNumber) {
const index = Math.min(
quotes.length - 1,
Math.floor(random() * quotes.length),
LIFE_QUOTES.length - 1,
Math.floor(random() * LIFE_QUOTES.length),
);
return quotes[index] ?? LIFE_QUOTES[0];
return LIFE_QUOTES[index] ?? LIFE_QUOTES[0];
}