Skip to content

Commit c8d8ade

Browse files
committed
feat(extension): ui for delete confirm
1 parent eb40d34 commit c8d8ade

File tree

3 files changed

+47
-5
lines changed

3 files changed

+47
-5
lines changed

clients/extension/components/notes-list/index.tsx

+26-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import style from './style.module.css'
22
import { CrossIcon } from '@ui/icons/CrossIcon'
3+
import { useState, useRef } from 'react'
34
import ReactMarkdown from 'react-markdown'
45

56
// Types
@@ -18,26 +19,47 @@ export function NotesList({ notes }: { notes?: NoteEdge[] }) {
1819
}
1920

2021
function Note({ note }: { note?: NoteEdge }) {
22+
const [confirmDelete, setConfirmDelete] = useState<boolean>(false)
23+
const noteRef = useRef<HTMLDivElement>(null)
24+
2125
const node = note?.node
2226
const title = node?.title
2327
const contentPreview = node?.contentPreview as string
28+
29+
const handleDeleteClick = () => {
30+
if (noteRef.current) noteRef.current.scrollIntoView({ behavior: 'smooth' })
31+
setConfirmDelete(true)
32+
}
33+
const handleCancelClick = () => setConfirmDelete(false)
34+
2435
return contentPreview ? (
25-
<div className={style.container}>
36+
<div className={`${style.container} ${confirmDelete && style.active}`} ref={noteRef}>
2637
<div className={style.note}>
2738
{title ? <h3>{title}</h3> : null}
2839
<ReactMarkdown allowedElements={['div']} unwrapDisallowed={true}>
2940
{contentPreview}
3041
</ReactMarkdown>
3142
</div>
3243
<div className={style.actions}>
33-
<button>
34-
<CrossIcon />
35-
</button>
44+
{!confirmDelete ? (
45+
<button onClick={handleDeleteClick}>
46+
<CrossIcon />
47+
</button>
48+
) : null}
3649
</div>
50+
{confirmDelete ? <NoteDeleteConfirm handleCancelClick={handleCancelClick} /> : null}
3751
</div>
3852
) : null
3953
}
4054

55+
function NoteDeleteConfirm({ handleCancelClick }: { handleCancelClick: () => void }) {
56+
return (
57+
<div className={style.confirm}>
58+
<button>Delete this note</button>
59+
<button onClick={handleCancelClick}>Cancel</button>
60+
</div>
61+
)
62+
}
4163
function NoNotes() {
4264
return <div className={style.noNotes}>Add your first note to this page</div>
4365
}

clients/extension/components/notes-list/style.module.css

+18-1
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,14 @@
66
}
77

88
.container {
9-
padding: 1rem 0.5rem 1rem 1rem;
9+
padding: 1rem;
1010
border-bottom: 1px solid var(--color-divider);
1111
display: grid;
1212
grid-template-columns: auto 42px;
1313
column-gap: 1rem;
14+
&.active {
15+
background-color: var(--color-canvas-active);
16+
}
1417
&:last-child {
1518
border-bottom: none;
1619
}
@@ -61,3 +64,17 @@
6164
font-style: italic;
6265
color: var(--color-text-secondary);
6366
}
67+
68+
.confirm {
69+
margin-top: 1rem;
70+
grid-column: span 2;
71+
display: flex;
72+
justify-content: space-between;
73+
column-gap: 1rem;
74+
button {
75+
display: block;
76+
text-align: center;
77+
padding: 0.5rem;
78+
width: 100%;
79+
}
80+
}

clients/extension/public/styles/global.css

+3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
--font-sans-serif: 'Graphik Web', 'Helvetica Neue', Helvetica, Arial, Sans-Serif;
2121

2222
--color-canvas: #ffffff;
23+
--color-canvas-active: hsl(0, 0%, 90%);
2324
--color-loader: #42414d;
2425
--color-text-primary: #15141a;
2526
--color-text-secondary: #333;
@@ -36,6 +37,7 @@
3637

3738
@media (prefers-color-scheme: dark) {
3839
--color-canvas: #42414d;
40+
--color-canvas-active: hsl(245, 8%, 38%);
3941
--color-loader: #15141a;
4042
--color-text-primary: #fbfbfe;
4143
--color-text-secondary: var(--color-grey85);
@@ -54,6 +56,7 @@
5456

5557
.colormode-light {
5658
--color-canvas: #ffffff;
59+
--color-canvas-active: hsl(0, 0%, 90%);
5760
--color-loader: #42414d;
5861
--color-text-primary: #15141a;
5962
--color-text-secondary: #333;

0 commit comments

Comments
 (0)