From 6a3eaaea335440371698bec409952d4c82d7d628 Mon Sep 17 00:00:00 2001 From: aidahosa1 Date: Mon, 17 Jun 2024 13:05:48 -0400 Subject: yay concise code --- .../views/collections/CollectionCardDeckView.tsx | 114 +++++++++++---------- 1 file changed, 59 insertions(+), 55 deletions(-) (limited to 'src') diff --git a/src/client/views/collections/CollectionCardDeckView.tsx b/src/client/views/collections/CollectionCardDeckView.tsx index 7362a65ae..f50ca6349 100644 --- a/src/client/views/collections/CollectionCardDeckView.tsx +++ b/src/client/views/collections/CollectionCardDeckView.tsx @@ -451,77 +451,81 @@ export class CollectionCardView extends CollectionSubView() { GPTPopup.Instance.onSortComplete = (sortResult: string) => this.processGptOutput(sortResult); }; - /** + /** * Renders the buttons to customize sorting depending on which group the card belongs to and the amount of total groups - * @param childPairIndex * @param doc + * @param cardSort * @returns */ - renderButtons = (doc: Doc, cardSort: cardSortings) => { - if (cardSort !== cardSortings.Custom) return ''; - const amButtons = Math.max(4, this.childDocs?.reduce((set, d) => this.cardSort_customField && set.add(NumCast(d[this.cardSort_customField])), new Set()).size ?? 0); - const activeButtonIndex = CollectionCardView.getButtonGroup(this.cardSort_customField, doc); - const totalWidth = amButtons * 72 + amButtons * 2 * 5 + 6; - return ( -
- {numberRange(amButtons).map(i => ( - // eslint-disable-next-line jsx-a11y/control-has-associated-label - Click to add/ remove this card from group {i +1}
}> + renderButtons = (doc: Doc, cardSort: cardSortings): JSX.Element | null => { + if (cardSort !== cardSortings.Custom) return null; + + const amButtons = Math.max(4, this.childDocs?.reduce((set, d) => { + if (this.cardSort_customField) { + set.add(NumCast(d[this.cardSort_customField])); + } + return set; + }, new Set()).size ?? 0); + + const activeButtonIndex = CollectionCardView.getButtonGroup(this.cardSort_customField, doc); + const totalWidth = amButtons * 72 + amButtons * 2 * 5 + 6; + + return ( +
+ {numberRange(amButtons).map(i => ( + Click to add/remove this card from group {i + 1}
}> + + + ))} + + ); +}; - + getButtonIcon = (isActive: boolean): JSX.Element => { + const iconMap: { [key: string]: any } = { + like: 'heart', + chat: 'robot', + idea: 'cloud' + }; - + const icon = iconMap[this.cardSort_customField ?? ''] || 'star'; + const color = isActive ? '#4476f7' : '#323232'; - ))} - - ); + return ; }; - getButtonIcons = (isActive: boolean) => { - switch (this.cardSort_customField) { - case 'like': - return ; - case 'chat': - return ; - case 'idea': - return ; - default: - return ; - } + + + @action + onDragStart = (index: number) => { + this.draggedIndex = index; }; @action -onDragStart = (index: number) => { - this.draggedIndex = index; -}; + onDragOver = (index: number) => { + if (this.draggedIndex !== index) { + this.overIndex = index; + } + }; -@action -onDragOver = (index: number) => { - if (this.draggedIndex !== index) { - this.overIndex = index; - } -}; + @action + onDrop = () => { + if (this.draggedIndex !== -1 && this.overIndex !== -1) { + const draggedDoc = this.sortedDocs[this.draggedIndex]; + this.sortedDocs.splice(this.draggedIndex, 1); + this.sortedDocs.splice(this.overIndex, 0, draggedDoc); + this.draggedIndex = -1; + this.overIndex = -1; + } + }; -@action -onDrop = () => { - if (this.draggedIndex !== -1 && this.overIndex !== -1) { - const draggedDoc = this.sortedDocs[this.draggedIndex]; - this.sortedDocs.splice(this.draggedIndex, 1); - this.sortedDocs.splice(this.overIndex, 0, draggedDoc); + @action + onDragEnd = () => { this.draggedIndex = -1; this.overIndex = -1; - } -}; - -@action -onDragEnd = () => { - this.draggedIndex = -1; - this.overIndex = -1; -}; + }; /** * Actually renders all the cards */ -- cgit v1.2.3-70-g09d2