2024-09-07 10:38:18 +03:00
|
|
|
<script setup lang="ts">
|
2023-01-27 18:15:46 +03:00
|
|
|
const { userId } = defineProps<{
|
|
|
|
userId: string
|
|
|
|
}>()
|
|
|
|
|
2024-02-21 18:20:08 +03:00
|
|
|
const { client } = useMasto()
|
|
|
|
const paginator = client.value.v1.lists.list()
|
|
|
|
const listsWithUser = ref((await client.value.v1.accounts.$select(userId).lists.list()).map(list => list.id))
|
2023-01-27 18:15:46 +03:00
|
|
|
|
|
|
|
function indexOfUserInList(listId: string) {
|
|
|
|
return listsWithUser.value.indexOf(listId)
|
|
|
|
}
|
|
|
|
|
|
|
|
async function edit(listId: string) {
|
|
|
|
try {
|
|
|
|
const index = indexOfUserInList(listId)
|
|
|
|
if (index === -1) {
|
2024-02-21 18:20:08 +03:00
|
|
|
await client.value.v1.lists.$select(listId).accounts.create({ accountIds: [userId] })
|
2023-01-27 18:15:46 +03:00
|
|
|
listsWithUser.value.push(listId)
|
|
|
|
}
|
|
|
|
else {
|
2024-02-21 18:20:08 +03:00
|
|
|
await client.value.v1.lists.$select(listId).accounts.remove({ accountIds: [userId] })
|
2023-01-27 18:15:46 +03:00
|
|
|
listsWithUser.value = listsWithUser.value.filter(id => id !== listId)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (err) {
|
|
|
|
console.error(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
2024-04-16 20:51:27 +03:00
|
|
|
<CommonPaginator :paginator="paginator">
|
2023-01-27 18:15:46 +03:00
|
|
|
<template #default="{ item }">
|
|
|
|
<div p4 hover:bg-active block w="100%" flex justify-between items-center gap-4>
|
|
|
|
<p>{{ item.title }}</p>
|
|
|
|
<CommonTooltip
|
|
|
|
:content="indexOfUserInList(item.id) === -1 ? $t('list.add_account') : $t('list.remove_account')"
|
|
|
|
:hover="indexOfUserInList(item.id) === -1 ? 'text-green' : 'text-red'"
|
|
|
|
>
|
|
|
|
<button
|
2023-02-03 02:09:12 +03:00
|
|
|
text-sm p2 border-1 transition-colors
|
|
|
|
border-dark
|
|
|
|
btn-action-icon
|
|
|
|
@click="() => edit(item.id)"
|
|
|
|
>
|
|
|
|
<span :class="indexOfUserInList(item.id) === -1 ? 'i-ri:user-add-line' : 'i-ri:user-unfollow-line'" />
|
|
|
|
</button>
|
2023-01-27 18:15:46 +03:00
|
|
|
</CommonTooltip>
|
|
|
|
</div>
|
|
|
|
</template>
|
2024-04-16 20:51:27 +03:00
|
|
|
<template #done>
|
|
|
|
<NuxtLink
|
|
|
|
p4 hover:bg-active block w="100%" flex justify-between items-center gap-4
|
|
|
|
to="/lists"
|
|
|
|
>
|
|
|
|
<p>{{ $t('list.manage') }}</p>
|
|
|
|
</NuxtLink>
|
|
|
|
</template>
|
2023-01-27 18:15:46 +03:00
|
|
|
</CommonPaginator>
|
|
|
|
</template>
|