aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/collections/CollectionCardDeckView.tsx
diff options
context:
space:
mode:
authoraidahosa1 <aisosa_idahosa@brown.edu>2024-05-14 02:14:58 -0400
committeraidahosa1 <aisosa_idahosa@brown.edu>2024-05-14 02:14:58 -0400
commit3c5b2353cb20843e968e51fdff58cc92f101ed51 (patch)
treeabc050f4770a497989b45ac037766fe256040cc5 /src/client/views/collections/CollectionCardDeckView.tsx
parentd699cac7cab64e868aeee8d88b16e7a76e92e483 (diff)
getting close to done
Diffstat (limited to 'src/client/views/collections/CollectionCardDeckView.tsx')
-rw-r--r--src/client/views/collections/CollectionCardDeckView.tsx63
1 files changed, 51 insertions, 12 deletions
diff --git a/src/client/views/collections/CollectionCardDeckView.tsx b/src/client/views/collections/CollectionCardDeckView.tsx
index 996c5711b..fc183b72b 100644
--- a/src/client/views/collections/CollectionCardDeckView.tsx
+++ b/src/client/views/collections/CollectionCardDeckView.tsx
@@ -2,7 +2,7 @@ import { ObservableMap, action, computed, makeObservable, observable } from 'mob
import { observer } from 'mobx-react';
import * as React from 'react';
import { Utils, returnFalse, returnTrue, returnZero } from '../../../Utils';
-import { Doc, DocListCast, Field } from '../../../fields/Doc';
+import { Doc, DocListCast, Field, StrListCast } from '../../../fields/Doc';
import { Id } from '../../../fields/FieldSymbols';
import { NumCast, ScriptCast, StrCast, BoolCast, DocCast } from '../../../fields/Types';
import { DragManager } from '../../util/DragManager';
@@ -17,6 +17,7 @@ import { LinkManager } from '../../util/LinkManager';
import { DocumentType } from '../../documents/DocumentTypes';
import { forEach } from 'lodash';
import { SnappingManager } from '../../util/SnappingManager';
+import { List } from '../../../fields/List';
@observer
export class CollectionCardView extends CollectionSubView() {
@@ -70,11 +71,49 @@ export class CollectionCardView extends CollectionSubView() {
super(props);
makeObservable(this);
// this.rotationDegree(7);
+
+ if (this._props.Document.customHashMap != undefined){
+ this.customGroupDictionary = this.getCustoms(StrListCast(this._props.Document.customHashMap))
+ }
+ }
+
+ @observable customGroupDictionary: Map<number, number>[] = [new Map<number, number>(), new Map<number, number>(), new Map<number, number>()];
+
+ @computed get mapToField(): List<string> {
+ const resultList = new List<string>(); // Creating a new ListImpl instance for strings
+
+ this.customGroupDictionary.forEach(map => {
+ // Convert each map to a single string with entries formatted as "key:value"
+ const mapString = Array.from(map.entries())
+ .map(([key, value]) => `${key}:${value}`)
+ .join(','); // Join all key-value pairs with commas
+ resultList.push(mapString); // Add the formatted string of the current map to the list
+ });
+
+ return resultList;
+ }
+
+ getCustoms = (stringFrom: string[]): Map<number, number>[] => {
+ return stringFrom.map(s => {
+ // Create a new Map object for each string.
+ const map = new Map<number, number>();
+ // Split the string by commas to get key-value pairs, then process each pair.
+ s.split(',').forEach(pair => {
+ const [key, value] = pair.split(':');
+ map.set(Number(key), Number(value));
+ });
+ return map;
+ });
}
+
+
+
+
private _dropDisposer?: DragManager.DragDropDisposer;
componentWillUnmount() {
+ console.log("hey hey hey")
this._dropDisposer?.();
}
@@ -253,9 +292,11 @@ export class CollectionCardView extends CollectionSubView() {
break;
case 'custom':
- typeA = this.customGroupDictionary.get(docs.indexOf(docA)) ?? '';
+
+ console.log(this.customGroupDictionary[NumCast(this._props.Document.customSortNumber)])
+ typeA = this.customGroupDictionary[NumCast(this._props.Document.customSortNumber)].get(docs.indexOf(docA)) ?? '9999';
// console.log(typeA + "A")
- typeB = this.customGroupDictionary.get(docs.indexOf(docB)) ?? '';
+ typeB = this.customGroupDictionary[NumCast(this._props.Document.customSortNumber)].get(docs.indexOf(docB)) ?? '9999';
// console.log(typeB + 'b')
break;
@@ -397,7 +438,7 @@ export class CollectionCardView extends CollectionSubView() {
SnappingManager.SetIsResizing(undefined);
this._forceChildXf = !this._forceChildXf;
}),
- 400
+ 700
);
}}
style={{
@@ -419,11 +460,13 @@ export class CollectionCardView extends CollectionSubView() {
});
}
- @observable amGroups = 0;
- @observable customGroupDictionary = new Map<number, number>();
+
+
+
@action toggleButton(childPairIndex: number, buttonID: number) {
- this.customGroupDictionary.set(childPairIndex, buttonID);
+ this.customGroupDictionary[NumCast(this._props.Document.customSortNumber)].set(childPairIndex, buttonID);
+ this._props.Document.customHashMap = this.mapToField
}
renderButtons(childPairIndex: number) {
@@ -431,11 +474,7 @@ export class CollectionCardView extends CollectionSubView() {
let amButtons = 4;
- if (this.amGroups > 4) {
- amButtons = this.amGroups;
- }
-
- let activeButtonIndex = this.customGroupDictionary.get(childPairIndex);
+ let activeButtonIndex = this.customGroupDictionary[NumCast(this._props.Document.customSortNumber)].get(childPairIndex);
for (let i = 0; i < amButtons; i++) {
const isActive = activeButtonIndex == i;