cleanup semicolon from js

This commit is contained in:
2026-01-31 15:43:58 +01:00
parent f919079f69
commit 640e7a3a4f
22 changed files with 1258 additions and 1269 deletions

View File

@@ -3,60 +3,60 @@
* Embedded chat for buyer-seller communication
*/
import { t, i18n } from '../i18n.js';
import { chatService } from '../services/chat.js';
import { cryptoService } from '../services/crypto.js';
import { t, i18n } from '../i18n.js'
import { chatService } from '../services/chat.js'
import { cryptoService } from '../services/crypto.js'
class ChatWidget extends HTMLElement {
static get observedAttributes() {
return ['listing-id', 'recipient-id', 'recipient-key', 'recipient-name'];
return ['listing-id', 'recipient-id', 'recipient-key', 'recipient-name']
}
constructor() {
super();
this.chat = null;
this.messages = [];
this.unsubscribe = null;
super()
this.chat = null
this.messages = []
this.unsubscribe = null
}
async connectedCallback() {
await cryptoService.ready;
await cryptoService.ready
this.listingId = this.getAttribute('listing-id');
this.recipientId = this.getAttribute('recipient-id');
this.recipientKey = this.getAttribute('recipient-key');
this.recipientName = this.getAttribute('recipient-name') || 'Seller';
this.listingId = this.getAttribute('listing-id')
this.recipientId = this.getAttribute('recipient-id')
this.recipientKey = this.getAttribute('recipient-key')
this.recipientName = this.getAttribute('recipient-name') || 'Seller'
if (this.listingId && this.recipientId && this.recipientKey) {
this.chat = chatService.getOrCreateChat(
this.recipientId,
this.recipientKey,
this.listingId
);
await this.loadMessages();
)
await this.loadMessages()
}
this.render();
this.setupEventListeners();
this.render()
this.setupEventListeners()
this.unsubscribe = chatService.subscribe(() => this.refreshMessages());
this.i18nUnsubscribe = i18n.subscribe(() => this.render());
this.unsubscribe = chatService.subscribe(() => this.refreshMessages())
this.i18nUnsubscribe = i18n.subscribe(() => this.render())
}
disconnectedCallback() {
if (this.unsubscribe) this.unsubscribe();
if (this.i18nUnsubscribe) this.i18nUnsubscribe();
if (this.unsubscribe) this.unsubscribe()
if (this.i18nUnsubscribe) this.i18nUnsubscribe()
}
async loadMessages() {
if (!this.chat) return;
this.messages = await chatService.getMessages(this.chat.id, this.recipientKey);
if (!this.chat) return
this.messages = await chatService.getMessages(this.chat.id, this.recipientKey)
}
async refreshMessages() {
await this.loadMessages();
this.renderMessages();
this.scrollToBottom();
await this.loadMessages()
this.renderMessages()
this.scrollToBottom()
}
render() {
@@ -86,10 +86,10 @@ class ChatWidget extends HTMLElement {
</button>
</form>
</div>
`;
`
this.setupEventListeners();
this.scrollToBottom();
this.setupEventListeners()
this.scrollToBottom()
}
renderMessagesHtml() {
@@ -98,7 +98,7 @@ class ChatWidget extends HTMLElement {
<div class="chat-empty">
<p>${t('chat.startConversation')}</p>
</div>
`;
`
}
return this.messages.map(msg => /* html */`
@@ -108,60 +108,60 @@ class ChatWidget extends HTMLElement {
<span class="message-time">${this.formatTime(msg.timestamp)}</span>
</div>
</div>
`).join('');
`).join('')
}
renderMessages() {
const container = this.querySelector('#chat-messages');
const container = this.querySelector('#chat-messages')
if (container) {
container.innerHTML = this.renderMessagesHtml();
container.innerHTML = this.renderMessagesHtml()
}
}
setupEventListeners() {
const form = this.querySelector('#chat-form');
form?.addEventListener('submit', (e) => this.handleSubmit(e));
const form = this.querySelector('#chat-form')
form?.addEventListener('submit', (e) => this.handleSubmit(e))
}
async handleSubmit(e) {
e.preventDefault();
e.preventDefault()
const input = this.querySelector('#message-input');
const text = input?.value.trim();
const input = this.querySelector('#message-input')
const text = input?.value.trim()
if (!text || !this.chat) return;
if (!text || !this.chat) return
input.value = '';
input.value = ''
await chatService.sendMessage(
this.chat.id,
this.recipientKey,
text
);
)
}
scrollToBottom() {
const container = this.querySelector('#chat-messages');
const container = this.querySelector('#chat-messages')
if (container) {
container.scrollTop = container.scrollHeight;
container.scrollTop = container.scrollHeight
}
}
formatTime(timestamp) {
const date = new Date(timestamp);
return date.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' });
const date = new Date(timestamp)
return date.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' })
}
escapeHtml(text) {
const div = document.createElement('div');
div.textContent = text;
return div.innerHTML;
const div = document.createElement('div')
div.textContent = text
return div.innerHTML
}
}
customElements.define('chat-widget', ChatWidget);
customElements.define('chat-widget', ChatWidget)
const style = document.createElement('style');
const style = document.createElement('style')
style.textContent = /* css */`
chat-widget {
display: block;
@@ -295,7 +295,7 @@ style.textContent = /* css */`
chat-widget .chat-input button:hover {
background: var(--color-text-secondary);
}
`;
document.head.appendChild(style);
`
document.head.appendChild(style)
export { ChatWidget };
export { ChatWidget }