Skip to content

Commit

Permalink
Fix: Re-rendering issue
Browse files Browse the repository at this point in the history
  • Loading branch information
shantanu-02 committed Jan 10, 2025
1 parent e3a3688 commit 5fe4047
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 13 deletions.
10 changes: 10 additions & 0 deletions users/discord/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,17 @@ const handleUserSelected = (userId) => {
);

if (selectedUserIndex !== -1) {
const usersSection = document.querySelector('.users_section');
const scrollPosition = usersSection?.scrollTop;

showUser = selectedUserIndex;

rerender(App(), window['root']);

const restoredUsersSection = document.querySelector('.users_section');
if (restoredUsersSection) {
restoredUsersSection.scrollTop = scrollPosition;
}
}
}
};
Expand Down
31 changes: 18 additions & 13 deletions users/discord/components/UsersSection.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@ export const UsersSection = ({ users, showUser, handleUserSelected }) => {

const handleClick = (userId) => {
selectedUserId = userId;
document.querySelectorAll('.user_card').forEach((card) => {
if (card.dataset.key === userId) {
card.classList.add('active_tab');
} else {
card.classList.remove('active_tab');
}
});
const activeCard = document.querySelector('.user_card.active_tab');
if (activeCard) {
activeCard.classList.remove('active_tab');
}

const newActiveCard = document.querySelector(
`.user_card[data-key="${userId}"]`,
);
if (newActiveCard) {
newActiveCard.classList.add('active_tab');
}

const selectedUser = users.find((user) => user.id === userId);

Expand All @@ -20,9 +24,9 @@ export const UsersSection = ({ users, showUser, handleUserSelected }) => {
detailsSection
.querySelectorAll('.user_details_field')
.forEach((field) => {
const label = field.querySelector('span:first-child')?.textContent;
const valueSpan = field.querySelector('span:last-child');
const link = field.querySelector('a');
const label = field.querySelector('#user-label')?.textContent;
const valueSpan = field.querySelector('#user-value');
const link = field.querySelector('#user-management-link');

switch (label) {
case 'Name: ':
Expand All @@ -35,10 +39,11 @@ export const UsersSection = ({ users, showUser, handleUserSelected }) => {
if (valueSpan) valueSpan.textContent = selectedUser.discordId;
break;
case 'Joined RDS server on: ':
if (valueSpan)
if (valueSpan) {
valueSpan.textContent = new Date(
selectedUser.discordJoinedAt,
).toUTCString();
}
break;
case 'User Management: ':
if (link) {
Expand All @@ -48,9 +53,9 @@ export const UsersSection = ({ users, showUser, handleUserSelected }) => {
break;
}
});
}

handleUserSelected(userId);
handleUserSelected(userId);
}
};

return createElement(
Expand Down

0 comments on commit 5fe4047

Please sign in to comment.