From 81a58c3622450cc16885e596e3ef4f7f4f98da49 Mon Sep 17 00:00:00 2001 From: balzack Date: Thu, 19 Dec 2024 22:13:57 -0800 Subject: [PATCH] added edit subject --- .../web/src/conversation/Conversation.tsx | 8 +- app/client/web/src/message/Message.module.css | 11 ++ app/client/web/src/message/Message.tsx | 47 ++++++-- app/client/web/src/message/useMessage.hook.ts | 10 +- app/sdk/src/focus.ts | 114 +++++++++--------- 5 files changed, 120 insertions(+), 70 deletions(-) diff --git a/app/client/web/src/conversation/Conversation.tsx b/app/client/web/src/conversation/Conversation.tsx index 10d27e12..28f5d99a 100644 --- a/app/client/web/src/conversation/Conversation.tsx +++ b/app/client/web/src/conversation/Conversation.tsx @@ -36,7 +36,7 @@ export function Conversation() { const attachAudio = useRef({ click: ()=>{} } as HTMLInputElement); const attachBinary = useRef({ click: ()=>{} } as HTMLInputElement); const { width, height, ref } = useResizeDetector(); - const input = useRef(); + const input = useRef(null as null | HTMLTextAreaElement); const addImage = (image: File | undefined) => { if (image) { @@ -118,8 +118,10 @@ export function Conversation() { } } - useEffect(() => { - input.current.focus(); + useEffect(() => { + if (input.current) { + input.current.focus(); + } }, [sending]); const topics = state.topics.map((topic, idx) => { diff --git a/app/client/web/src/message/Message.module.css b/app/client/web/src/message/Message.module.css index 625a8a5a..03dfa7ec 100644 --- a/app/client/web/src/message/Message.module.css +++ b/app/client/web/src/message/Message.module.css @@ -42,6 +42,17 @@ display: none; } + .editing { + margin-top: 12px; + } + + .controls { + padding: 4px; + justify-content: flex-end; + display: flex; + gap: 8px; + } + .thumbs { display: flex; flex-direction: row; diff --git a/app/client/web/src/message/Message.tsx b/app/client/web/src/message/Message.tsx index 92705266..22fccf9c 100644 --- a/app/client/web/src/message/Message.tsx +++ b/app/client/web/src/message/Message.tsx @@ -2,14 +2,14 @@ import { useRef, useEffect, useState, useCallback } from 'react'; import { avatar } from '../constants/Icons' import { Topic, Card, Profile } from 'databag-client-sdk'; import classes from './Message.module.css' -import { Image, Skeleton, ActionIcon } from '@mantine/core' +import { Textarea, Button, Image, Skeleton, ActionIcon } from '@mantine/core' import { ImageAsset } from './imageAsset/ImageAsset'; import { AudioAsset } from './audioAsset/AudioAsset'; import { VideoAsset } from './videoAsset/VideoAsset'; import { BinaryAsset } from './binaryAsset/BinaryAsset'; import type { MediaAsset } from '../conversation/Conversation'; import { useMessage } from './useMessage.hook'; -import { IconForbid, IconTrash, IconShare, IconEdit, IconAlertSquareRounded, IconChevronLeft, IconChevronRight, IconFileAlert } from '@tabler/icons-react'; +import { IconForbid, IconTrash, IconEdit, IconAlertSquareRounded, IconChevronLeft, IconChevronRight, IconFileAlert } from '@tabler/icons-react'; import { useResizeDetector } from 'react-resize-detector'; import DOMPurify from 'dompurify'; @@ -19,11 +19,30 @@ export function Message({ topic, card, profile, host }: { topic: Topic, card: Ca const { locked, data, created, topicId, status, transform } = topic; const { name, handle, node } = profile || card || { name: null, handle: null, node: null } const { text, textColor, textSize, assets } = data || { text: null, textColor: null, textSize: null } - const textStyle = textColor && textSize ? { color: textColor, fontSize: textSize } : textColor ? { color: textColor } : textSize ? { fontSize: textSize } : {} + const textStyle = { color: textColor ? textColor : undefined, fontSize: textSize ? textSize : undefined }; const logoUrl = profile ? profile.imageUrl : card ? card.imageUrl : avatar; const timestamp = actions.getTimestamp(created); const [message, setMessage] = useState(

); + const [editing, setEditing] = useState(false); + const [editText, setEditText] = useState(''); + const [saving, setSaving] = useState(false); + const save = async () => { + setSaving(true); + try { + await actions.saveSubject(topic.topicId, topic.sealed, {...topic.data, text: editText}); + } catch (err) { + console.log(err); + } + setSaving(false); + setEditing(false); + } + + const edit = () => { + setEditing(true); + setEditText(text); + } + useEffect(() => { const urlPattern = new RegExp('(https?:\\/\\/)?(www\\.)?[-a-zA-Z0-9@:%._\\+~#=]{2,256}\\.[a-z]{2,4}\\b([-a-zA-Z0-9@:%_\\+.~#?&//=]*)'); const hostPattern = new RegExp('^https?:\\/\\/', 'i'); @@ -105,9 +124,8 @@ export function Message({ topic, card, profile, host }: { topic: Topic, card: Ca
- { !locked && profile && ( - + )} { (host || profile) && ( @@ -117,13 +135,24 @@ export function Message({ topic, card, profile, host }: { topic: Topic, card: Ca
- { !locked && status === 'confirmed' && text && ( -
-
- { message } + {! locked && status === 'confirmed' && editing && ( +
+