Invite and remove track coauthors from the library songs list
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { inviteCandidates } from '$lib/data/coauthors';
|
||||
|
||||
const user = (id: string) => ({ id, name: `User ${id}`, profilePictureUrl: null });
|
||||
|
||||
describe('inviteCandidates', () => {
|
||||
it('hides the owner, selected users and users with an active invitation', () => {
|
||||
const result = inviteCandidates([user('owner'), user('a'), user('b'), user('c'), user('d')], {
|
||||
ownerId: 'owner',
|
||||
selectedIds: ['a'],
|
||||
invites: [
|
||||
{ userId: 'b', name: 'B', status: 'Pending' },
|
||||
{ userId: 'c', name: 'C', status: 'Accepted' }
|
||||
]
|
||||
});
|
||||
expect(result.map((item) => item.id)).toEqual(['d']);
|
||||
});
|
||||
|
||||
it('keeps users who rejected so they can be invited again', () => {
|
||||
const result = inviteCandidates([user('a')], {
|
||||
ownerId: null,
|
||||
selectedIds: [],
|
||||
invites: [{ userId: 'a', name: 'A', status: 'Rejected' }]
|
||||
});
|
||||
expect(result.map((item) => item.id)).toEqual(['a']);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,30 @@
|
||||
import type { CoauthorInvite, CoauthorStatus } from '$lib/types';
|
||||
import type { TrackTone } from '$lib/data/libraryTracks';
|
||||
|
||||
export interface UserOption {
|
||||
id: string;
|
||||
name: string;
|
||||
profilePictureUrl: string | null;
|
||||
}
|
||||
|
||||
export const COAUTHOR_STATUS: Record<CoauthorStatus, { label: string; tone: TrackTone }> = {
|
||||
Pending: { label: 'Pendiente', tone: 'neutral' },
|
||||
Accepted: { label: 'Aceptado', tone: 'success' },
|
||||
Rejected: { label: 'Rechazado', tone: 'danger' }
|
||||
};
|
||||
|
||||
export function inviteCandidates(
|
||||
results: UserOption[],
|
||||
{
|
||||
ownerId,
|
||||
selectedIds,
|
||||
invites
|
||||
}: { ownerId: string | null; selectedIds: string[]; invites: CoauthorInvite[] }
|
||||
): UserOption[] {
|
||||
const blocked = new Set([
|
||||
...selectedIds,
|
||||
...invites.filter((invite) => invite.status !== 'Rejected').map((invite) => invite.userId)
|
||||
]);
|
||||
if (ownerId) blocked.add(ownerId);
|
||||
return results.filter((user) => !blocked.has(user.id));
|
||||
}
|
||||
Reference in New Issue
Block a user