mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-10-23 15:36:33 +00:00
refactor(tours): move non-component exports out of component files and split long hooks
Clears the client lint ratchet: helpers move to sibling .ts files for react-refresh, complex render paths get small helpers, floating promises are voided, the stage rail lets a stale request go during render, and the collections page reads the active list's tours and rights in ActiveCollectionTours. StageNumber is no longer exported.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import type { Collection } from '@trek/shared';
|
||||
import type { Collection, CollectionMember, CollectionRole } from '@trek/shared';
|
||||
|
||||
/**
|
||||
* Whether the user may add to a list: their own, or a shared one where they
|
||||
@@ -12,8 +12,24 @@ export function canAddToCollection(
|
||||
if (collection.is_owner !== false) return true;
|
||||
return (collection.members ?? []).some(
|
||||
(member) =>
|
||||
member.user_id === userId &&
|
||||
member.status === 'accepted' &&
|
||||
(member.role === 'editor' || member.role === 'admin')
|
||||
member.user_id === userId && member.status === 'accepted' && (member.role === 'editor' || member.role === 'admin')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* The user's role on a list: owner of their own, else the role a shared list
|
||||
* gives them as a member, or null when they are neither.
|
||||
*/
|
||||
export function collectionRoleOf(
|
||||
isOwner: boolean,
|
||||
members: readonly Pick<CollectionMember, 'user_id' | 'is_owner' | 'role'>[],
|
||||
userId: number | null | undefined
|
||||
): 'owner' | CollectionRole | null {
|
||||
if (isOwner) return 'owner';
|
||||
return members.find((member) => member.user_id === userId && !member.is_owner)?.role ?? null;
|
||||
}
|
||||
|
||||
/** Whether a role may remove from a list: its owner or an admin of it. */
|
||||
export function canRemoveFromCollection(role: 'owner' | CollectionRole | null): boolean {
|
||||
return role === 'owner' || role === 'admin';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user