Skip to content

Added editMessage function - #9

Open
JaBrik228 wants to merge 2 commits into
mainfrom
JaBrik228/message-edit
Open

Added editMessage function#9
JaBrik228 wants to merge 2 commits into
mainfrom
JaBrik228/message-edit

Conversation

@JaBrik228

Copy link
Copy Markdown
Collaborator

No description provided.

@JaBrik228
JaBrik228 requested a review from SDesya74 July 30, 2024 18:33
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="iso-8859-1"?>

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Прогони через svg optimizer чтобы убрал комменты и лишнее

Comment thread src/lib/index.svelte.ts Outdated
}

export type Message = {
export interface IMessage {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Не уверен что следует слой логики переименовывать ради фронтенда

Comment thread src/lib/index.svelte.ts Outdated
delete this.inner[id]
}

edit(id: Id, newContent: string) {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

А почему бы просто сообщению контент не установить, раз оно в onedit доступно? Реактивное же

Comment thread src/routes/+page.svelte Outdated
}

function onEditMessage() {
if (currEditableMessageId) {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Условие можно инвертировать, тогда вложенность будет меньше

if (!currEditableMessageId) {
    return
}

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

И имя currEditableMessageId наверное лучше заменить на currentEditingMessage, возможно даже лучше сделать не Id, потому что message - сигнал и по Id его можно не таскать

Comment thread src/routes/+page.svelte Outdated
}
}

function focusOnMessage(value: IMessage) {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

function startEditing мб? Более декларативно звучит и объясняет, зачем нужна функция

Comment thread src/routes/+page.svelte Outdated
textInputElement?.focus()
}

function onEditMessageByKeyDown(e: KeyboardEvent) {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Та же история, startEditByShortcut или типа того, лучше именовать бизнес функции по смыслу, а не по действию

Comment thread src/routes/+page.svelte Outdated

<footer
class="dark:text-white bg-slate-100 dark:bg-slate-700 border-t border-gray-300 dark:border-slate-600 p-4 absolute left-0 bottom-0 w-full"
class={`dark:text-white ${currEditableMessageId ? 'bg-orange-100' : 'bg-slate-100'} dark:bg-slate-700 border-t border-gray-300 dark:border-slate-600 p-4 absolute left-0 bottom-0 w-full`}

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Тут можно воспользоваться свелтовским синтаксисом

class:bg-orange-100={currEditableMessageId}

А, ну и bg-orange возможно стоит поменять на bg-accent с прозрачностью через bg-opacity. Хотя текущая механика установки цветов прозрачность не поддерживает... В целом можно и bg-orange оставить, но если есть желание прямо в этом ПР починить и прозрачность цветов, можешь это сделать. В файле со стилями темы вроде даже написано как

@JaBrik228

Copy link
Copy Markdown
Collaborator Author

Нашёл баг: При изменении сообщения, оно не обновлялось в localStorage.
Добавил функцию, в которой происходит запись сообщений в localStorage, чтобы не дублировать код в двух местах, теперь если логика сохранения сообщений измениться, можно будет изменить её в одной функции.

Так же внёс все правки, по твоим замечаниям

Comment thread src/lib/index.svelte.ts
delete this.inner[id]
}

edit(message: Message, newContent: string) {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Я имел в виду что вообще метод не нужен, поскольку логика вряд ли поменяется, ведь сообщение - сигнал. Просто подсосемся на его обновление и в будущем будем с бэкендом взаимодействовать

Comment thread src/routes/+page.svelte
// TODO: Make a multiline chat input that grows dynamically
let textInputElement: HTMLInputElement | null = $state(null)

function saveMessagesOnLocalStorage() {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saveMessagesToLocalStorage

Comment thread src/routes/+page.svelte
currentEditingMessage = null
textInput = ''

setTimeout(() => textInputElement?.focus(), 0)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Лучше поменять на tick, в svelte есть

Comment thread src/routes/+page.svelte
textInputElement?.focus()
}

function startEditByShortcut(e: KeyboardEvent) {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

startEditingByShortcut, как в функции выше

Comment thread src/routes/+page.svelte

<footer
class="dark:text-white bg-slate-100 dark:bg-slate-700 border-t border-gray-300 dark:border-slate-600 p-4 absolute left-0 bottom-0 w-full"
class:bg-orange-100={currentEditingMessage}

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Необязательно описывать оба варианта, можно в class описать ситуацию по умолчанию, когда !currentEditingMessage, а потом под ним описать дополнение с class:bg-orange-100. Оранжевый может оверрайдить серый, а приоритет у него будет выше, поскольку он указывается после дефолтного. В такой реализации пропадёт дублирование проверки currentEditingMessage

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Я изначально так и сделал, это не сработало

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants