Skip to content

Conversation

@JaBrik228
Copy link
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
Owner

Choose a reason for hiding this comment

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

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

}

export type Message = {
export interface IMessage {
Copy link
Owner

Choose a reason for hiding this comment

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

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

delete this.inner[id]
}

edit(id: Id, newContent: string) {
Copy link
Owner

Choose a reason for hiding this comment

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

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

}
function onEditMessage() {
if (currEditableMessageId) {
Copy link
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
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 его можно не таскать

}
}
function focusOnMessage(value: IMessage) {
Copy link
Owner

Choose a reason for hiding this comment

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

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

textInputElement?.focus()
}
function onEditMessageByKeyDown(e: KeyboardEvent) {
Copy link
Owner

Choose a reason for hiding this comment

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

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


<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
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
Collaborator Author

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

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

delete this.inner[id]
}

edit(message: Message, newContent: string) {
Copy link
Owner

Choose a reason for hiding this comment

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

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

// TODO: Make a multiline chat input that grows dynamically
let textInputElement: HTMLInputElement | null = $state(null)
function saveMessagesOnLocalStorage() {
Copy link
Owner

Choose a reason for hiding this comment

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

saveMessagesToLocalStorage

currentEditingMessage = null
textInput = ''
setTimeout(() => textInputElement?.focus(), 0)
Copy link
Owner

Choose a reason for hiding this comment

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

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

textInputElement?.focus()
}
function startEditByShortcut(e: KeyboardEvent) {
Copy link
Owner

Choose a reason for hiding this comment

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

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


<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
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
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.

3 participants