활성화 된 유저 앞으로 정렬

This commit is contained in:
yoon 2025-02-28 10:13:23 +09:00
parent ffabb284fa
commit 86f85cce10

View File

@ -1,7 +1,7 @@
<template>
<ul class="list-unstyled users-list d-flex align-items-center gap-1">
<li
v-for="(user, index) in userList"
v-for="(user, index) in sortedUserList"
:key="index"
class="avatar pull-up"
:class="{ 'opacity-100': isUserDisabled(user) }"
@ -25,7 +25,7 @@
</template>
<script setup>
import { onMounted, ref, nextTick } from 'vue';
import { onMounted, ref, nextTick, computed } from 'vue';
import { useUserStore } from '@s/userList';
import $api from '@api';
@ -41,6 +41,19 @@ const props = defineProps({
}
});
// computed
const sortedUserList = computed(() => {
return [...userList.value].sort((a, b) => {
const aDisabled = isUserDisabled(a);
const bDisabled = isUserDisabled(b);
//
if (!aDisabled && bDisabled) return -1;
if (aDisabled && !bDisabled) return 1;
return 0;
});
});
//
const fetchProjectParticipation = async () => {
if (props.projctSeq) {
@ -79,25 +92,31 @@ const isUserDisabled = (user) => {
// / DB
const toggleDisable = async (index) => {
const user = userList.value[index];
const user = sortedUserList.value[index];
if (user) {
const newParticipationStatus = props.projctSeq
? user.PROJCTYON === '1'
: !user.disabled;
if (props.projctSeq) {
const response = await $api.patch('project/updateYon', {
memberSeq: user.MEMBERSEQ,
projctSeq: props.projctSeq,
projctYon: newParticipationStatus ? '0' : '1'
});
if (response.status === 200) {
user.PROJCTYON = newParticipationStatus ? '0' : '1';
// userList
const originalIndex = userList.value.findIndex(u => u.MEMBERSEQ === user.MEMBERSEQ);
if (originalIndex !== -1) {
userList.value[originalIndex].PROJCTYON = newParticipationStatus ? '0' : '1';
}
}
} else {
user.disabled = newParticipationStatus;
emitUserListUpdate();
// userList
const originalIndex = userList.value.findIndex(u => u.MEMBERSEQ === user.MEMBERSEQ);
if (originalIndex !== -1) {
userList.value[originalIndex].disabled = newParticipationStatus;
emitUserListUpdate();
}
}
}
};