Skip to content

Commit

Permalink
feat(sidebar): active character outline
Browse files Browse the repository at this point in the history
  • Loading branch information
kwaa committed Jan 28, 2025
1 parent cef0d64 commit 8b9c43f
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/components/sidebar.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Icon } from '@iconify/react'
import { Avatar, Box, Flex, IconButton, ScrollArea, Tooltip } from '@radix-ui/themes'
import { useEffect, useState } from 'react'
import { useMatch } from 'react-router-dom'
import { v7 } from 'uuid'

import { db } from '../db'
Expand All @@ -13,6 +14,7 @@ import { SidebarNewCharacter } from './sidebar-new-character'
export const Sidebar = () => {
const [characters, setCharacters] = useState<typeof charactersTable.$inferSelect[]>([])
const [updateCharacters, setUpdateCharacters] = useState(0)
const match = useMatch('/room/:uuid')

const handleSelect = async (e: FileList | null) => {
if (!e)
Expand Down Expand Up @@ -51,6 +53,16 @@ export const Sidebar = () => {
// return () => setUpdateCharacters(false)
}, [updateCharacters])

const isActive = (uuid: string) =>
match?.params.uuid === uuid
? {
outlineColor: 'var(--accent-7)',
outlineOffset: 2,
outlineStyle: 'solid',
outlineWidth: 2,
}
: {}

return (
<Box display={{ initial: 'none', md: 'block' }}>
<Box
Expand All @@ -73,8 +85,8 @@ export const Sidebar = () => {
{characters.map(character => (
<Tooltip content={character.name} key={character.id} side="right">
<Link params={{ uuid: character.id }} to="/room/:uuid" viewTransition>
<IconButton asChild>
<Avatar color="gray" fallback={character.name.slice(0, 2)} size="4" src={character.avatar ?? undefined} />
<IconButton asChild style={isActive(character.id)}>
<Avatar fallback={character.name.slice(0, 2)} size="4" src={character.avatar ?? undefined} />
</IconButton>
</Link>
</Tooltip>
Expand Down

0 comments on commit 8b9c43f

Please sign in to comment.