Skip to content

Commit

Permalink
virtual relations + ui improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
velascoandres committed Mar 22, 2024
1 parent fe1e982 commit 5a2a749
Show file tree
Hide file tree
Showing 16 changed files with 275 additions and 43 deletions.
Binary file modified bun.lockb
Binary file not shown.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"@radix-ui/react-dialog": "^1.0.5",
"@radix-ui/react-dropdown-menu": "^2.0.6",
"@radix-ui/react-label": "^2.0.2",
"@radix-ui/react-navigation-menu": "^1.1.4",
"@radix-ui/react-select": "^2.0.0",
"@radix-ui/react-slot": "^1.0.2",
"@radix-ui/react-switch": "^1.0.3",
Expand Down
6 changes: 3 additions & 3 deletions src/app/_auth/components/profile-menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ export const ProfileMenu = () => {
</Avatar>
</DropdownMenuTrigger>
<DropdownMenuContent>
<DropdownMenuLabel>{data.user.name}</DropdownMenuLabel>
<DropdownMenuLabel className="text-sm">{data.user.name}</DropdownMenuLabel>
<DropdownMenuSeparator />
<DropdownMenuItem
className="cursor-pointer"
className="cursor-pointer text-sm"
onClick={() => signOut({ callbackUrl: '/' })}
>
Sign out
Sign out
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
Expand Down
129 changes: 129 additions & 0 deletions src/app/_shared/components/ui/navigation-menu.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
import * as React from 'react'
import { cva } from 'class-variance-authority'
import { ChevronDown } from 'lucide-react'

import * as NavigationMenuPrimitive from '@radix-ui/react-navigation-menu'

import { cn } from '@/lib/utils'

const NavigationMenu = React.forwardRef<
React.ElementRef<typeof NavigationMenuPrimitive.Root>,
React.ComponentPropsWithoutRef<typeof NavigationMenuPrimitive.Root>
>(({ className, children, ...props }, ref) => (
<NavigationMenuPrimitive.Root
ref={ref}
className={cn(
'relative z-10 flex max-w-max flex-1 items-center justify-center',
className
)}
{...props}
>
{children}
<NavigationMenuViewport />
</NavigationMenuPrimitive.Root>
))
NavigationMenu.displayName = NavigationMenuPrimitive.Root.displayName

const NavigationMenuList = React.forwardRef<
React.ElementRef<typeof NavigationMenuPrimitive.List>,
React.ComponentPropsWithoutRef<typeof NavigationMenuPrimitive.List>
>(({ className, ...props }, ref) => (
<NavigationMenuPrimitive.List
ref={ref}
className={cn(
'group flex flex-1 list-none items-center justify-center space-x-1',
className
)}
{...props}
/>
))
NavigationMenuList.displayName = NavigationMenuPrimitive.List.displayName

const NavigationMenuItem = NavigationMenuPrimitive.Item

const navigationMenuTriggerStyle = cva(
'group inline-flex h-10 w-max items-center justify-center rounded-md bg-background px-4 py-2 text-sm font-medium transition-colors hover:bg-accent hover:text-accent-foreground focus:bg-accent focus:text-accent-foreground focus:outline-none disabled:pointer-events-none disabled:opacity-50 data-[active]:bg-accent/50 data-[state=open]:bg-accent/50'
)

const NavigationMenuTrigger = React.forwardRef<
React.ElementRef<typeof NavigationMenuPrimitive.Trigger>,
React.ComponentPropsWithoutRef<typeof NavigationMenuPrimitive.Trigger>
>(({ className, children, ...props }, ref) => (
<NavigationMenuPrimitive.Trigger
ref={ref}
className={cn(navigationMenuTriggerStyle(), 'group', className)}
{...props}
>
{children}{' '}
<ChevronDown
className="relative top-[1px] ml-1 h-5 w-5 transition duration-200 group-data-[state=open]:rotate-180"
aria-hidden="true"
/>
</NavigationMenuPrimitive.Trigger>
))
NavigationMenuTrigger.displayName = NavigationMenuPrimitive.Trigger.displayName

const NavigationMenuContent = React.forwardRef<
React.ElementRef<typeof NavigationMenuPrimitive.Content>,
React.ComponentPropsWithoutRef<typeof NavigationMenuPrimitive.Content>
>(({ className, ...props }, ref) => (
<NavigationMenuPrimitive.Content
ref={ref}
className={cn(
'left-0 top-0 w-full data-[motion^=from-]:animate-in data-[motion^=to-]:animate-out data-[motion^=from-]:fade-in data-[motion^=to-]:fade-out data-[motion=from-end]:slide-in-from-right-52 data-[motion=from-start]:slide-in-from-left-52 data-[motion=to-end]:slide-out-to-right-52 data-[motion=to-start]:slide-out-to-left-52 md:absolute md:w-auto ',
className
)}
{...props}
/>
))
NavigationMenuContent.displayName = NavigationMenuPrimitive.Content.displayName

const NavigationMenuLink = NavigationMenuPrimitive.Link

const NavigationMenuViewport = React.forwardRef<
React.ElementRef<typeof NavigationMenuPrimitive.Viewport>,
React.ComponentPropsWithoutRef<typeof NavigationMenuPrimitive.Viewport>
>(({ className, ...props }, ref) => (
<div className={cn('absolute left-0 top-full flex justify-center')}>
<NavigationMenuPrimitive.Viewport
className={cn(
'origin-top-center relative mt-1.5 h-[var(--radix-navigation-menu-viewport-height)] w-full overflow-hidden rounded-md border bg-popover text-popover-foreground shadow-lg data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-90 md:w-[var(--radix-navigation-menu-viewport-width)]',
className
)}
ref={ref}
{...props}
/>
</div>
))
NavigationMenuViewport.displayName =
NavigationMenuPrimitive.Viewport.displayName

const NavigationMenuIndicator = React.forwardRef<
React.ElementRef<typeof NavigationMenuPrimitive.Indicator>,
React.ComponentPropsWithoutRef<typeof NavigationMenuPrimitive.Indicator>
>(({ className, ...props }, ref) => (
<NavigationMenuPrimitive.Indicator
ref={ref}
className={cn(
'top-full z-[1] flex h-1.5 items-end justify-center overflow-hidden data-[state=visible]:animate-in data-[state=hidden]:animate-out data-[state=hidden]:fade-out data-[state=visible]:fade-in',
className
)}
{...props}
>
<div className="relative top-[60%] h-2 w-2 rotate-45 rounded-tl-sm bg-border shadow-md" />
</NavigationMenuPrimitive.Indicator>
))
NavigationMenuIndicator.displayName =
NavigationMenuPrimitive.Indicator.displayName

export {
navigationMenuTriggerStyle,
NavigationMenu,
NavigationMenuList,
NavigationMenuItem,
NavigationMenuContent,
NavigationMenuTrigger,
NavigationMenuLink,
NavigationMenuIndicator,
NavigationMenuViewport,
}
2 changes: 1 addition & 1 deletion src/app/_spaces/components/attach-space.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export const AttachWhiteboardSpace = ({
loading={isLoading}
fallback={<Skeleton className="h-[300px] w-full" />}
>
<div className="inline-flex gap-4 w-full">
<div className="flex flex-col md:flex-row gap-4 w-full">
<div className="basis-1/2 flex flex-col items-start gap-2">
<h3 className="ml-2 mt-2 font-semibold text-base self-start text-primary">Available whiteboards: </h3>
<ul className="list-none w-full p-2 overflow-y-auto max-h-[300px] border border-border rounded-md">
Expand Down
10 changes: 7 additions & 3 deletions src/app/_spaces/components/detach-space.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,15 @@ export const DetachWhiteboardSpace = ({
return (
<DialogContent>
<DialogHeader>
<DialogTitle className="text-xl">Detach: <strong className="text-primary" >{whiteboard.name}</strong></DialogTitle>
<DialogTitle className="text-lg">Detach: <strong className="text-primary" >{whiteboard.name}</strong></DialogTitle>
</DialogHeader>

<p className="px-2 font-semibold text-lg">
Are you sure to <strong className="text-red-500">detach</strong> the whiteboard from the space?
<p className="px-2 font-semibold">
Are you sure to <strong className="text-red-500">detach</strong> the whiteboard?
</p>

<p className="p-3 border rounded-sm text-sm bg-secondary">
the whiteboard will be detached from the space: <span className="text-indigo-400">&quot;{whiteboard.space?.name}&quot;</span>
</p>

<DialogFooter>
Expand Down
4 changes: 2 additions & 2 deletions src/app/_spaces/components/remove-space.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ export const RemoveSpace = ({
return (
<DialogContent>
<DialogHeader>
<DialogTitle className="text-xl">Delete: <strong className="text-primary-400" >{space.name}</strong></DialogTitle>
<DialogTitle className="text-lg">Delete: <strong className="text-primary-400" >{space.name}</strong></DialogTitle>
</DialogHeader>

<p className="px-2 font-semibold text-lg">
<p className="px-2 font-semibold">
Are you sure to <strong className="text-red-500">delete</strong> the space?
</p>

Expand Down
4 changes: 2 additions & 2 deletions src/app/_whiteboards/components/delete-whiteboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ export const DeleteWhiteboard = ({
return (
<DialogContent>
<DialogHeader>
<DialogTitle className="text-xl">Delete: <strong className="text-primary" >{whiteboard.name}</strong></DialogTitle>
<DialogTitle className="text-lg">Delete: <strong className="text-primary" >{whiteboard.name}</strong></DialogTitle>
</DialogHeader>

<p className="px-2 font-semibold text-lg">
<p className="px-2 font-semibold">
Are you sure to <strong className="text-red-500">delete</strong> the whiteboard?
</p>

Expand Down
8 changes: 4 additions & 4 deletions src/app/_whiteboards/components/whiteboard-card.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use client'

import Link from 'next/link'
import { FilePenLine, Link as LinkIcon,Split, Trash2 } from 'lucide-react'
import { ExternalLink,FilePenLine, Split, Trash2 } from 'lucide-react'

import {
ContextMenu,
Expand Down Expand Up @@ -65,8 +65,8 @@ export const WhiteboardCard = ({ whiteboard, children }: ListItemProps) => {

</div>
{
whiteboard.isPublic && <Link href={`${window.location.origin}/view-whiteboard/${whiteboard.id}`} className="absolute bottom-0 right-0 hover:underline self-end transition ease-in hover:border-primary bg-indigo-600 rounded-tl-sm px-4">
<span className="text-sm">Public</span>
whiteboard.isPublic && <Link target="_blank" href={`${window.location.origin}/view-whiteboard/${whiteboard.id}`} className="absolute bottom-0 right-0 hover:underline self-end transition ease-in hover:border-primary bg-[#63e] rounded-tl-sm px-4 flex items-center gap-1 py-1">
<ExternalLink className="h-4 w-4" /> <span className="text-sm">Public</span>
</Link>
}
</div>
Expand Down Expand Up @@ -111,7 +111,7 @@ export const WhiteboardActions = ({
onClick={() => handleCopyClipboard(`${window.location.origin}/view-whiteboard/${whiteboard.id}`)}
className="cursor-pointer flex justify-start gap-2"
>
<LinkIcon className="h-5 w-5" /> Copy public link
<ExternalLink className="h-5 w-5" /> Copy public link
</ContextMenuItem>
)
}
Expand Down
50 changes: 50 additions & 0 deletions src/app/_whiteboards/components/whiteboard-header.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
'use client'

import React from 'react'

import { Avatar, AvatarImage } from '@/app/_shared/components/ui/avatar'
import {
NavigationMenu,
NavigationMenuContent,
NavigationMenuItem,
NavigationMenuList,
NavigationMenuTrigger
} from '@/app/_shared/components/ui/navigation-menu'


interface Props {
title: string
description: string

creator: {
name: string
avatarUrl?: string
}
}


export const WhiteboardHeader = ({ title, description, creator }: Props) => {
return (
<NavigationMenu className="z-[2] px-3 py-2 rounded-md bg-background/70 backdrop-blur-sm fixed inline-flex justify-center items-center top-4 center-fixed gap-2 border border-border">
<NavigationMenuList className="gap-2">
<NavigationMenuItem>
<NavigationMenuTrigger className="bg-transparent">
{title}
</NavigationMenuTrigger>
<NavigationMenuContent className="min-w-[15rem] max-w-md px-3 py-4 text-sm">
{ description }
</NavigationMenuContent>
</NavigationMenuItem>
<NavigationMenuItem className="text-sm flex gap-2 justify-center items-center">
<Avatar>
<AvatarImage src={creator.avatarUrl} />
</Avatar>
<div className="flex flex-col gap-1 text-xs">
<span>{ creator.name}</span>
<span className="text-gray-400">Author </span>
</div>
</NavigationMenuItem>
</NavigationMenuList>
</NavigationMenu>
)
}
55 changes: 33 additions & 22 deletions src/app/_whiteboards/components/whiteboard-navigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,52 @@ import React from 'react'
import Link from 'next/link'
import { Group,Presentation } from 'lucide-react'

import { ProfileCard } from '@/app/_auth/components/profile-card'
import { ProfileMenu } from '@/app/_auth/components/profile-menu'
import {
NavigationMenu,
NavigationMenuItem,
NavigationMenuLink,
NavigationMenuList,
navigationMenuTriggerStyle
} from '@/app/_shared/components/ui/navigation-menu'

interface Props {
whiteboardName: string
description?: string
spaceId?: number | null
}


export const WhiteboardNavigation = ({ whiteboardName, spaceId }: Props) => {

return (
<nav className="z-[2] fixed inline-flex items-center justify-between bottom-16 md:bottom-4 right-[5%] left-[5%] md:right-[15%] md:left-[15%] lg:right-[30%] lg:left-[30%] bg-background rounded-full px-2 py-1 gap-2 border border-border">
<div className="inline-flex justify-start gap-2">
<Link href="/whiteboards" className="transition ease-in hover:text-secondary rounded-full p-2 hover:bg-secondary-foreground">
<Presentation />
</Link>

<NavigationMenu className="z-[2] fixed inline-flex items-center justify-between bottom-16 md:bottom-4 center-fixed bg-background rounded-md px-3 py-1 gap-2 border border-border">
<NavigationMenuList className="gap-2">
<NavigationMenuItem className="font-bold max-w-xs text-ellipsis">
{whiteboardName}
</NavigationMenuItem>
<NavigationMenuItem>
<Link href="/whiteboards">
<NavigationMenuLink className={navigationMenuTriggerStyle()}>
<Presentation />
</NavigationMenuLink>
</Link>
</NavigationMenuItem>
{
spaceId && (
<Link href={`/spaces/${spaceId}`} className="transition ease-in hover:text-secondary rounded-full p-2 hover:bg-secondary-foreground">
<Group />
</Link>
<NavigationMenuItem>
<Link href={`/spaces/${spaceId}`}>
<NavigationMenuLink className={navigationMenuTriggerStyle()}>
<Group />
</NavigationMenuLink>
</Link>
</NavigationMenuItem>
)
}
</div>

<h1 className="font-bold max-w-xs text-ellipsis">{whiteboardName}</h1>

<div className="hidden md:block">
<ProfileCard />
</div>
<div className="block md:hidden">
<ProfileMenu />
</div>
</nav>
}
<NavigationMenuItem className="pt-1">
<ProfileMenu />
</NavigationMenuItem>
</NavigationMenuList>
</NavigationMenu>
)
}
15 changes: 15 additions & 0 deletions src/app/_whiteboards/interfaces/whiteboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,19 @@ export interface Whiteboard {
isPublic: boolean
content: unknown
previewUrl?: string
}

export interface PublicWhiteboard {
id: number
name: string
description?: string
space?: Space
isPublic: boolean
content: unknown
previewUrl?: string
createdBy: {
id: number
name: string
image: string
}
}
Loading

0 comments on commit 5a2a749

Please sign in to comment.