Skip to content

Commit

Permalink
style: run prettier format
Browse files Browse the repository at this point in the history
  • Loading branch information
rmrt1n committed Mar 4, 2024
1 parent cb1794b commit 8e0d915
Show file tree
Hide file tree
Showing 37 changed files with 529 additions and 541 deletions.
13 changes: 5 additions & 8 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,9 @@ module.exports = {
parser: '@typescript-eslint/parser',
plugins: ['react-refresh'],
rules: {
'react-refresh/only-export-components': [
'warn',
{ allowConstantExport: true },
],
'react-refresh/only-export-components': ['warn', { allowConstantExport: true }],
'react/no-unescaped-entities': 0,
'@typescript-eslint/no-explicit-any': 0
'@typescript-eslint/no-explicit-any': 0,
},
parserOptions: {
ecmaVersion: 'latest',
Expand All @@ -27,7 +24,7 @@ module.exports = {
},
settings: {
react: {
version: 'detect'
}
}
version: 'detect',
},
},
}
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# Cardinal Editor

tba...

## Development

```shell
git clone https://github.com/Argus-Labs/cardinal-editor
cd cardinal-editor
Expand Down
2 changes: 1 addition & 1 deletion components.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
"components": "@/components",
"utils": "@/lib/utils"
}
}
}
14 changes: 10 additions & 4 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,16 @@
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<!-- TODO: change to Argus' brand font (Beausite Classic Web) -->
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;500;700&display=swap" rel="stylesheet">
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link
href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap"
rel="stylesheet"
/>
<link
href="https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;500;700&display=swap"
rel="stylesheet"
/>
<title>Cardinal Editor</title>
</head>
<body>
Expand Down
15 changes: 8 additions & 7 deletions src/components/bottom-bar.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { useEffect, useRef, useState } from 'react';
import { ImperativePanelHandle } from 'react-resizable-panels';
import { ResizablePanel } from './ui/resizable';
import { Button } from './ui/button';
import { ChevronsDown, ChevronsUp } from 'lucide-react';
import { useQuery } from '@tanstack/react-query';
import { useQuery } from '@tanstack/react-query'
import { ChevronsDown, ChevronsUp } from 'lucide-react'
import { useEffect, useRef, useState } from 'react'
import { ImperativePanelHandle } from 'react-resizable-panels'

import { Button } from '@/components/ui/button'
import { ResizablePanel } from '@/components/ui/resizable'

export function BottomBar() {
const ref = useRef<ImperativePanelHandle>(null);
const ref = useRef<ImperativePanelHandle>(null)
const [collapsed, setCollapsed] = useState(true)
const { data } = useQuery({ queryKey: ['last-query'], initialData: null })

Expand Down
87 changes: 54 additions & 33 deletions src/components/entity-group-sheets.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,49 @@
import { useState } from 'react';
import { useQuery } from '@tanstack/react-query';
import { Edit } from 'lucide-react';
import { useQuery } from '@tanstack/react-query'
import { Edit } from 'lucide-react'
import { useState } from 'react'

import { Sheet, SheetClose, SheetContent, SheetDescription, SheetFooter, SheetHeader, SheetTitle, SheetTrigger } from '@/components/ui/sheet';
import { Button } from '@/components/ui/button';
import { Label } from '@/components/ui/label';
import { Input } from '@/components/ui/input';
import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from '@/components/ui/accordion';
import { Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger } from '@/components/ui/dialog';
import { useToast } from '@/components/ui/use-toast';
import { MultiSelect } from '@/components/multi-select';
import { EntityCard } from '@/components/entity-views';
import { Entity } from '@/lib/types';
import { useCardinal } from '@/lib/cardinal-provider';
import { worldQueryOptions } from '@/lib/query-options';
import { useConfig } from '@/lib/config-provider';
import { EntityCard } from '@/components/entity-views'
import { MultiSelect } from '@/components/multi-select'
import {
Accordion,
AccordionContent,
AccordionItem,
AccordionTrigger,
} from '@/components/ui/accordion'
import { Button } from '@/components/ui/button'
import {
Dialog,
DialogClose,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
DialogTrigger,
} from '@/components/ui/dialog'
import { Input } from '@/components/ui/input'
import { Label } from '@/components/ui/label'
import {
Sheet,
SheetClose,
SheetContent,
SheetDescription,
SheetFooter,
SheetHeader,
SheetTitle,
SheetTrigger,
} from '@/components/ui/sheet'
import { useToast } from '@/components/ui/use-toast'
import { useCardinal } from '@/lib/cardinal-provider'
import { useConfig } from '@/lib/config-provider'
import { worldQueryOptions } from '@/lib/query-options'
import { Entity } from '@/lib/types'

// TODO: update this when registered components endpoint is done
const sampleEntity = (components: string[]): Entity => {
return {
id: 0,
components: components.reduce((acc, c) => ({ ...acc, [c]: { attribute: 'dummy data' } }), {})
components: components.reduce((acc, c) => ({ ...acc, [c]: { attribute: 'dummy data' } }), {}),
}
}

Expand All @@ -37,7 +60,7 @@ export function NewEntityGroupSheet() {

const components = data?.components.map((c) => ({ label: c, value: c })) ?? []
const hasSelectedComponents = selected && selected.length > 0
const accordionValue = hasSelectedComponents ? "default" : ""
const accordionValue = hasSelectedComponents ? 'default' : ''

const handleClick = (e: React.MouseEvent<HTMLElement>) => {
if (entityGroupName.length === 0) {
Expand All @@ -56,11 +79,11 @@ export function NewEntityGroupSheet() {
}
const newEntityGroup = {
name: entityGroupName,
components: selected
components: selected,
}
setConfig({ ...config, entityGroups: [...config.entityGroups, newEntityGroup] })
toast({
title: 'Successfully created entity group'
title: 'Successfully created entity group',
})
}

Expand Down Expand Up @@ -104,9 +127,7 @@ export function NewEntityGroupSheet() {
<AccordionItem value="default" className="border-0 space-y-2">
<AccordionTrigger className="py-2 text-sm">Sample entities</AccordionTrigger>
<AccordionContent>
{hasSelectedComponents && (
<EntityCard entity={sampleEntity(selected)} />
)}
{hasSelectedComponents && <EntityCard entity={sampleEntity(selected)} />}
</AccordionContent>
</AccordionItem>
</Accordion>
Expand All @@ -125,8 +146,8 @@ export function NewEntityGroupSheet() {

interface EditEntityGroupProps {
entityGroup: {
name: string,
components: string[],
name: string
components: string[]
}
}

Expand All @@ -143,7 +164,7 @@ export function EditEntityGroupSheet({ entityGroup }: EditEntityGroupProps) {

const components = data?.components.map((c) => ({ label: c, value: c })) ?? []
const hasSelectedComponents = selected && selected.length > 0
const accordionValue = hasSelectedComponents ? "default" : ""
const accordionValue = hasSelectedComponents ? 'default' : ''

const handleEdit = (e: React.MouseEvent<HTMLElement>) => {
if (entityGroupName.length === 0) {
Expand All @@ -164,20 +185,20 @@ export function EditEntityGroupSheet({ entityGroup }: EditEntityGroupProps) {
if (eg.name !== entityGroup.name) return eg
return {
name: entityGroupName,
components: selected
components: selected,
}
})
setConfig({ ...config, entityGroups: newEntityGroups })
toast({
title: 'Successfully updated entity group'
title: 'Successfully updated entity group',
})
}
const handleDelete = () => {
const newEntityGroups = config.entityGroups.filter((eg) => eg.name !== entityGroupName)
setConfig({ ...config, entityGroups: newEntityGroups })
setOpen(false)
toast({
title: 'Successfully deleted entity group'
title: 'Successfully deleted entity group',
})
}

Expand Down Expand Up @@ -219,9 +240,7 @@ export function EditEntityGroupSheet({ entityGroup }: EditEntityGroupProps) {
<AccordionItem value="default" className="border-0 space-y-2">
<AccordionTrigger className="py-2 text-sm">Sample entities</AccordionTrigger>
<AccordionContent>
{hasSelectedComponents && (
<EntityCard entity={sampleEntity(selected)} />
)}
{hasSelectedComponents && <EntityCard entity={sampleEntity(selected)} />}
</AccordionContent>
</AccordionItem>
</Accordion>
Expand All @@ -245,7 +264,9 @@ export function EditEntityGroupSheet({ entityGroup }: EditEntityGroupProps) {
<Button variant="outline">Cancel</Button>
</DialogClose>
<DialogClose asChild>
<Button variant="destructive" onClick={handleDelete}>Delete</Button>
<Button variant="destructive" onClick={handleDelete}>
Delete
</Button>
</DialogClose>
</DialogFooter>
</DialogContent>
Expand Down
31 changes: 18 additions & 13 deletions src/components/entity-views.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from "@/components/ui/accordion"
import { Entity } from "@/lib/types"
import {
Accordion,
AccordionContent,
AccordionItem,
AccordionTrigger,
} from '@/components/ui/accordion'
import { Entity } from '@/lib/types'

interface EntityCardsListProps {
entities: Entity[]
Expand All @@ -25,9 +30,7 @@ export function EntityCard({ entity }: EntityCardProps) {
return (
<>
<div className="3xl:min-w-96 bg-background border border-border rounded-lg font-mono text-sm">
<div className="px-3 py-2 font-bold border-b border-border">
Entity {entity.id}
</div>
<div className="px-3 py-2 font-bold border-b border-border">Entity {entity.id}</div>
<div className="px-3 py-2 space-y-2">
{Object.keys(entity.components).map((name) => (
<ComponentDetails key={name} name={name} component={entity.components[name]} />
Expand All @@ -44,9 +47,7 @@ export function EntityList({ entities }: EntityCardsListProps) {
<Accordion type="multiple" className="font-mono space-y-1">
{entities.map((entity) => (
<AccordionItem key={entity.id} value={entity.id.toString()} className="border-0">
<AccordionTrigger
className="px-3 py-2 border border-border rounded-lg data-[state=open]:rounded-b-none bg-background font-bold text-sm"
>
<AccordionTrigger className="px-3 py-2 border border-border rounded-lg data-[state=open]:rounded-b-none bg-background font-bold text-sm">
Entity {entity.id}
</AccordionTrigger>
<AccordionContent
Expand All @@ -72,15 +73,19 @@ interface ComponentDetailsProps {
// TODO: add case for object types (arrays are included as objects too)
const formatAttribute = (attr: any): React.ReactNode => {
switch (typeof attr) {
case 'string': return <span className="text-green-500">{`"${attr}"`}</span>
case 'number': return <span className="text-orange-500">{attr}</span>
case 'boolean': return <span className="text-blue-500">{attr}</span>
default: return <span>{attr}</span>
case 'string':
return <span className="text-green-500">{`"${attr}"`}</span>
case 'number':
return <span className="text-orange-500">{attr}</span>
case 'boolean':
return <span className="text-blue-500">{attr}</span>
default:
return <span>{attr}</span>
}
}

function ComponentDetails({ name, component }: ComponentDetailsProps) {
const attributes = Object.keys(component).filter((k) => !k.startsWith("_"))
const attributes = Object.keys(component).filter((k) => !k.startsWith('_'))

return (
// 0.8125rem / 13px since the default sizes are too small/big
Expand Down
Loading

0 comments on commit 8e0d915

Please sign in to comment.