Compare commits
2 Commits
211dbb72e0
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 3003066a5a | |||
| 4a485255b0 |
@@ -72,7 +72,7 @@ function AppSidebar() {
|
|||||||
<div className="flex items-center gap-3 rounded-md px-2 py-1.5">
|
<div className="flex items-center gap-3 rounded-md px-2 py-1.5">
|
||||||
<div className="flex flex-col leading-tight gap-2">
|
<div className="flex flex-col leading-tight gap-2">
|
||||||
<span className="text-xs text-muted-foreground">
|
<span className="text-xs text-muted-foreground">
|
||||||
{notes.length} note{notes.length !== 1 && "s"}
|
{notes.size || 0} note{notes.size !== 1 && "s"}
|
||||||
</span>
|
</span>
|
||||||
<div className="flex flex-row gap-2">
|
<div className="flex flex-row gap-2">
|
||||||
<div className="flex h-4 w-4 items-center justify-center rounded-full bg-foreground">
|
<div className="flex h-4 w-4 items-center justify-center rounded-full bg-foreground">
|
||||||
|
|||||||
@@ -5,10 +5,12 @@ import {
|
|||||||
useRef,
|
useRef,
|
||||||
useEffect,
|
useEffect,
|
||||||
} from "react"
|
} from "react"
|
||||||
import { FileText } from "lucide-react"
|
|
||||||
|
import { FileText, X } from "lucide-react"
|
||||||
import { Input } from "@/components/ui/input"
|
import { Input } from "@/components/ui/input"
|
||||||
import { cn } from "@/lib/utils"
|
import { cn } from "@/lib/utils"
|
||||||
import { useNotesStore } from "../contexts/NotesStore"
|
import { useNotesStore } from "../contexts/NotesStore"
|
||||||
|
import { useNote } from "@/contexts/ActiveNoteContext"
|
||||||
|
|
||||||
type ListItemProps = {
|
type ListItemProps = {
|
||||||
id: string
|
id: string
|
||||||
@@ -17,7 +19,8 @@ type ListItemProps = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function ListItem({ id, label, onSelect }: ListItemProps) {
|
function ListItem({ id, label, onSelect }: ListItemProps) {
|
||||||
const { updateNote } = useNotesStore()
|
const { updateNote, deleteNote } = useNotesStore();
|
||||||
|
const { currentNoteId, setCurrentNoteId } = useNote();
|
||||||
const [tempLabel, setTempLabel] = useState(label)
|
const [tempLabel, setTempLabel] = useState(label)
|
||||||
const [isEditing, setIsEditing] = useState(false)
|
const [isEditing, setIsEditing] = useState(false)
|
||||||
const containerRef = useRef<HTMLDivElement | null>(null)
|
const containerRef = useRef<HTMLDivElement | null>(null)
|
||||||
@@ -45,6 +48,14 @@ function ListItem({ id, label, onSelect }: ListItemProps) {
|
|||||||
setIsEditing(false)
|
setIsEditing(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const handleDelete = () => {
|
||||||
|
if (currentNoteId === id) {
|
||||||
|
setCurrentNoteId(null)
|
||||||
|
}
|
||||||
|
|
||||||
|
deleteNote(id)
|
||||||
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!isEditing) return
|
if (!isEditing) return
|
||||||
|
|
||||||
@@ -70,10 +81,10 @@ function ListItem({ id, label, onSelect }: ListItemProps) {
|
|||||||
className={cn(
|
className={cn(
|
||||||
"flex items-center gap-2 px-3 py-2 rounded-md cursor-pointer",
|
"flex items-center gap-2 px-3 py-2 rounded-md cursor-pointer",
|
||||||
"text-muted-foreground hover:bg-muted hover:text-foreground",
|
"text-muted-foreground hover:bg-muted hover:text-foreground",
|
||||||
"transition-colors"
|
"transition-colors listItem"
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
<FileText className="h-4 w-4 shrink-0" />
|
<FileText className="h-3.5 w-3.5" />
|
||||||
|
|
||||||
{isEditing ? (
|
{isEditing ? (
|
||||||
<Input
|
<Input
|
||||||
@@ -84,7 +95,15 @@ function ListItem({ id, label, onSelect }: ListItemProps) {
|
|||||||
className="h-7 px-2 text-sm"
|
className="h-7 px-2 text-sm"
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
<span className="truncate text-sm">{label}</span>
|
<>
|
||||||
|
<span className="truncate text-sm">{label}</span>
|
||||||
|
<div
|
||||||
|
className="opacity-0 listItem-delete h-4 w-4 items-center justify-center rounded-full bg-muted-foreground p-0.5 ml-auto"
|
||||||
|
onClick={handleDelete}
|
||||||
|
>
|
||||||
|
<X className="h-3 w-3 text-background" />
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -130,6 +130,13 @@ body {
|
|||||||
padding-inline: 0 !important;
|
padding-inline: 0 !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.listItem:hover {
|
||||||
|
.listItem-delete {
|
||||||
|
transition: opacity .25s ease-out;
|
||||||
|
opacity: 100%;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@layer base {
|
@layer base {
|
||||||
* {
|
* {
|
||||||
@apply border-border outline-ring/50;
|
@apply border-border outline-ring/50;
|
||||||
|
|||||||
Reference in New Issue
Block a user