Skip to content

Commit

Permalink
Lint
Browse files Browse the repository at this point in the history
  • Loading branch information
simonkellly committed May 24, 2024
1 parent e478a4d commit bea7833
Show file tree
Hide file tree
Showing 13 changed files with 254 additions and 156 deletions.
95 changes: 56 additions & 39 deletions src/components/layout/ActionBar.tsx
Original file line number Diff line number Diff line change
@@ -1,67 +1,84 @@
import { cn } from "@/lib/utils";
import { HTMLAttributes, forwardRef } from "react";
import { Button, ButtonProps } from "../ui/button";
import { LucideIcon, LucideProps } from "lucide-react";
import { LucideIcon, LucideProps } from 'lucide-react';
import { HTMLAttributes, forwardRef } from 'react';
import { cn } from '@/lib/utils';
import { Button, ButtonProps } from '../ui/button';

export const ActionIcon = forwardRef<SVGSVGElement, LucideProps & { icon: LucideIcon }>(({ ...props }, ref) => (
<props.icon
className={cn("h-4 w-4", props.className)}
ref={ref}
/>
export const ActionIcon = forwardRef<
SVGSVGElement,
LucideProps & { icon: LucideIcon }
>(({ ...props }, ref) => (
<props.icon className={cn('h-4 w-4', props.className)} ref={ref} />
));

export const ActionButton = forwardRef<HTMLButtonElement, ButtonProps & { icon?: LucideIcon }>(
({ children, className, ...props }, ref) => (
<Button
ref={ref}
variant="ghost"
size={null}
className={cn('h-full aspect-square p-1', className)}
onClick={e => {
e.currentTarget.blur();
if (props.onClick) {
props.onClick(e);
}
}}
{...props}
>
{children || (props.icon && <ActionIcon icon={props.icon} />)}
</Button>
)
);
export const ActionButton = forwardRef<
HTMLButtonElement,
ButtonProps & { icon?: LucideIcon }
>(({ children, className, ...props }, ref) => (
<Button
ref={ref}
variant="ghost"
size={null}
className={cn('h-full aspect-square p-1', className)}
onClick={e => {
e.currentTarget.blur();
if (props.onClick) {
props.onClick(e);
}
}}
{...props}
>
{children || (props.icon && <ActionIcon icon={props.icon} />)}
</Button>
));

export const ActionStart = forwardRef<HTMLDivElement, HTMLAttributes<HTMLDivElement>>(({ ...props }, ref) => (
export const ActionStart = forwardRef<
HTMLDivElement,
HTMLAttributes<HTMLDivElement>
>(({ ...props }, ref) => (
<div
className={cn("flex flex-row h-full basis-1/3", props.className)}
className={cn('flex flex-row h-full basis-1/3', props.className)}
ref={ref}
{...props}
/>
));

export const ActionMiddle = forwardRef<HTMLDivElement, HTMLAttributes<HTMLDivElement>>(({ ...props }, ref) => (
export const ActionMiddle = forwardRef<
HTMLDivElement,
HTMLAttributes<HTMLDivElement>
>(({ ...props }, ref) => (
<div
className={cn("flex flex-row h-full basis-1/3 grow justify-center", props.className)}
className={cn(
'flex flex-row h-full basis-1/3 grow justify-center',
props.className
)}
ref={ref}
{...props}
/>
));

export const ActionEnd = forwardRef<HTMLDivElement, HTMLAttributes<HTMLDivElement>>(({ ...props }, ref) => (
export const ActionEnd = forwardRef<
HTMLDivElement,
HTMLAttributes<HTMLDivElement>
>(({ ...props }, ref) => (
<div
className={cn("flex flex-row-reverse h-full basis-1/3", props.className)}
className={cn('flex flex-row-reverse h-full basis-1/3', props.className)}
ref={ref}
{...props}
/>
));

export const ActionBar = forwardRef<HTMLDivElement, HTMLAttributes<HTMLDivElement>>(({ children, ...props }, ref) => (
export const ActionBar = forwardRef<
HTMLDivElement,
HTMLAttributes<HTMLDivElement>
>(({ children, ...props }, ref) => (
<div
className={cn("bg-card rounded-lg border w-full h-12 p-1 relative", props.className)}
className={cn(
'bg-card rounded-lg border w-full h-12 p-1 relative',
props.className
)}
ref={ref}
{...props}
>
<div className="h-full flex justify-between">
{children}
</div>
<div className="h-full flex justify-between">{children}</div>
</div>
));
2 changes: 1 addition & 1 deletion src/components/ui/toast.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const toastVariants = cva(
const Toast = React.forwardRef<
React.ElementRef<typeof ToastPrimitives.Root>,
React.ComponentPropsWithoutRef<typeof ToastPrimitives.Root> &
VariantProps<typeof toastVariants>
VariantProps<typeof toastVariants>
>(({ className, variant, ...props }, ref) => {
return (
<ToastPrimitives.Root
Expand Down
2 changes: 1 addition & 1 deletion src/routes/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ function Index() {
<CardDescription>Under construction.</CardDescription>
</CardHeader>
<CardContent>
<p>
<p>
Use the smart timer{' '}
<Link to="/timer" className="underline">
here
Expand Down
5 changes: 1 addition & 4 deletions src/routes/timer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ import DrawScrambleCard from '@/timer/drawScrambleCard';
import LiveCubeCard from '@/timer/liveCubeCard';
import ResultsCard from '@/timer/resultsCard';
import ScrambleDisplay from '@/timer/scrambleDisplay';
import useCubeTimer, {
HOLD_DOWN_TIME,
TimerState,
} from '@/timer/useCubeTimer';
import useCubeTimer, { HOLD_DOWN_TIME, TimerState } from '@/timer/useCubeTimer';

export const Route = createFileRoute('/timer')({
component: Timer,
Expand Down
33 changes: 20 additions & 13 deletions src/routes/trainer.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import { ScrollArea } from "@/components/ui/scroll-area";
import LiveCubeCard from "@/timer/liveCubeCard";
import DrawSolutionCard from "@/trainer/DrawSolutionCard";
import SolutionDisplay from "@/trainer/SolutionDisplay";
import TrainerBar from "@/trainer/TrainerBar";
import { TrainerStore } from "@/trainer/trainerStore";
import useAlgTrainer from "@/trainer/useAlgTrainer";
import { createFileRoute } from "@tanstack/react-router";
import { useStore } from "@tanstack/react-store";
import { createFileRoute } from '@tanstack/react-router';
import { useStore } from '@tanstack/react-store';
import { ScrollArea } from '@/components/ui/scroll-area';
import LiveCubeCard from '@/timer/liveCubeCard';
import DrawSolutionCard from '@/trainer/DrawSolutionCard';
import SolutionDisplay from '@/trainer/SolutionDisplay';
import TrainerBar from '@/trainer/TrainerBar';
import { TrainerStore } from '@/trainer/trainerStore';
import useAlgTrainer from '@/trainer/useAlgTrainer';

export const Route = createFileRoute('/trainer')({
component: Trainer,
});

function Trainer() {
function Trainer() {
useAlgTrainer();
const alg = useStore(TrainerStore, (state) => state.alg);
const alg = useStore(TrainerStore, state => state.alg);

return (
<div className="flex flex-col justify-between h-dvh w-screen p-2">
Expand All @@ -23,7 +23,14 @@ function Trainer() {
<SolutionDisplay />
<div className="absolute top-0 left-0 w-full h-full flex">
<h1 className="m-auto text-6xl sm:text-7xl md:text-9xl font-extrabold select-none">
{alg ? <>{alg.case.first}{alg.case.second}</> : "--"}
{alg ? (
<>
{alg.case.first}
{alg.case.second}
</>
) : (
'--'
)}
</h1>
</div>
</div>
Expand All @@ -35,4 +42,4 @@ function Trainer() {
</ScrollArea>
</div>
);
}
}
45 changes: 33 additions & 12 deletions src/timer/TimerBar.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
import CubeName from "@/components/cubing/cubeName";
import { ActionBar, ActionStart, ActionButton, ActionMiddle, ActionEnd, ActionIcon } from "@/components/layout/ActionBar";
import { useTheme } from "@/components/theme-provider";
import { CubeStore, connect, reset } from "@/lib/smartCube";
import { Link } from "@tanstack/react-router";
import { useStore } from "@tanstack/react-store";
import { ArrowLeft, Bluetooth, BluetoothConnected, Moon, RotateCcw, Sun } from "lucide-react";
import { Link } from '@tanstack/react-router';
import { useStore } from '@tanstack/react-store';
import {
ArrowLeft,
Bluetooth,
BluetoothConnected,
Moon,
RotateCcw,
Sun,
} from 'lucide-react';
import CubeName from '@/components/cubing/cubeName';
import {
ActionBar,
ActionStart,
ActionButton,
ActionMiddle,
ActionEnd,
ActionIcon,
} from '@/components/layout/ActionBar';
import { useTheme } from '@/components/theme-provider';
import {
Select,
SelectContent,
Expand All @@ -14,6 +27,7 @@ import {
SelectTrigger,
SelectValue,
} from '@/components/ui/select';
import { CubeStore, connect, reset } from '@/lib/smartCube';

function ThemeToggle() {
const { theme, setTheme } = useTheme();
Expand Down Expand Up @@ -43,8 +57,12 @@ export function SessionSelector() {
<SelectGroup>
<SelectLabel>Sessions</SelectLabel>
<SelectItem value="3bld">3BLD</SelectItem>
<SelectItem value="edges" disabled>Edges</SelectItem>
<SelectItem value="corners" disabled>Corners</SelectItem>
<SelectItem value="edges" disabled>
Edges
</SelectItem>
<SelectItem value="corners" disabled>
Corners
</SelectItem>
</SelectGroup>
</SelectContent>
</Select>
Expand All @@ -68,14 +86,17 @@ export default function TimerBar() {
<SessionSelector />
</ActionMiddle>
<ActionEnd>
<ActionButton className="gap-2 sm:aspect-auto sm:px-2" onClick={() => connect()}>
<ActionButton
className="gap-2 sm:aspect-auto sm:px-2"
onClick={() => connect()}
>
<ActionIcon icon={cube ? BluetoothConnected : Bluetooth} />
<span className="hidden sm:inline">
<CubeName />
</span>
</ActionButton>
{cube && <ActionButton icon={RotateCcw} onClick={() => reset()}/>}
{cube && <ActionButton icon={RotateCcw} onClick={() => reset()} />}
</ActionEnd>
</ActionBar>
);
}
}
2 changes: 1 addition & 1 deletion src/timer/useCubeTimer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import { Solve, db } from '@/lib/db';
import { SOLVED, dnfAnalyser } from '@/lib/dnfAnalyser';
import { CubeStore } from '@/lib/smartCube';
import { extractAlgs } from '@/lib/solutionParser';
import { TimerStore } from './timerStore';
import { shouldIgnoreEvent } from '@/lib/utils';
import { TimerStore } from './timerStore';

export enum TimerState {
Inactive = 'INACTIVE',
Expand Down
4 changes: 3 additions & 1 deletion src/trainer/DrawSolutionCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import { Badge } from '@/components/ui/badge';
import { TrainerStore } from './trainerStore';

export default function DrawSolutionCard() {
const scramble = useStore(TrainerStore, state => state.moves).map(m => m.move).join(' ');
const scramble = useStore(TrainerStore, state => state.moves)
.map(m => m.move)
.join(' ');

return (
<fieldset className="bg-card rounded-lg border px-4 col-span-1 h-72">
Expand Down
4 changes: 2 additions & 2 deletions src/trainer/SolutionDisplay.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useStore } from '@tanstack/react-store';
import { simplify } from '@/lib/solutionParser';
import { cn } from '@/lib/utils';
import { TrainerStore } from './trainerStore';
import { simplify } from '@/lib/solutionParser';

export default function SolutionDisplay() {
const moves = useStore(TrainerStore, state => state.moves).map(m => m.move);
Expand All @@ -14,7 +14,7 @@ export default function SolutionDisplay() {
<h2 className="text-1xl sm:text-3xl font-semibold text-center p-4 pb-0 flex-none select-none">
{splitMoves.map((move, i) => {
const className = cn(
'inline-block px-1 mx-0.5 py-0.5 sm:px-2 sm:mx-1 sm:py-1 rounded-lg',
'inline-block px-1 mx-0.5 py-0.5 sm:px-2 sm:mx-1 sm:py-1 rounded-lg'
);
return (
<div key={movesTotal + ' ' + i} className={className}>
Expand Down
36 changes: 26 additions & 10 deletions src/trainer/TrainerBar.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
import CubeName from "@/components/cubing/cubeName";
import { ActionBar, ActionStart, ActionButton, ActionEnd, ActionIcon } from "@/components/layout/ActionBar";
import { useTheme } from "@/components/theme-provider";
import { CubeStore, connect, reset } from "@/lib/smartCube";
import { Link } from "@tanstack/react-router";
import { useStore } from "@tanstack/react-store";
import { ArrowLeft, Bluetooth, BluetoothConnected, Moon, RotateCcw, Sun } from "lucide-react";
import { Link } from '@tanstack/react-router';
import { useStore } from '@tanstack/react-store';
import {
ArrowLeft,
Bluetooth,
BluetoothConnected,
Moon,
RotateCcw,
Sun,
} from 'lucide-react';
import CubeName from '@/components/cubing/cubeName';
import {
ActionBar,
ActionStart,
ActionButton,
ActionEnd,
ActionIcon,
} from '@/components/layout/ActionBar';
import { useTheme } from '@/components/theme-provider';
import { CubeStore, connect, reset } from '@/lib/smartCube';

function ThemeToggle() {
const { theme, setTheme } = useTheme();
Expand Down Expand Up @@ -38,14 +51,17 @@ export default function TrainerBar() {
<ThemeToggle />
</ActionStart>
<ActionEnd>
<ActionButton className="gap-2 sm:aspect-auto sm:px-2" onClick={() => connect()}>
<ActionButton
className="gap-2 sm:aspect-auto sm:px-2"
onClick={() => connect()}
>
<ActionIcon icon={cube ? BluetoothConnected : Bluetooth} />
<span className="hidden sm:inline">
<CubeName />
</span>
</ActionButton>
{cube && <ActionButton icon={RotateCcw} onClick={() => reset()}/>}
{cube && <ActionButton icon={RotateCcw} onClick={() => reset()} />}
</ActionEnd>
</ActionBar>
);
}
}
Loading

0 comments on commit bea7833

Please sign in to comment.