From 46b11167f78d7c638e38f7c99f3ac3a3bfc7e1b0 Mon Sep 17 00:00:00 2001 From: Dan Reeves Date: Mon, 23 Oct 2023 02:56:00 +0100 Subject: [PATCH] big file shuffle --- app/components/Form.tsx | 2 +- app/components/ThemeToggle.tsx | 2 +- app/components/ui/badge.tsx | 46 ++--- app/components/ui/button.tsx | 2 +- app/components/ui/checkbox.tsx | 34 ++-- app/components/ui/command.tsx | 190 +++++++++--------- app/components/ui/dialog.tsx | 148 +++++++------- app/components/ui/dropdown-menu.tsx | 2 +- app/components/ui/input.tsx | 30 +-- app/components/ui/label.tsx | 20 +- app/components/ui/popover.tsx | 30 +-- app/components/ui/select.tsx | 160 +++++++-------- app/components/ui/separator.tsx | 38 ++-- app/components/ui/table.tsx | 138 ++++++------- .../themeProvider.tsx} | 4 +- app/jobs/fetchMissions.ts | 4 +- app/jobs/refreshTokens.ts | 2 +- app/layout.tsx | 2 +- app/root.tsx | 2 +- app/routes/_pages.settings.tsx | 2 +- app/routes/api.gameplay_session.ts | 2 +- app/routes/armoury.$character.$store.tsx | 4 +- app/routes/armoury.$character.contracts.tsx | 2 +- app/routes/armoury.$character.inventory.tsx | 4 +- ...armoury.$character.sessions.$sessionId.tsx | 40 ++++ app/routes/armoury.$character.sessions.tsx | 55 ++--- app/routes/armoury.$character.statistics.tsx | 2 +- app/routes/armoury.traits.tsx | 4 +- app/routes/armoury.tsx | 4 +- app/routes/auth.steam.$steamId.hasToken.ts | 2 +- app/routes/auth.steam.$steamId.ts | 4 +- app/routes/devtool.tsx | 2 +- app/routes/mission-board._index.tsx | 2 +- app/routes/mission-board.history.tsx | 4 +- app/services/auth.server.ts | 2 +- app/{data => services/db}/authtoken.server.ts | 2 +- .../db}/gameplaySessions.server.ts | 21 +- .../db}/missionInstances.server.ts | 2 +- .../db}/ownedTraits.server.ts | 2 +- app/{data => services/db}/user.server.ts | 2 +- .../prisma.server.ts} | 0 app/{lib/utils.ts => utils/cn.ts} | 0 components.json | 30 +-- darktide.yml | 4 + 44 files changed, 547 insertions(+), 507 deletions(-) rename app/{theme-provider.tsx => hooks/themeProvider.tsx} (87%) create mode 100644 app/routes/armoury.$character.sessions.$sessionId.tsx rename app/{data => services/db}/authtoken.server.ts (96%) rename app/{data => services/db}/gameplaySessions.server.ts (56%) rename app/{data => services/db}/missionInstances.server.ts (90%) rename app/{data => services/db}/ownedTraits.server.ts (95%) rename app/{data => services/db}/user.server.ts (91%) rename app/{data/db.server.ts => services/prisma.server.ts} (100%) rename app/{lib/utils.ts => utils/cn.ts} (100%) diff --git a/app/components/Form.tsx b/app/components/Form.tsx index d6235a9..753c9d7 100644 --- a/app/components/Form.tsx +++ b/app/components/Form.tsx @@ -1,6 +1,6 @@ import { useSearchParams, useSubmit, Form as RemixForm } from "@remix-run/react" import type { ReactNode } from "react" -import { cn } from "~/lib/utils" +import { cn } from "~/utils/cn" type CheckboxProps = { value?: string diff --git a/app/components/ThemeToggle.tsx b/app/components/ThemeToggle.tsx index 84bad59..9d2449b 100644 --- a/app/components/ThemeToggle.tsx +++ b/app/components/ThemeToggle.tsx @@ -1,7 +1,7 @@ "use client" import { Moon, Sun } from "lucide-react" -import { useTheme } from "next-themes" +import { useTheme } from "~/hooks/themeProvider" import { Button } from "~/components/ui/button" import { diff --git a/app/components/ui/badge.tsx b/app/components/ui/badge.tsx index 8665d4f..d9b458c 100644 --- a/app/components/ui/badge.tsx +++ b/app/components/ui/badge.tsx @@ -1,36 +1,36 @@ import * as React from "react" import { cva, type VariantProps } from "class-variance-authority" -import { cn } from "app/lib/utils" +import { cn } from "~/utils/cn" const badgeVariants = cva( - "inline-flex items-center rounded-full border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2", - { - variants: { - variant: { - default: - "border-transparent bg-primary text-primary-foreground hover:bg-primary/80", - secondary: - "border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80", - destructive: - "border-transparent bg-destructive text-destructive-foreground hover:bg-destructive/80", - outline: "text-foreground", - }, - }, - defaultVariants: { - variant: "default", - }, - } + "inline-flex items-center rounded-full border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2", + { + variants: { + variant: { + default: + "border-transparent bg-primary text-primary-foreground hover:bg-primary/80", + secondary: + "border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80", + destructive: + "border-transparent bg-destructive text-destructive-foreground hover:bg-destructive/80", + outline: "text-foreground", + }, + }, + defaultVariants: { + variant: "default", + }, + }, ) export interface BadgeProps - extends React.HTMLAttributes, - VariantProps {} + extends React.HTMLAttributes, + VariantProps {} function Badge({ className, variant, ...props }: BadgeProps) { - return ( -
- ) + return ( +
+ ) } export { Badge, badgeVariants } diff --git a/app/components/ui/button.tsx b/app/components/ui/button.tsx index 09e61b7..7414187 100644 --- a/app/components/ui/button.tsx +++ b/app/components/ui/button.tsx @@ -2,7 +2,7 @@ import * as React from "react" import { Slot } from "@radix-ui/react-slot" import { cva, type VariantProps } from "class-variance-authority" -import { cn } from "app/lib/utils" +import { cn } from "~/utils/cn" const buttonVariants = cva( "inline-flex items-center justify-center rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50", diff --git a/app/components/ui/checkbox.tsx b/app/components/ui/checkbox.tsx index 378cc90..3e95629 100644 --- a/app/components/ui/checkbox.tsx +++ b/app/components/ui/checkbox.tsx @@ -2,26 +2,26 @@ import * as React from "react" import * as CheckboxPrimitive from "@radix-ui/react-checkbox" import { Check } from "lucide-react" -import { cn } from "app/lib/utils" +import { cn } from "~/utils/cn" const Checkbox = React.forwardRef< - React.ElementRef, - React.ComponentPropsWithoutRef + React.ElementRef, + React.ComponentPropsWithoutRef >(({ className, ...props }, ref) => ( - - - - - + + + + + )) Checkbox.displayName = CheckboxPrimitive.Root.displayName diff --git a/app/components/ui/command.tsx b/app/components/ui/command.tsx index 0763955..8b5ba0e 100644 --- a/app/components/ui/command.tsx +++ b/app/components/ui/command.tsx @@ -1,153 +1,153 @@ import * as React from "react" -import { DialogProps } from "@radix-ui/react-dialog" +import type { DialogProps } from "@radix-ui/react-dialog" import { Command as CommandPrimitive } from "cmdk" import { Search } from "lucide-react" -import { cn } from "app/lib/utils" +import { cn } from "~/utils/cn" import { Dialog, DialogContent } from "app/components/ui/dialog" const Command = React.forwardRef< - React.ElementRef, - React.ComponentPropsWithoutRef + React.ElementRef, + React.ComponentPropsWithoutRef >(({ className, ...props }, ref) => ( - + )) Command.displayName = CommandPrimitive.displayName interface CommandDialogProps extends DialogProps {} const CommandDialog = ({ children, ...props }: CommandDialogProps) => { - return ( - - - - {children} - - - - ) + return ( + + + + {children} + + + + ) } const CommandInput = React.forwardRef< - React.ElementRef, - React.ComponentPropsWithoutRef + React.ElementRef, + React.ComponentPropsWithoutRef >(({ className, ...props }, ref) => ( -
- - -
+
+ + +
)) CommandInput.displayName = CommandPrimitive.Input.displayName const CommandList = React.forwardRef< - React.ElementRef, - React.ComponentPropsWithoutRef + React.ElementRef, + React.ComponentPropsWithoutRef >(({ className, ...props }, ref) => ( - + )) CommandList.displayName = CommandPrimitive.List.displayName const CommandEmpty = React.forwardRef< - React.ElementRef, - React.ComponentPropsWithoutRef + React.ElementRef, + React.ComponentPropsWithoutRef >((props, ref) => ( - + )) CommandEmpty.displayName = CommandPrimitive.Empty.displayName const CommandGroup = React.forwardRef< - React.ElementRef, - React.ComponentPropsWithoutRef + React.ElementRef, + React.ComponentPropsWithoutRef >(({ className, ...props }, ref) => ( - + )) CommandGroup.displayName = CommandPrimitive.Group.displayName const CommandSeparator = React.forwardRef< - React.ElementRef, - React.ComponentPropsWithoutRef + React.ElementRef, + React.ComponentPropsWithoutRef >(({ className, ...props }, ref) => ( - + )) CommandSeparator.displayName = CommandPrimitive.Separator.displayName const CommandItem = React.forwardRef< - React.ElementRef, - React.ComponentPropsWithoutRef + React.ElementRef, + React.ComponentPropsWithoutRef >(({ className, ...props }, ref) => ( - + )) CommandItem.displayName = CommandPrimitive.Item.displayName const CommandShortcut = ({ - className, - ...props + className, + ...props }: React.HTMLAttributes) => { - return ( - - ) + return ( + + ) } CommandShortcut.displayName = "CommandShortcut" export { - Command, - CommandDialog, - CommandInput, - CommandList, - CommandEmpty, - CommandGroup, - CommandItem, - CommandShortcut, - CommandSeparator, + Command, + CommandDialog, + CommandInput, + CommandList, + CommandEmpty, + CommandGroup, + CommandItem, + CommandShortcut, + CommandSeparator, } diff --git a/app/components/ui/dialog.tsx b/app/components/ui/dialog.tsx index 20e93b1..6524187 100644 --- a/app/components/ui/dialog.tsx +++ b/app/components/ui/dialog.tsx @@ -2,7 +2,7 @@ import * as React from "react" import * as DialogPrimitive from "@radix-ui/react-dialog" import { X } from "lucide-react" -import { cn } from "app/lib/utils" +import { cn } from "~/utils/cn" const Dialog = DialogPrimitive.Root @@ -11,107 +11,107 @@ const DialogTrigger = DialogPrimitive.Trigger const DialogPortal = DialogPrimitive.Portal const DialogOverlay = React.forwardRef< - React.ElementRef, - React.ComponentPropsWithoutRef + React.ElementRef, + React.ComponentPropsWithoutRef >(({ className, ...props }, ref) => ( - + )) DialogOverlay.displayName = DialogPrimitive.Overlay.displayName const DialogContent = React.forwardRef< - React.ElementRef, - React.ComponentPropsWithoutRef + React.ElementRef, + React.ComponentPropsWithoutRef >(({ className, children, ...props }, ref) => ( - - - - {children} - - - Close - - - + + + + {children} + + + Close + + + )) DialogContent.displayName = DialogPrimitive.Content.displayName const DialogHeader = ({ - className, - ...props + className, + ...props }: React.HTMLAttributes) => ( -
+
) DialogHeader.displayName = "DialogHeader" const DialogFooter = ({ - className, - ...props + className, + ...props }: React.HTMLAttributes) => ( -
+
) DialogFooter.displayName = "DialogFooter" const DialogTitle = React.forwardRef< - React.ElementRef, - React.ComponentPropsWithoutRef + React.ElementRef, + React.ComponentPropsWithoutRef >(({ className, ...props }, ref) => ( - + )) DialogTitle.displayName = DialogPrimitive.Title.displayName const DialogDescription = React.forwardRef< - React.ElementRef, - React.ComponentPropsWithoutRef + React.ElementRef, + React.ComponentPropsWithoutRef >(({ className, ...props }, ref) => ( - + )) DialogDescription.displayName = DialogPrimitive.Description.displayName export { - Dialog, - DialogPortal, - DialogOverlay, - DialogTrigger, - DialogContent, - DialogHeader, - DialogFooter, - DialogTitle, - DialogDescription, + Dialog, + DialogPortal, + DialogOverlay, + DialogTrigger, + DialogContent, + DialogHeader, + DialogFooter, + DialogTitle, + DialogDescription, } diff --git a/app/components/ui/dropdown-menu.tsx b/app/components/ui/dropdown-menu.tsx index be6cc6c..244f347 100644 --- a/app/components/ui/dropdown-menu.tsx +++ b/app/components/ui/dropdown-menu.tsx @@ -2,7 +2,7 @@ import * as React from "react" import * as DropdownMenuPrimitive from "@radix-ui/react-dropdown-menu" import { Check, ChevronRight, Circle } from "lucide-react" -import { cn } from "app/lib/utils" +import { cn } from "~/utils/cn" const DropdownMenu = DropdownMenuPrimitive.Root diff --git a/app/components/ui/input.tsx b/app/components/ui/input.tsx index 23e9432..ef82666 100644 --- a/app/components/ui/input.tsx +++ b/app/components/ui/input.tsx @@ -1,24 +1,24 @@ import * as React from "react" -import { cn } from "app/lib/utils" +import { cn } from "~/utils/cn" export interface InputProps - extends React.InputHTMLAttributes {} + extends React.InputHTMLAttributes {} const Input = React.forwardRef( - ({ className, type, ...props }, ref) => { - return ( - - ) - } + ({ className, type, ...props }, ref) => { + return ( + + ) + }, ) Input.displayName = "Input" diff --git a/app/components/ui/label.tsx b/app/components/ui/label.tsx index 416ef98..184264c 100644 --- a/app/components/ui/label.tsx +++ b/app/components/ui/label.tsx @@ -2,22 +2,22 @@ import * as React from "react" import * as LabelPrimitive from "@radix-ui/react-label" import { cva, type VariantProps } from "class-variance-authority" -import { cn } from "app/lib/utils" +import { cn } from "~/utils/cn" const labelVariants = cva( - "text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70" + "text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70", ) const Label = React.forwardRef< - React.ElementRef, - React.ComponentPropsWithoutRef & - VariantProps + React.ElementRef, + React.ComponentPropsWithoutRef & + VariantProps >(({ className, ...props }, ref) => ( - + )) Label.displayName = LabelPrimitive.Root.displayName diff --git a/app/components/ui/popover.tsx b/app/components/ui/popover.tsx index c2b118c..2219a08 100644 --- a/app/components/ui/popover.tsx +++ b/app/components/ui/popover.tsx @@ -1,28 +1,28 @@ import * as React from "react" import * as PopoverPrimitive from "@radix-ui/react-popover" -import { cn } from "app/lib/utils" +import { cn } from "~/utils/cn" const Popover = PopoverPrimitive.Root const PopoverTrigger = PopoverPrimitive.Trigger const PopoverContent = React.forwardRef< - React.ElementRef, - React.ComponentPropsWithoutRef + React.ElementRef, + React.ComponentPropsWithoutRef >(({ className, align = "center", sideOffset = 4, ...props }, ref) => ( - - - + + + )) PopoverContent.displayName = PopoverPrimitive.Content.displayName diff --git a/app/components/ui/select.tsx b/app/components/ui/select.tsx index e45eb5f..e244525 100644 --- a/app/components/ui/select.tsx +++ b/app/components/ui/select.tsx @@ -2,7 +2,7 @@ import * as React from "react" import * as SelectPrimitive from "@radix-ui/react-select" import { Check, ChevronDown } from "lucide-react" -import { cn } from "app/lib/utils" +import { cn } from "~/utils/cn" const Select = SelectPrimitive.Root @@ -11,109 +11,109 @@ const SelectGroup = SelectPrimitive.Group const SelectValue = SelectPrimitive.Value const SelectTrigger = React.forwardRef< - React.ElementRef, - React.ComponentPropsWithoutRef + React.ElementRef, + React.ComponentPropsWithoutRef >(({ className, children, ...props }, ref) => ( - - {children} - - - - + + {children} + + + + )) SelectTrigger.displayName = SelectPrimitive.Trigger.displayName const SelectContent = React.forwardRef< - React.ElementRef, - React.ComponentPropsWithoutRef + React.ElementRef, + React.ComponentPropsWithoutRef >(({ className, children, position = "popper", ...props }, ref) => ( - - - - {children} - - - + + + + {children} + + + )) SelectContent.displayName = SelectPrimitive.Content.displayName const SelectLabel = React.forwardRef< - React.ElementRef, - React.ComponentPropsWithoutRef + React.ElementRef, + React.ComponentPropsWithoutRef >(({ className, ...props }, ref) => ( - + )) SelectLabel.displayName = SelectPrimitive.Label.displayName const SelectItem = React.forwardRef< - React.ElementRef, - React.ComponentPropsWithoutRef + React.ElementRef, + React.ComponentPropsWithoutRef >(({ className, children, ...props }, ref) => ( - - - - - - + + + + + + - {children} - + {children} + )) SelectItem.displayName = SelectPrimitive.Item.displayName const SelectSeparator = React.forwardRef< - React.ElementRef, - React.ComponentPropsWithoutRef + React.ElementRef, + React.ComponentPropsWithoutRef >(({ className, ...props }, ref) => ( - + )) SelectSeparator.displayName = SelectPrimitive.Separator.displayName export { - Select, - SelectGroup, - SelectValue, - SelectTrigger, - SelectContent, - SelectLabel, - SelectItem, - SelectSeparator, + Select, + SelectGroup, + SelectValue, + SelectTrigger, + SelectContent, + SelectLabel, + SelectItem, + SelectSeparator, } diff --git a/app/components/ui/separator.tsx b/app/components/ui/separator.tsx index c970cb9..59eecb6 100644 --- a/app/components/ui/separator.tsx +++ b/app/components/ui/separator.tsx @@ -1,28 +1,28 @@ import * as React from "react" import * as SeparatorPrimitive from "@radix-ui/react-separator" -import { cn } from "app/lib/utils" +import { cn } from "~/utils/cn" const Separator = React.forwardRef< - React.ElementRef, - React.ComponentPropsWithoutRef + React.ElementRef, + React.ComponentPropsWithoutRef >( - ( - { className, orientation = "horizontal", decorative = true, ...props }, - ref - ) => ( - - ) + ( + { className, orientation = "horizontal", decorative = true, ...props }, + ref, + ) => ( + + ), ) Separator.displayName = SeparatorPrimitive.Root.displayName diff --git a/app/components/ui/table.tsx b/app/components/ui/table.tsx index 5529e00..61b0ac5 100644 --- a/app/components/ui/table.tsx +++ b/app/components/ui/table.tsx @@ -1,114 +1,114 @@ import * as React from "react" -import { cn } from "app/lib/utils" +import { cn } from "~/utils/cn" const Table = React.forwardRef< - HTMLTableElement, - React.HTMLAttributes + HTMLTableElement, + React.HTMLAttributes >(({ className, ...props }, ref) => ( -
- - +
+
+ )) Table.displayName = "Table" const TableHeader = React.forwardRef< - HTMLTableSectionElement, - React.HTMLAttributes + HTMLTableSectionElement, + React.HTMLAttributes >(({ className, ...props }, ref) => ( - + )) TableHeader.displayName = "TableHeader" const TableBody = React.forwardRef< - HTMLTableSectionElement, - React.HTMLAttributes + HTMLTableSectionElement, + React.HTMLAttributes >(({ className, ...props }, ref) => ( - + )) TableBody.displayName = "TableBody" const TableFooter = React.forwardRef< - HTMLTableSectionElement, - React.HTMLAttributes + HTMLTableSectionElement, + React.HTMLAttributes >(({ className, ...props }, ref) => ( - + )) TableFooter.displayName = "TableFooter" const TableRow = React.forwardRef< - HTMLTableRowElement, - React.HTMLAttributes + HTMLTableRowElement, + React.HTMLAttributes >(({ className, ...props }, ref) => ( - + )) TableRow.displayName = "TableRow" const TableHead = React.forwardRef< - HTMLTableCellElement, - React.ThHTMLAttributes + HTMLTableCellElement, + React.ThHTMLAttributes >(({ className, ...props }, ref) => ( -
+ )) TableHead.displayName = "TableHead" const TableCell = React.forwardRef< - HTMLTableCellElement, - React.TdHTMLAttributes + HTMLTableCellElement, + React.TdHTMLAttributes >(({ className, ...props }, ref) => ( - + )) TableCell.displayName = "TableCell" const TableCaption = React.forwardRef< - HTMLTableCaptionElement, - React.HTMLAttributes + HTMLTableCaptionElement, + React.HTMLAttributes >(({ className, ...props }, ref) => ( -
+ )) TableCaption.displayName = "TableCaption" export { - Table, - TableHeader, - TableBody, - TableFooter, - TableHead, - TableRow, - TableCell, - TableCaption, + Table, + TableHeader, + TableBody, + TableFooter, + TableHead, + TableRow, + TableCell, + TableCaption, } diff --git a/app/theme-provider.tsx b/app/hooks/themeProvider.tsx similarity index 87% rename from app/theme-provider.tsx rename to app/hooks/themeProvider.tsx index 1e0e83d..dac8bca 100644 --- a/app/theme-provider.tsx +++ b/app/hooks/themeProvider.tsx @@ -1,8 +1,8 @@ -"use client" - import { ThemeProvider as NextThemesProvider } from "next-themes" import { type ThemeProviderProps } from "next-themes/dist/types" export function ThemeProvider({ children, ...props }: ThemeProviderProps) { return {children} } + +export { useTheme } from "next-themes" diff --git a/app/jobs/fetchMissions.ts b/app/jobs/fetchMissions.ts index 7f52e65..3f649ed 100644 --- a/app/jobs/fetchMissions.ts +++ b/app/jobs/fetchMissions.ts @@ -1,6 +1,6 @@ import { getMissions } from "~/services/darktide.server" -import { saveMissions } from "~/data/missionInstances.server" -import { getAuthTokenBySteamId } from "~/data/authtoken.server" +import { saveMissions } from "~/services/db/missionInstances.server" +import { getAuthTokenBySteamId } from "~/services/db/authtoken.server" export async function fetchMissions() { console.log("Starting mission refresh...") diff --git a/app/jobs/refreshTokens.ts b/app/jobs/refreshTokens.ts index aa32eb9..356fade 100644 --- a/app/jobs/refreshTokens.ts +++ b/app/jobs/refreshTokens.ts @@ -2,7 +2,7 @@ import { deleteAuthToken, getExpiringTokens, updateAuthToken, -} from "~/data/authtoken.server" +} from "~/services/db/authtoken.server" import { refreshToken } from "~/services/darktide.server" export async function refreshTokens(inNext = 30) { diff --git a/app/layout.tsx b/app/layout.tsx index 654cf34..e8cb76d 100644 --- a/app/layout.tsx +++ b/app/layout.tsx @@ -4,7 +4,7 @@ import { Link, NavLink, Outlet } from "@remix-run/react" import type { User } from "./services/auth.server" import { ThemeToggle } from "~/components/ThemeToggle" import { Button, buttonVariants } from "~/components/ui/button" -import { cn } from "~/lib/utils" +import { cn } from "~/utils/cn" import { DropdownMenu, DropdownMenuTrigger, diff --git a/app/root.tsx b/app/root.tsx index b248034..3b79c1e 100644 --- a/app/root.tsx +++ b/app/root.tsx @@ -14,7 +14,7 @@ import { authenticator } from "~/services/auth.server" import { initJobs } from "~/jobs/index.server" import { useRevalidateOnFocus } from "~/hooks/revalidateOnFocus" -import { ThemeProvider } from "./theme-provider" +import { ThemeProvider } from "./hooks/themeProvider" import acceptLanguage from "accept-language-parser" import { LocaleProvider } from "./hooks/locale" diff --git a/app/routes/_pages.settings.tsx b/app/routes/_pages.settings.tsx index 6a87fcc..056d8e1 100644 --- a/app/routes/_pages.settings.tsx +++ b/app/routes/_pages.settings.tsx @@ -1,6 +1,6 @@ import type { ActionArgs, LoaderArgs } from "@remix-run/node" import { json } from "@remix-run/node" -import { deleteAuthToken, getAuthToken } from "~/data/authtoken.server" +import { deleteAuthToken, getAuthToken } from "~/services/db/authtoken.server" import { authenticator } from "~/services/auth.server" import { Form, useLoaderData } from "@remix-run/react" diff --git a/app/routes/api.gameplay_session.ts b/app/routes/api.gameplay_session.ts index 12eb09a..b5305c1 100644 --- a/app/routes/api.gameplay_session.ts +++ b/app/routes/api.gameplay_session.ts @@ -1,7 +1,7 @@ import type { ActionArgs } from "@remix-run/server-runtime" import { json } from "@remix-run/server-runtime" import { z } from "zod" -import { saveGameplaySession } from "~/data/gameplaySessions.server" +import { saveGameplaySession } from "~/services/db/gameplaySessions.server" let GameplaySessionSchema = z.object({ account_id: z.string(), diff --git a/app/routes/armoury.$character.$store.tsx b/app/routes/armoury.$character.$store.tsx index c92ba1b..e6f7e08 100644 --- a/app/routes/armoury.$character.$store.tsx +++ b/app/routes/armoury.$character.$store.tsx @@ -8,7 +8,7 @@ import type { ActionArgs, LoaderArgs } from "@remix-run/node" import { redirect, json } from "@remix-run/node" import { z } from "zod" import { zx } from "zodix" -import { getAuthToken } from "~/data/authtoken.server" +import { getAuthToken } from "~/services/db/authtoken.server" import { getItems } from "~/data/items.server" import { CurioSchema, TraitSchema, WeaponSchema } from "~/data/schemas.server" import { replaceAll } from "~/data/utils.server" @@ -37,7 +37,7 @@ import { SelectGroup } from "@radix-ui/react-select" import { titleCase } from "~/utils/titleCase" import { ChevronsUp, Database } from "lucide-react" import { Button } from "~/components/ui/button" -import { cn } from "~/lib/utils" +import { cn } from "~/utils/cn" import useLocale from "~/hooks/locale" let storeSlugToType: Record = { diff --git a/app/routes/armoury.$character.contracts.tsx b/app/routes/armoury.$character.contracts.tsx index b6f226e..5807e4e 100644 --- a/app/routes/armoury.$character.contracts.tsx +++ b/app/routes/armoury.$character.contracts.tsx @@ -5,7 +5,7 @@ import { json } from "@remix-run/node" import { useEffect, useState } from "react" import { z } from "zod" import { zx } from "zodix" -import { getAuthToken } from "~/data/authtoken.server" +import { getAuthToken } from "~/services/db/authtoken.server" import { authenticator } from "~/services/auth.server" import { completeCharacterContract, diff --git a/app/routes/armoury.$character.inventory.tsx b/app/routes/armoury.$character.inventory.tsx index 69bc897..4c9216a 100644 --- a/app/routes/armoury.$character.inventory.tsx +++ b/app/routes/armoury.$character.inventory.tsx @@ -5,13 +5,13 @@ import { z } from "zod" import { zx } from "zodix" import { Form } from "~/components/Form" import { Img } from "~/components/Img" -import { getAuthToken } from "~/data/authtoken.server" +import { getAuthToken } from "~/services/db/authtoken.server" import { getItems } from "~/data/items.server" import { BlessingSchema, WeaponSchema } from "~/data/schemas.server" import { authenticator } from "~/services/auth.server" import { getAccountGear } from "~/services/darktide.server" import { getSearchParam } from "~/utils/getSearchParam" -import { cn } from "~/lib/utils" +import { cn } from "~/utils/cn" import { Input } from "~/components/ui/input" import { Label } from "~/components/ui/label" import { ChevronsUp } from "lucide-react" diff --git a/app/routes/armoury.$character.sessions.$sessionId.tsx b/app/routes/armoury.$character.sessions.$sessionId.tsx new file mode 100644 index 0000000..2028e8c --- /dev/null +++ b/app/routes/armoury.$character.sessions.$sessionId.tsx @@ -0,0 +1,40 @@ +import { useLoaderData } from "@remix-run/react" +import type { LoaderArgs } from "@remix-run/server-runtime" +import { json } from "@remix-run/server-runtime" +import { z } from "zod" +import { zx } from "zodix" +import { getAuthToken } from "~/services/db/authtoken.server" +import { authenticator } from "~/services/auth.server" +import { getGameplaySession } from "~/services/db/gameplaySessions.server" + +export async function loader({ params, request }: LoaderArgs) { + let { character: characterId, sessionId } = zx.parseParams(params, { + character: z.string(), + sessionId: z.string(), + }) + let user = await authenticator.isAuthenticated(request, { + failureRedirect: "/login", + }) + + let auth = await getAuthToken(user.id) + + let gameplaySession = await getGameplaySession({ + accountId: auth.sub, + characterId, + sessionId, + }) + + return json({ + session: gameplaySession, + }) +} + +export default function Statistics() { + let { session } = useLoaderData() + + return ( +
+ {JSON.stringify(session)} +
+ ) +} diff --git a/app/routes/armoury.$character.sessions.tsx b/app/routes/armoury.$character.sessions.tsx index a012bbd..94e1da2 100644 --- a/app/routes/armoury.$character.sessions.tsx +++ b/app/routes/armoury.$character.sessions.tsx @@ -1,11 +1,10 @@ -import { Link, useLoaderData } from "@remix-run/react" +import { Link, useLoaderData, useOutlet } from "@remix-run/react" import type { LoaderArgs } from "@remix-run/server-runtime" import { json } from "@remix-run/server-runtime" import { z } from "zod" import { zx } from "zodix" -import { getAuthToken } from "~/data/authtoken.server" +import { getAuthToken } from "~/services/db/authtoken.server" import { authenticator } from "~/services/auth.server" -import { getCharacterStats } from "~/services/darktide.server" import { Table, TableBody, @@ -14,44 +13,9 @@ import { TableHeader, TableRow, } from "~/components/ui/table" -import { zipObjectDeep, get, orderBy } from "lodash-es" -import { is, record, string } from "valibot" -import { getGameplaySessions } from "~/data/gameplaySessions.server" +import { getGameplaySessions } from "~/services/db/gameplaySessions.server" import useLocale from "~/hooks/locale" -type Stats = { typePath: string[]; value: Record }[] -function zipStats(stats: Stats) { - return zipObjectDeep( - stats.map((stat) => stat.typePath.join(".")), - stats.map((stat) => stat.value), - ) -} - -function explodeKeyTable(keyTable: unknown): Record[] { - let result = [] - - if (is(record(string()), keyTable)) { - for (let key in keyTable) { - let value = keyTable[key] - let row: Record = { value } - - let otherCols = key.split("|") - if (Array.isArray(otherCols) && otherCols.length) { - for (let col of otherCols) { - let [key, val] = col.split(":") - if (key) { - row[key] = val - } - } - } - - result.push(row) - } - } - - return result -} - export async function loader({ params, request }: LoaderArgs) { let { character: characterId } = zx.parseParams(params, { character: z.string(), @@ -77,6 +41,19 @@ export async function loader({ params, request }: LoaderArgs) { export default function Statistics() { let { sessions } = useLoaderData() let locale = useLocale() + let subpage = useOutlet() + + if (process.env.NODE_ENV !== "development") { + return ( +
+ coming soon +
+ ) + } + + if (subpage) { + return subpage + } return (
diff --git a/app/routes/armoury.$character.statistics.tsx b/app/routes/armoury.$character.statistics.tsx index 7e9d82a..8c0adad 100644 --- a/app/routes/armoury.$character.statistics.tsx +++ b/app/routes/armoury.$character.statistics.tsx @@ -3,7 +3,7 @@ import type { LoaderArgs } from "@remix-run/server-runtime" import { json } from "@remix-run/server-runtime" import { z } from "zod" import { zx } from "zodix" -import { getAuthToken } from "~/data/authtoken.server" +import { getAuthToken } from "~/services/db/authtoken.server" import { authenticator } from "~/services/auth.server" import { getCharacterStats } from "~/services/darktide.server" import { diff --git a/app/routes/armoury.traits.tsx b/app/routes/armoury.traits.tsx index a4115d6..2eeacb6 100644 --- a/app/routes/armoury.traits.tsx +++ b/app/routes/armoury.traits.tsx @@ -2,7 +2,7 @@ import type { ActionArgs, LoaderArgs } from "@remix-run/node" import { Tabs, TabList, Tab, TabPanel } from "react-aria-components" import { json } from "@remix-run/node" import { useLoaderData, useNavigation, Form } from "@remix-run/react" -import { getAuthToken } from "~/data/authtoken.server" +import { getAuthToken } from "~/services/db/authtoken.server" import { getItems } from "~/data/items.server" import { BlessingSchema, WeaponSchema } from "~/data/schemas.server" import { authenticator } from "~/services/auth.server" @@ -10,7 +10,7 @@ import { getAccountTrait } from "~/services/darktide.server" import { getUserOwnedTraits, setUserOwnedTraits, -} from "~/data/ownedTraits.server" +} from "~/services/db/ownedTraits.server" import { getWeaponTemplates } from "~/data/weaponTemplates.server" import type { AuthToken } from "@prisma/client" import { ArrowPathIcon } from "@heroicons/react/24/outline" diff --git a/app/routes/armoury.tsx b/app/routes/armoury.tsx index 1c030b5..26911c9 100644 --- a/app/routes/armoury.tsx +++ b/app/routes/armoury.tsx @@ -7,7 +7,7 @@ import { useMatches, useNavigate, } from "@remix-run/react" -import { getAuthToken } from "~/data/authtoken.server" +import { getAuthToken } from "~/services/db/authtoken.server" import { authenticator } from "~/services/auth.server" import { ExclamationCircleIcon } from "@heroicons/react/24/outline" import { getAccountSummary } from "~/services/darktide.server" @@ -19,7 +19,7 @@ import { import { Command, CommandGroup, CommandItem } from "~/components/ui/command" import { ChevronsUpDown } from "lucide-react" import { Button } from "~/components/ui/button" -import { cn } from "~/lib/utils" +import { cn } from "~/utils/cn" import { Separator } from "~/components/ui/separator" let navLinks = [{ label: "Trait collection", link: "traits" }] diff --git a/app/routes/auth.steam.$steamId.hasToken.ts b/app/routes/auth.steam.$steamId.hasToken.ts index faa1446..e8eb56c 100644 --- a/app/routes/auth.steam.$steamId.hasToken.ts +++ b/app/routes/auth.steam.$steamId.hasToken.ts @@ -1,6 +1,6 @@ import type { LoaderArgs } from "@remix-run/node" import { json } from "@remix-run/node" -import { getAuthTokenBySteamId } from "~/data/authtoken.server" +import { getAuthTokenBySteamId } from "~/services/db/authtoken.server" export async function loader({ params }: LoaderArgs) { if (params.steamId) { diff --git a/app/routes/auth.steam.$steamId.ts b/app/routes/auth.steam.$steamId.ts index 7c55573..acc908e 100644 --- a/app/routes/auth.steam.$steamId.ts +++ b/app/routes/auth.steam.$steamId.ts @@ -1,7 +1,7 @@ import type { LoaderArgs } from "@remix-run/node" import { json } from "@remix-run/node" -import { updateAuthToken } from "~/data/authtoken.server" -import { getUserBySteamId } from "~/data/user.server" +import { updateAuthToken } from "~/services/db/authtoken.server" +import { getUserBySteamId } from "~/services/db/user.server" import { checkToken, joinQueue } from "~/services/darktide.server" import { sleep } from "~/utils/sleep" diff --git a/app/routes/devtool.tsx b/app/routes/devtool.tsx index a6d55bb..79064f3 100644 --- a/app/routes/devtool.tsx +++ b/app/routes/devtool.tsx @@ -3,7 +3,7 @@ import { json } from "@remix-run/server-runtime" import type { ActionArgs, LoaderArgs } from "@remix-run/server-runtime" import { Button } from "~/components/ui/button" import { Input } from "~/components/ui/input" -import { getAuthToken } from "~/data/authtoken.server" +import { getAuthToken } from "~/services/db/authtoken.server" import { authenticator } from "~/services/auth.server" export async function loader({ request }: LoaderArgs) { diff --git a/app/routes/mission-board._index.tsx b/app/routes/mission-board._index.tsx index 9038ae9..77aaf70 100644 --- a/app/routes/mission-board._index.tsx +++ b/app/routes/mission-board._index.tsx @@ -1,7 +1,7 @@ import type { LoaderArgs } from "@remix-run/node" import { json } from "@remix-run/node" import { reverse, sortBy } from "lodash-es" -import { getAuthTokenBySteamId } from "~/data/authtoken.server" +import { getAuthTokenBySteamId } from "~/services/db/authtoken.server" import { getMissions } from "~/services/darktide.server" import { getMissionTemplate, diff --git a/app/routes/mission-board.history.tsx b/app/routes/mission-board.history.tsx index 10abbae..d7618b1 100644 --- a/app/routes/mission-board.history.tsx +++ b/app/routes/mission-board.history.tsx @@ -1,7 +1,7 @@ import { Link, useLoaderData, useSearchParams } from "@remix-run/react" import type { LoaderArgs } from "@remix-run/server-runtime" import { json } from "@remix-run/server-runtime" -import { getMissionHistory } from "~/data/missionInstances.server" +import { getMissionHistory } from "~/services/db/missionInstances.server" import { Table, @@ -11,7 +11,7 @@ import { TableHeader, TableRow, } from "~/components/ui/table" -import { cn } from "~/lib/utils" +import { cn } from "~/utils/cn" import type { ReactNode } from "react" import { CircumstanceTemplates, diff --git a/app/services/auth.server.ts b/app/services/auth.server.ts index 9f68e9c..dec1a88 100644 --- a/app/services/auth.server.ts +++ b/app/services/auth.server.ts @@ -1,7 +1,7 @@ import { Authenticator } from "remix-auth" import { SteamStrategy } from "remix-auth-steam" import { sessionStorage } from "~/services/session.server" -import { getOrCreateSteamUser } from "~/data/user.server" +import { getOrCreateSteamUser } from "~/services/db/user.server" let domain = process.env.NODE_ENV === "production" diff --git a/app/data/authtoken.server.ts b/app/services/db/authtoken.server.ts similarity index 96% rename from app/data/authtoken.server.ts rename to app/services/db/authtoken.server.ts index 1ddc952..d773f67 100644 --- a/app/data/authtoken.server.ts +++ b/app/services/db/authtoken.server.ts @@ -1,7 +1,7 @@ import type { AuthToken } from "@prisma/client" import memoizee from "memoizee" import { json } from "@remix-run/node" -import { prisma } from "~/data/db.server" +import { prisma } from "~/services/prisma.server" type UpdateArgs = Omit export async function updateAuthToken(payload: UpdateArgs) { diff --git a/app/data/gameplaySessions.server.ts b/app/services/db/gameplaySessions.server.ts similarity index 56% rename from app/data/gameplaySessions.server.ts rename to app/services/db/gameplaySessions.server.ts index 0105907..267d3fd 100644 --- a/app/data/gameplaySessions.server.ts +++ b/app/services/db/gameplaySessions.server.ts @@ -1,5 +1,5 @@ import type { GameplaySession } from "@prisma/client" -import { prisma } from "~/data/db.server" +import { prisma } from "~/services/prisma.server" export async function saveGameplaySession( session: Omit, @@ -22,3 +22,22 @@ export async function getGameplaySessions({ orderBy: [{ createdAt: "desc" }], }) } + +export async function getGameplaySession({ + accountId, + characterId, + sessionId, +}: { + accountId: string + characterId: string + sessionId: string +}) { + return await prisma.gameplaySession.findFirstOrThrow({ + where: { + accountId, + characterId, + sessionId, + }, + orderBy: [{ createdAt: "desc" }], + }) +} diff --git a/app/data/missionInstances.server.ts b/app/services/db/missionInstances.server.ts similarity index 90% rename from app/data/missionInstances.server.ts rename to app/services/db/missionInstances.server.ts index cffd135..9cfe042 100644 --- a/app/data/missionInstances.server.ts +++ b/app/services/db/missionInstances.server.ts @@ -1,5 +1,5 @@ import type { MissionInstance } from "@prisma/client" -import { prisma } from "~/data/db.server" +import { prisma } from "~/services/prisma.server" export async function getMissionHistory() { let dayAgo = Date.now() - 24 * 60 * 60 * 1000 diff --git a/app/data/ownedTraits.server.ts b/app/services/db/ownedTraits.server.ts similarity index 95% rename from app/data/ownedTraits.server.ts rename to app/services/db/ownedTraits.server.ts index 675f3a2..8343ac3 100644 --- a/app/data/ownedTraits.server.ts +++ b/app/services/db/ownedTraits.server.ts @@ -1,4 +1,4 @@ -import { prisma } from "~/data/db.server" +import { prisma } from "~/services/prisma.server" import { z } from "zod" let OwnedTraitsSchema = z.array( diff --git a/app/data/user.server.ts b/app/services/db/user.server.ts similarity index 91% rename from app/data/user.server.ts rename to app/services/db/user.server.ts index ab831ac..a8d1e21 100644 --- a/app/data/user.server.ts +++ b/app/services/db/user.server.ts @@ -1,4 +1,4 @@ -import { prisma } from "~/data/db.server" +import { prisma } from "~/services/prisma.server" import { nanoid } from "~/utils/nanoid" export async function getUserBySteamId(steamId: string) { diff --git a/app/data/db.server.ts b/app/services/prisma.server.ts similarity index 100% rename from app/data/db.server.ts rename to app/services/prisma.server.ts diff --git a/app/lib/utils.ts b/app/utils/cn.ts similarity index 100% rename from app/lib/utils.ts rename to app/utils/cn.ts diff --git a/components.json b/components.json index c5e49ca..63c664f 100644 --- a/components.json +++ b/components.json @@ -1,16 +1,16 @@ { - "$schema": "https://ui.shadcn.com/schema.json", - "style": "default", - "rsc": false, - "tsx": true, - "tailwind": { - "config": "tailwind.config.js", - "css": "app/tailwind.css", - "baseColor": "zinc", - "cssVariables": true - }, - "aliases": { - "components": "app/components", - "utils": "app/lib/utils" - } -} \ No newline at end of file + "$schema": "https://ui.shadcn.com/schema.json", + "style": "default", + "rsc": false, + "tsx": true, + "tailwind": { + "config": "tailwind.config.js", + "css": "app/tailwind.css", + "baseColor": "zinc", + "cssVariables": true + }, + "aliases": { + "components": "app/components", + "utils": "app/utils/cn" + } +} diff --git a/darktide.yml b/darktide.yml index 632a03d..8c86c05 100644 --- a/darktide.yml +++ b/darktide.yml @@ -26,6 +26,10 @@ globals: cjson.decode: args: - type: string + string.split: + args: + - type: string + - type: string string.starts_with: args: - type: string