mirror of
https://github.com/yusufipk/YTChatHub.git
synced 2026-09-11 10:56:17 +00:00
feat: add toggle behavior to message selection in dashboard
This commit is contained in:
@@ -18,16 +18,22 @@ export default function DashboardPage() {
|
|||||||
const handleSelect = useCallback(
|
const handleSelect = useCallback(
|
||||||
async (message: ChatMessage) => {
|
async (message: ChatMessage) => {
|
||||||
try {
|
try {
|
||||||
await fetch(`${BACKEND_URL}/overlay/selection`, {
|
// If clicking the already-selected message, clear it
|
||||||
method: 'POST',
|
if (selection?.id === message.id) {
|
||||||
headers: { 'Content-Type': 'application/json' },
|
await fetch(`${BACKEND_URL}/overlay/selection`, { method: 'DELETE' });
|
||||||
body: JSON.stringify({ id: message.id })
|
} else {
|
||||||
});
|
// Otherwise, select the new message
|
||||||
|
await fetch(`${BACKEND_URL}/overlay/selection`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
body: JSON.stringify({ id: message.id })
|
||||||
|
});
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to select message', error);
|
console.error('Failed to select message', error);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[]
|
[selection]
|
||||||
);
|
);
|
||||||
|
|
||||||
const handleClear = useCallback(async () => {
|
const handleClear = useCallback(async () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user