В настоящее время я работаю над обновлением функции в моем коде, которая отслеживает статистику пользователей в зависимости от количества постов, которые они сделали, и о том, что они получили. Тем не менее, я сталкиваюсь с проблемой, которая мне нужна помощь в решении. Статистика не обновляется-они остаются на 0 для обоих. Ниже приведен частичный раздел кода, связанный с обновлением статистики. Не могли бы вы помочь мне определить и исправить ошибку? < /P>
html: < /p>
0 Posts
Posts
0 Likes Received
Likes Received
< /code>
javascript: < /p>
function initAccountStats() {
if (!auth.currentUser) return;
const user = db.getUserByEmail(auth.currentUser.email);
if (!user) return;
// Initialize counts if undefined
user.postCount = user.postCount || 0;
user.likesReceived = user.likesReceived || 0;
db.updateUser(auth.currentUser.email, user);
// Update DOM elements
const postsElement = document.getElementById('account-posts-count');
const likesElement = document.getElementById('account-likes-count');
if (postsElement) postsElement.textContent = `${user.postCount} Posts`;
if (likesElement) likesElement.textContent = `${user.likesReceived} Likes Received`;
}
function clearUserInterface() {
// Clear profile information
document.getElementById('profile-name').textContent = '';
document.getElementById('profile-email').textContent = '';
document.getElementById('profile-picture').src = 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0IiBmaWxsPSJub25lIiBzdHJva2U9ImN1cnJlbnRDb2xvciIgc3Ryb2tlLXdpZHRoPSIyIiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiIGNsYXNzPSJsdWNpZGUgbHVjaWRlLXVzZXIiPjxwYXRoIGQ9Ik0xOSAyMXYtMmE0IDQgMCAwIDAtNC00SDlhNCA0IDAgMCAwLTQgNHYyIi8+PGNpcmNsZSBjeD0iMTIiIGN5PSI3IiByPSI0Ii8+PC9zdmc+';
// Clear account form
document.getElementById('account-name').value = '';
document.getElementById('account-email').value = '';
document.getElementById('account-bio').value = '';
document.getElementById('pfp-preview').src = '';
// Clear statistics
document.getElementById('account-posts-count').textContent = '0 Posts';
document.getElementById('account-likes-count').textContent = '0 Likes Received';
// Clear posts container
document.getElementById('nearbyPostsContainer').innerHTML = '';
// Clear any active popups
closeAllPopups();
closeProfilePopup();
closeFullscreenPopup();
// Clear user location
userLocation = DEFAULT_CENTER;
// Reset map view if it exists
if (map) {
map.setCenter(DEFAULT_CENTER);
map.setZoom(8);
}
}
function updateProfileStats(email) {
const user = db.getUserByEmail(email);
if (!user) return;
// Update posts count
const postsCountElement = document.getElementById('account-posts-count');
if (postsCountElement) {
postsCountElement.textContent = `${user.postCount || 0} Posts`;
}
// Update likes received
const likesCountElement = document.getElementById('account-likes-count');
if (likesCountElement) {
likesCountElement.textContent = `${user.likesReceived || 0} Likes Received`;
}
// Log stats to console for debugging
console.log(`[updateProfileStats] User: ${user.email}, Posts: ${user.postCount || 0}, Likes Received: ${user.likesReceived || 0}`);
const userPosts = db.getPostsByUser(email);
const likesReceived = db.getLikesReceived(email);
// Update stats in the profile popup if it's open
if (currentProfileEmail === email) {
document.getElementById('popup-posts-count').textContent = `${userPosts.length} Posts`;
document.getElementById('popup-likes-count').textContent = `${db.getLikesReceived(email)} Likes Received`;
}
// Update stats in the account page if viewing own profile
if (auth.currentUser?.email === email) {
document.getElementById('profile-posts-count').textContent = `${userPosts.length} Posts`;
document.getElementById('profile-likes-count').textContent = `${db.getLikesReceived(email)} Likes Received`;
}
}
< /code>
Кроме того, если есть какие -либо оптимизации, чтобы сделать логику более эффективной, я бы тоже признателен. Спасибо!
Подробнее здесь: https://stackoverflow.com/questions/795 ... calstorage
Статистика профиля не обновляется в LocalStorage ⇐ Html
Программисты Html
-
Anonymous
1744963611
Anonymous
В настоящее время я работаю над обновлением функции в моем коде, которая отслеживает статистику пользователей в зависимости от количества постов, которые они сделали, и о том, что они получили. Тем не менее, я сталкиваюсь с проблемой, которая мне нужна помощь в решении. Статистика не обновляется-они остаются на 0 для обоих. Ниже приведен частичный раздел кода, связанный с обновлением статистики. Не могли бы вы помочь мне определить и исправить ошибку? < /P>
html: < /p>
0 Posts
Posts
0 Likes Received
Likes Received
< /code>
javascript: < /p>
function initAccountStats() {
if (!auth.currentUser) return;
const user = db.getUserByEmail(auth.currentUser.email);
if (!user) return;
// Initialize counts if undefined
user.postCount = user.postCount || 0;
user.likesReceived = user.likesReceived || 0;
db.updateUser(auth.currentUser.email, user);
// Update DOM elements
const postsElement = document.getElementById('account-posts-count');
const likesElement = document.getElementById('account-likes-count');
if (postsElement) postsElement.textContent = `${user.postCount} Posts`;
if (likesElement) likesElement.textContent = `${user.likesReceived} Likes Received`;
}
function clearUserInterface() {
// Clear profile information
document.getElementById('profile-name').textContent = '';
document.getElementById('profile-email').textContent = '';
document.getElementById('profile-picture').src = 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0IiBmaWxsPSJub25lIiBzdHJva2U9ImN1cnJlbnRDb2xvciIgc3Ryb2tlLXdpZHRoPSIyIiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiIGNsYXNzPSJsdWNpZGUgbHVjaWRlLXVzZXIiPjxwYXRoIGQ9Ik0xOSAyMXYtMmE0IDQgMCAwIDAtNC00SDlhNCA0IDAgMCAwLTQgNHYyIi8+PGNpcmNsZSBjeD0iMTIiIGN5PSI3IiByPSI0Ii8+PC9zdmc+';
// Clear account form
document.getElementById('account-name').value = '';
document.getElementById('account-email').value = '';
document.getElementById('account-bio').value = '';
document.getElementById('pfp-preview').src = '';
// Clear statistics
document.getElementById('account-posts-count').textContent = '0 Posts';
document.getElementById('account-likes-count').textContent = '0 Likes Received';
// Clear posts container
document.getElementById('nearbyPostsContainer').innerHTML = '';
// Clear any active popups
closeAllPopups();
closeProfilePopup();
closeFullscreenPopup();
// Clear user location
userLocation = DEFAULT_CENTER;
// Reset map view if it exists
if (map) {
map.setCenter(DEFAULT_CENTER);
map.setZoom(8);
}
}
function updateProfileStats(email) {
const user = db.getUserByEmail(email);
if (!user) return;
// Update posts count
const postsCountElement = document.getElementById('account-posts-count');
if (postsCountElement) {
postsCountElement.textContent = `${user.postCount || 0} Posts`;
}
// Update likes received
const likesCountElement = document.getElementById('account-likes-count');
if (likesCountElement) {
likesCountElement.textContent = `${user.likesReceived || 0} Likes Received`;
}
// Log stats to console for debugging
console.log(`[updateProfileStats] User: ${user.email}, Posts: ${user.postCount || 0}, Likes Received: ${user.likesReceived || 0}`);
const userPosts = db.getPostsByUser(email);
const likesReceived = db.getLikesReceived(email);
// Update stats in the profile popup if it's open
if (currentProfileEmail === email) {
document.getElementById('popup-posts-count').textContent = `${userPosts.length} Posts`;
document.getElementById('popup-likes-count').textContent = `${db.getLikesReceived(email)} Likes Received`;
}
// Update stats in the account page if viewing own profile
if (auth.currentUser?.email === email) {
document.getElementById('profile-posts-count').textContent = `${userPosts.length} Posts`;
document.getElementById('profile-likes-count').textContent = `${db.getLikesReceived(email)} Likes Received`;
}
}
< /code>
Кроме того, если есть какие -либо оптимизации, чтобы сделать логику более эффективной, я бы тоже признателен. Спасибо!
Подробнее здесь: [url]https://stackoverflow.com/questions/79580616/profile-stats-are-not-updating-in-localstorage[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия