ui(sharing): redesign share dialog with clearer structure + affordances
Target is now anchored in a chip at the top instead of a floating line. Existing shares and the add-user form are split into labeled sections with states for loading / empty. Each share row gets a hash-tinted initial avatar and a semantic permission pill (primary = edit, muted = view). The user picker is full-width with avatars in the dropdown, and permission becomes a segmented "Can view / Can edit" control alongside an icon-labeled Share button. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,16 @@
|
|||||||
import { useEffect, useMemo, useState } from 'react'
|
import { useEffect, useMemo, useState } from 'react'
|
||||||
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
|
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
|
||||||
import { Users, Trash2 } from 'lucide-react'
|
import {
|
||||||
|
Users,
|
||||||
|
Trash2,
|
||||||
|
Layers,
|
||||||
|
Folder,
|
||||||
|
Eye,
|
||||||
|
Pencil,
|
||||||
|
UserPlus,
|
||||||
|
Loader2,
|
||||||
|
} from 'lucide-react'
|
||||||
|
import { cn } from '@/lib/utils'
|
||||||
import {
|
import {
|
||||||
sharing,
|
sharing,
|
||||||
type ShareInfo,
|
type ShareInfo,
|
||||||
@@ -14,10 +24,12 @@ import {
|
|||||||
import {
|
import {
|
||||||
Dialog,
|
Dialog,
|
||||||
DialogContent,
|
DialogContent,
|
||||||
|
DialogDescription,
|
||||||
DialogHeader,
|
DialogHeader,
|
||||||
DialogTitle,
|
DialogTitle,
|
||||||
} from '@/components/ui/dialog'
|
} from '@/components/ui/dialog'
|
||||||
import { Button } from '@/components/ui/button'
|
import { Button } from '@/components/ui/button'
|
||||||
|
import { Label } from '@/components/ui/label'
|
||||||
import {
|
import {
|
||||||
Select,
|
Select,
|
||||||
SelectContent,
|
SelectContent,
|
||||||
@@ -116,100 +128,164 @@ export function ShareDialog({
|
|||||||
}
|
}
|
||||||
}, [isOpen])
|
}, [isOpen])
|
||||||
|
|
||||||
|
const TypeIcon = type === 'heap' ? Layers : Folder
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Dialog open={isOpen} onOpenChange={(o) => !o && onClose()}>
|
<Dialog open={isOpen} onOpenChange={(o) => !o && onClose()}>
|
||||||
<DialogContent className="max-w-[420px]">
|
<DialogContent className="max-w-md">
|
||||||
<DialogHeader>
|
<DialogHeader>
|
||||||
<DialogTitle className="flex items-center gap-2">
|
<DialogTitle className="flex items-center gap-2">
|
||||||
<Users className="h-4 w-4 text-text-muted" />
|
<Users className="h-4 w-4 text-primary" />
|
||||||
Share {type === 'heap' ? 'heap' : 'folder'}
|
Share {type === 'heap' ? 'heap' : 'folder'}
|
||||||
</DialogTitle>
|
</DialogTitle>
|
||||||
|
<DialogDescription className="sr-only">
|
||||||
|
Manage who can access this {type}.
|
||||||
|
</DialogDescription>
|
||||||
</DialogHeader>
|
</DialogHeader>
|
||||||
|
|
||||||
<div className="text-sm text-text-muted">
|
{/* Target chip — gives the action a clear subject instead of a
|
||||||
Sharing <span className="font-medium text-text">{targetName}</span>
|
* bare "Sharing X" line floating under the title. */}
|
||||||
|
<div className="mt-1 flex items-center gap-2 rounded-md border border-border bg-surface-2 px-3 py-2">
|
||||||
|
<TypeIcon className="h-4 w-4 shrink-0 text-text-muted" />
|
||||||
|
<span className="truncate text-sm font-medium text-text">
|
||||||
|
{targetName}
|
||||||
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Existing shares */}
|
{/* People with access ────────────────────────────────────────── */}
|
||||||
{shares.length > 0 && (
|
<section className="space-y-2">
|
||||||
<div className="space-y-1.5">
|
<div className="flex items-center justify-between">
|
||||||
{shares.map((share) => (
|
<Label>People with access</Label>
|
||||||
<div
|
{shares.length > 0 && (
|
||||||
key={share.id}
|
<span className="text-[11px] text-text-faint">
|
||||||
className="flex items-center justify-between rounded border border-border bg-surface-2 px-3 py-1.5 text-sm"
|
{shares.length} {shares.length === 1 ? 'person' : 'people'}
|
||||||
>
|
</span>
|
||||||
<div className="flex items-center gap-2">
|
)}
|
||||||
<span className="font-medium text-text">
|
|
||||||
{share.shared_with_username}
|
|
||||||
</span>
|
|
||||||
<span className="rounded bg-surface px-1.5 py-0.5 text-[10px] font-medium uppercase text-text-muted">
|
|
||||||
{share.permission}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<Button
|
|
||||||
variant="ghost"
|
|
||||||
size="icon"
|
|
||||||
onClick={() => revokeMutation.mutate(share.id)}
|
|
||||||
className="h-6 w-6 text-text-muted hover:text-reject"
|
|
||||||
title="Revoke access"
|
|
||||||
>
|
|
||||||
<Trash2 className="h-3.5 w-3.5" />
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
))}
|
|
||||||
</div>
|
</div>
|
||||||
)}
|
|
||||||
{isLoading && (
|
|
||||||
<div className="text-xs text-text-muted">Loading shares...</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
|
{isLoading ? (
|
||||||
|
<div className="flex items-center gap-2 rounded-md border border-dashed border-border px-3 py-3 text-xs text-text-muted">
|
||||||
|
<Loader2 className="h-3.5 w-3.5 animate-spin" />
|
||||||
|
Loading shares…
|
||||||
|
</div>
|
||||||
|
) : shares.length === 0 ? (
|
||||||
|
<div className="rounded-md border border-dashed border-border px-3 py-3 text-center text-xs text-text-muted">
|
||||||
|
Only you can see this {type}. Add people below to share it.
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<ul className="divide-y divide-border overflow-hidden rounded-md border border-border bg-surface-2">
|
||||||
|
{shares.map((share) => (
|
||||||
|
<li
|
||||||
|
key={share.id}
|
||||||
|
className="flex items-center justify-between gap-2 px-3 py-2"
|
||||||
|
>
|
||||||
|
<div className="flex min-w-0 items-center gap-2.5">
|
||||||
|
<Avatar name={share.shared_with_username} />
|
||||||
|
<span className="truncate text-sm font-medium text-text">
|
||||||
|
{share.shared_with_username}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center gap-1">
|
||||||
|
<PermissionPill permission={share.permission} />
|
||||||
|
<Button
|
||||||
|
variant="ghost"
|
||||||
|
size="icon"
|
||||||
|
onClick={() => revokeMutation.mutate(share.id)}
|
||||||
|
disabled={revokeMutation.isPending}
|
||||||
|
className="h-7 w-7 text-text-muted hover:bg-reject/10 hover:text-reject"
|
||||||
|
title="Revoke access"
|
||||||
|
>
|
||||||
|
<Trash2 className="h-3.5 w-3.5" />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</li>
|
||||||
|
))}
|
||||||
|
</ul>
|
||||||
|
)}
|
||||||
|
</section>
|
||||||
|
|
||||||
|
{/* Add people ────────────────────────────────────────────────── */}
|
||||||
<form
|
<form
|
||||||
onSubmit={(e) => {
|
onSubmit={(e) => {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
if (username.trim()) addMutation.mutate()
|
if (username.trim()) addMutation.mutate()
|
||||||
}}
|
}}
|
||||||
className="space-y-3"
|
className="space-y-2"
|
||||||
>
|
>
|
||||||
<div className="flex gap-2">
|
<Label htmlFor="share-user">Add people</Label>
|
||||||
<Select
|
|
||||||
value={username}
|
<Select
|
||||||
onValueChange={(v) => {
|
value={username}
|
||||||
setUsername(v)
|
onValueChange={(v) => {
|
||||||
setError(null)
|
setUsername(v)
|
||||||
}}
|
setError(null)
|
||||||
disabled={isLoadingUsers || availableUsers.length === 0}
|
}}
|
||||||
>
|
disabled={isLoadingUsers || availableUsers.length === 0}
|
||||||
<SelectTrigger className="flex-1">
|
>
|
||||||
<SelectValue
|
<SelectTrigger id="share-user" className="w-full">
|
||||||
placeholder={
|
<SelectValue
|
||||||
isLoadingUsers
|
placeholder={
|
||||||
? 'Loading users…'
|
isLoadingUsers
|
||||||
: availableUsers.length === 0
|
? 'Loading users…'
|
||||||
? 'No users to share with'
|
: availableUsers.length === 0
|
||||||
: 'Select a user'
|
? 'No users to share with'
|
||||||
}
|
: 'Select a user'
|
||||||
/>
|
}
|
||||||
</SelectTrigger>
|
/>
|
||||||
<SelectContent>
|
</SelectTrigger>
|
||||||
{availableUsers.map((u) => (
|
<SelectContent>
|
||||||
<SelectItem key={u.id} value={u.username}>
|
{availableUsers.map((u) => (
|
||||||
|
<SelectItem key={u.id} value={u.username}>
|
||||||
|
<span className="flex items-center gap-2">
|
||||||
|
<Avatar name={u.username} size="sm" />
|
||||||
{u.username}
|
{u.username}
|
||||||
</SelectItem>
|
</span>
|
||||||
))}
|
</SelectItem>
|
||||||
</SelectContent>
|
))}
|
||||||
</Select>
|
</SelectContent>
|
||||||
<Select
|
</Select>
|
||||||
value={permission}
|
|
||||||
onValueChange={(v) => setPermission(v as 'read' | 'write')}
|
{/* Permission picker — segmented control style so the two
|
||||||
|
* options are visible at once and the difference between
|
||||||
|
* "view" and "edit" is obvious without opening a dropdown. */}
|
||||||
|
<div className="flex items-center justify-between gap-2 pt-1">
|
||||||
|
<div
|
||||||
|
role="radiogroup"
|
||||||
|
aria-label="Permission"
|
||||||
|
className="inline-flex overflow-hidden rounded-md border border-border bg-surface-2 p-0.5"
|
||||||
>
|
>
|
||||||
<SelectTrigger className="w-auto">
|
<PermissionOption
|
||||||
<SelectValue />
|
icon={Eye}
|
||||||
</SelectTrigger>
|
label="Can view"
|
||||||
<SelectContent>
|
value="read"
|
||||||
<SelectItem value="read">Read</SelectItem>
|
current={permission}
|
||||||
<SelectItem value="write">Read + Write</SelectItem>
|
onSelect={setPermission}
|
||||||
</SelectContent>
|
/>
|
||||||
</Select>
|
<PermissionOption
|
||||||
|
icon={Pencil}
|
||||||
|
label="Can edit"
|
||||||
|
value="write"
|
||||||
|
current={permission}
|
||||||
|
onSelect={setPermission}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<Button
|
||||||
|
type="submit"
|
||||||
|
size="sm"
|
||||||
|
disabled={!username.trim() || addMutation.isPending}
|
||||||
|
>
|
||||||
|
{addMutation.isPending ? (
|
||||||
|
<>
|
||||||
|
<Loader2 className="mr-1.5 h-3.5 w-3.5 animate-spin" />
|
||||||
|
Sharing…
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<UserPlus className="mr-1.5 h-3.5 w-3.5" />
|
||||||
|
Share
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{error && (
|
{error && (
|
||||||
@@ -217,17 +293,93 @@ export function ShareDialog({
|
|||||||
<AlertDescription>{error}</AlertDescription>
|
<AlertDescription>{error}</AlertDescription>
|
||||||
</Alert>
|
</Alert>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<div className="flex justify-end">
|
|
||||||
<Button
|
|
||||||
type="submit"
|
|
||||||
disabled={!username.trim() || addMutation.isPending}
|
|
||||||
>
|
|
||||||
{addMutation.isPending ? 'Sharing...' : 'Share'}
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
</form>
|
</form>
|
||||||
</DialogContent>
|
</DialogContent>
|
||||||
</Dialog>
|
</Dialog>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ── Helpers ────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
/** Circular initial bubble. Hashes the username into one of a small set
|
||||||
|
* of stable palette tints so each person's avatar reads consistently
|
||||||
|
* across the app — the colour isn't meaningful, it's just an identity
|
||||||
|
* cue to make a list of names feel less anonymous. */
|
||||||
|
function Avatar({ name, size = 'md' }: { name: string; size?: 'sm' | 'md' }) {
|
||||||
|
const initials = name.slice(0, 2).toUpperCase()
|
||||||
|
const palette = [
|
||||||
|
'bg-primary/25 text-primary',
|
||||||
|
'bg-pick/25 text-pick',
|
||||||
|
'bg-blue-500/25 text-blue-300',
|
||||||
|
'bg-purple-500/25 text-purple-300',
|
||||||
|
'bg-amber-500/25 text-amber-300',
|
||||||
|
]
|
||||||
|
let hash = 0
|
||||||
|
for (let i = 0; i < name.length; i++) hash = (hash * 31 + name.charCodeAt(i)) | 0
|
||||||
|
const tint = palette[Math.abs(hash) % palette.length]
|
||||||
|
const dims = size === 'sm' ? 'h-5 w-5 text-[9px]' : 'h-7 w-7 text-[11px]'
|
||||||
|
return (
|
||||||
|
<span
|
||||||
|
className={cn(
|
||||||
|
'inline-flex shrink-0 items-center justify-center rounded-full font-semibold uppercase tracking-wide',
|
||||||
|
dims,
|
||||||
|
tint
|
||||||
|
)}
|
||||||
|
aria-hidden
|
||||||
|
>
|
||||||
|
{initials}
|
||||||
|
</span>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function PermissionPill({ permission }: { permission: string }) {
|
||||||
|
const isWrite = permission === 'write'
|
||||||
|
const Icon = isWrite ? Pencil : Eye
|
||||||
|
return (
|
||||||
|
<span
|
||||||
|
className={cn(
|
||||||
|
'inline-flex items-center gap-1 rounded-sm px-1.5 py-0.5 text-[10px] font-semibold uppercase tracking-wide',
|
||||||
|
isWrite
|
||||||
|
? 'bg-primary/15 text-primary'
|
||||||
|
: 'bg-surface-offset text-text-muted'
|
||||||
|
)}
|
||||||
|
title={isWrite ? 'Read + Write' : 'Read-only'}
|
||||||
|
>
|
||||||
|
<Icon className="h-2.5 w-2.5" />
|
||||||
|
{isWrite ? 'Edit' : 'View'}
|
||||||
|
</span>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function PermissionOption({
|
||||||
|
icon: Icon,
|
||||||
|
label,
|
||||||
|
value,
|
||||||
|
current,
|
||||||
|
onSelect,
|
||||||
|
}: {
|
||||||
|
icon: typeof Eye
|
||||||
|
label: string
|
||||||
|
value: 'read' | 'write'
|
||||||
|
current: 'read' | 'write'
|
||||||
|
onSelect: (v: 'read' | 'write') => void
|
||||||
|
}) {
|
||||||
|
const active = current === value
|
||||||
|
return (
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
role="radio"
|
||||||
|
aria-checked={active}
|
||||||
|
onClick={() => onSelect(value)}
|
||||||
|
className={cn(
|
||||||
|
'inline-flex items-center gap-1.5 rounded px-2.5 py-1 text-xs font-medium transition-colors',
|
||||||
|
active
|
||||||
|
? 'bg-primary/20 text-primary shadow-[inset_0_0_0_1px_rgba(232,150,90,0.35)]'
|
||||||
|
: 'text-text-muted hover:text-text'
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
<Icon className="h-3 w-3" />
|
||||||
|
{label}
|
||||||
|
</button>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user