SHA256
Add handoff task document for PWA, chats, and connections
This commit is contained in:
@@ -1,18 +1,9 @@
|
||||
import { renderHeader } from '../components/header.js?v=20260403081123';
|
||||
import { contactDirectory, directMessages } from '../mock-data.js?v=20260403081123';
|
||||
import { ensureChat } from '../state.js?v=20260403081123';
|
||||
import { directMessages } from '../mock-data.js?v=20260403081123';
|
||||
import { authService, ensureChat, setContacts, state } from '../state.js?v=20260403081123';
|
||||
|
||||
export const pageMeta = { id: 'contact-search-view', title: 'Поиск контактов' };
|
||||
|
||||
function getMatches(query) {
|
||||
const normalized = query.trim().toLowerCase();
|
||||
if (!normalized) return [];
|
||||
|
||||
return contactDirectory
|
||||
.filter((contact) => contact.name.toLowerCase().startsWith(normalized))
|
||||
.slice(0, 5);
|
||||
}
|
||||
|
||||
export function render({ navigate }) {
|
||||
const screen = document.createElement('section');
|
||||
screen.className = 'stack';
|
||||
@@ -21,7 +12,7 @@ export function render({ navigate }) {
|
||||
input.className = 'input';
|
||||
input.type = 'text';
|
||||
input.name = 'contact';
|
||||
input.placeholder = 'Введите имя контакта';
|
||||
input.placeholder = 'Введите начало логина';
|
||||
input.autocomplete = 'off';
|
||||
input.maxLength = 80;
|
||||
|
||||
@@ -43,7 +34,7 @@ export function render({ navigate }) {
|
||||
resultsCard.hidden = false;
|
||||
|
||||
if (!query.trim()) {
|
||||
status.textContent = 'Введите первые буквы имени, чтобы найти контакт.';
|
||||
status.textContent = 'Введите начало логина пользователя.';
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -54,16 +45,16 @@ export function render({ navigate }) {
|
||||
|
||||
status.textContent = `Найдено пользователей: ${matches.length}`;
|
||||
|
||||
matches.forEach((contact) => {
|
||||
matches.forEach((login) => {
|
||||
const row = document.createElement('article');
|
||||
row.className = 'list-item';
|
||||
row.innerHTML = `
|
||||
<div class="avatar">${contact.initials}</div>
|
||||
<div class="avatar">${(login[0] || '?').toUpperCase()}</div>
|
||||
<div>
|
||||
<strong>${contact.name}</strong>
|
||||
<p class="meta-muted" style="margin-top:4px;">${contact.about}</p>
|
||||
<strong>${login}</strong>
|
||||
<p class="meta-muted" style="margin-top:4px;">Пользователь сервера</p>
|
||||
</div>
|
||||
<div class="meta-muted">Контакт</div>
|
||||
<div class="meta-muted">Профиль</div>
|
||||
`;
|
||||
resultsList.append(row);
|
||||
});
|
||||
@@ -72,38 +63,48 @@ export function render({ navigate }) {
|
||||
const searchButton = document.createElement('button');
|
||||
searchButton.className = 'primary-btn';
|
||||
searchButton.type = 'button';
|
||||
searchButton.textContent = 'Найти';
|
||||
searchButton.addEventListener('click', () => {
|
||||
renderResults(getMatches(input.value), input.value);
|
||||
searchButton.textContent = 'Поиск';
|
||||
searchButton.addEventListener('click', async () => {
|
||||
try {
|
||||
const logins = await authService.searchUsers(input.value.trim());
|
||||
renderResults(logins, input.value);
|
||||
} catch (e) {
|
||||
status.textContent = `Ошибка поиска: ${e.message || 'unknown'}`;
|
||||
resultsCard.hidden = false;
|
||||
}
|
||||
});
|
||||
|
||||
const addButton = document.createElement('button');
|
||||
addButton.className = 'ghost-btn';
|
||||
addButton.type = 'button';
|
||||
addButton.textContent = 'Добавить';
|
||||
addButton.textContent = 'Открыть чат';
|
||||
addButton.addEventListener('click', () => {
|
||||
if (!latestMatches.length) {
|
||||
status.textContent = 'Сначала выполните поиск, чтобы добавить контакт.';
|
||||
status.textContent = 'Сначала выполните поиск.';
|
||||
resultsCard.hidden = false;
|
||||
return;
|
||||
}
|
||||
|
||||
const contact = latestMatches[0];
|
||||
const exists = directMessages.some((item) => item.id === contact.id);
|
||||
const login = latestMatches[0];
|
||||
const exists = directMessages.some((item) => item.id === login);
|
||||
|
||||
if (!exists) {
|
||||
directMessages.unshift({
|
||||
id: contact.id,
|
||||
name: contact.name,
|
||||
initials: contact.initials,
|
||||
lastMessage: 'Новый контакт добавлен. Можно начинать диалог.',
|
||||
id: login,
|
||||
name: login,
|
||||
initials: (login[0] || '?').toUpperCase(),
|
||||
lastMessage: 'Диалог создан. Пользователь пока не в контактах.',
|
||||
time: 'сейчас',
|
||||
unread: 0,
|
||||
});
|
||||
}
|
||||
|
||||
ensureChat(contact.id);
|
||||
navigate(`chat-view/${contact.id}`);
|
||||
if (!state.contacts.includes(login)) {
|
||||
setContacts([...state.contacts, login]);
|
||||
}
|
||||
|
||||
ensureChat(login);
|
||||
navigate(`chat-view/${login}`);
|
||||
});
|
||||
|
||||
const controls = document.createElement('div');
|
||||
|
||||
Reference in New Issue
Block a user