瀏覽代碼

Rendering deck tiles

crobi 9 年之前
父節點
當前提交
f1ec793d3d
共有 4 個文件被更改,包括 157 次插入4 次删除
  1. 71
    2
      client/css/rpg-cards.css
  2. 79
    0
      client/src/views/components/deck.ts
  3. 6
    2
      client/src/views/decks.ts
  4. 1
    0
      client/tsconfig.json

+ 71
- 2
client/css/rpg-cards.css 查看文件

@@ -14,8 +14,8 @@ body {
14 14
     display: flex;
15 15
     flex-direction: row;
16 16
     height: 3rem;
17
-    background-color: rgb(126, 120, 3);
18
-    color: rgb(228, 228, 238);
17
+    background-color: #4CAF50;
18
+    color: #FFF;
19 19
     font-size: 1.8rem;
20 20
     line-height: 3rem;
21 21
 }
@@ -50,3 +50,72 @@ body {
50 50
     cursor: initial;
51 51
     background-color: inherit;
52 52
 }
53
+
54
+/* ---------------------------------------------------------------------------*/
55
+/* List of decks */
56
+/* ---------------------------------------------------------------------------*/
57
+.decks {
58
+    margin-top: 1rem;
59
+    display: flex;
60
+    flex-direction: row;
61
+    flex-wrap: wrap;
62
+}
63
+
64
+.deck-tile {
65
+    margin: .5rem;
66
+    width: 20rem;
67
+    height: 12rem;
68
+
69
+    display: flex;
70
+    flex-direction: column;
71
+
72
+    background-color: rgb(255, 255, 255);
73
+
74
+    page-break-inside: avoid;
75
+    border-radius: 4px;
76
+    box-shadow: 0 1px 4px 0 rgba(0, 0, 0, 0.37);
77
+}
78
+.deck-tile-header {
79
+    background-color: #F44336;
80
+    color: rgb(255, 255, 255);
81
+    display: flex;
82
+    flex-direction: row;
83
+    padding: 0.5rem;
84
+    border-radius: 4px 4px 0 0;
85
+    font-size: 1.2rem;
86
+    font-weight: 400;
87
+}
88
+.deck-tile-header:hover {
89
+    background-color: rgb(96, 104, 126);
90
+    cursor: pointer;
91
+}
92
+.deck-tile-header-name {
93
+    flex: 1;
94
+}
95
+.deck-tile-header-id {
96
+
97
+}
98
+.deck-tile-body {
99
+    flex: 1;
100
+    display: flex;
101
+    justify-content: center;
102
+    flex-direction: column;
103
+    align-items: center;
104
+}
105
+.deck-tile-body-item {
106
+    /* Vertical centering */
107
+    /*
108
+    display: flex;
109
+    flex-direction: column;
110
+    justify-content: center;
111
+    */
112
+    width: 100%;
113
+    padding: 0 1rem;
114
+    flex: 1;
115
+}
116
+.deck-tile-footer {
117
+    padding: 0.5rem;
118
+    border-radius: 0 0 4px 4px;
119
+    color: #a8a8a8;
120
+    background: #eaeaea;
121
+}

+ 79
- 0
client/src/views/components/deck.ts 查看文件

@@ -0,0 +1,79 @@
1
+module rpgcards {
2
+
3
+    export interface DeckTileProps {
4
+        key      : string; //< Unique key for react
5
+        id       : string;
6
+        name     : string;
7
+        desc     : string;
8
+        cards    : number;
9
+    }
10
+    function DeckTilePropsEqual(a:DeckTileProps, b:DeckTileProps) {
11
+        return a.id === b.id &&
12
+            a.name === b.name &&
13
+            a.desc === b.desc &&
14
+            a.cards === b.cards;
15
+    }
16
+
17
+    interface DeckTileState {
18
+    }
19
+
20
+    export function tileHeader(id: string, name: string) {
21
+        return React.DOM.div
22
+            ( { className: 'deck-tile-header', onClick: null }
23
+            , React.DOM.div({ className: 'deck-tile-header-name' }, name)
24
+            , React.DOM.div({ className: 'deck-tile-header-id' }, id.substring(0, 5))
25
+            );
26
+    }
27
+
28
+    export function tileBody(description: string) {
29
+        return React.DOM.div
30
+            ( { className: 'deck-tile-body', onClick: null }
31
+            , description
32
+            );
33
+    }
34
+
35
+    export function tileFooter(cards: number) {
36
+        let cardsText = "This deck contains " + cards + " cards.";
37
+        return React.DOM.div
38
+            ( { className: 'deck-tile-footer', onClick: null }
39
+            , cardsText
40
+            );
41
+    }
42
+
43
+    export class DeckTileSpec extends React.Component<DeckTileProps, DeckTileState> {
44
+        displayName: string;
45
+
46
+        initialState(props: DeckTileProps): DeckTileState {
47
+            return {};
48
+        }
49
+
50
+        // Use this function to speed up rendering
51
+        /*
52
+        shouldComponentUpdate(nextProps: DeckTileProps, nextState: DeckTileState): boolean {
53
+            return DeckTilePropsEqual(this.props, nextProps);
54
+        }
55
+        */
56
+
57
+        constructor(props: DeckTileProps) {
58
+            super(props);
59
+            this.state = this.initialState(props);
60
+            this.displayName = "DeckTile";
61
+        }
62
+
63
+        render() {
64
+            let deckId = this.props.id;
65
+            let deckName = this.props.name;
66
+            let deckDesc = this.props.desc;
67
+            let deckCards = this.props.cards;
68
+
69
+            return React.DOM.div
70
+                ( { className: 'deck-tile' }
71
+                , tileHeader(deckId, deckName)
72
+                , tileBody(deckDesc)
73
+                , tileFooter(deckCards)
74
+                );
75
+        }
76
+    }
77
+
78
+    export var DeckTile: React.Factory<DeckTileProps> = React.createFactory(DeckTileSpec);
79
+}

+ 6
- 2
client/src/views/decks.ts 查看文件

@@ -9,8 +9,12 @@ module rpgcards {
9 9
             let cards = store.getCardsForDeck(id);
10 10
 
11 11
             return AsyncT.liftA2(deck, cards, (deck, cards) => {
12
-                return React.DOM.div({key:deck.id},
13
-                    "Deck " + deck.id + ": " + cards.length + " cards")
12
+                return <React.ReactElement<any>> DeckTile({
13
+                    key : deck.id,
14
+                    id  : deck.id,
15
+                    desc: deck.description,
16
+                    name: deck.name,
17
+                    cards: cards.length });
14 18
             }).caseOf({
15 19
                 just: (t) => t,
16 20
                 nothing: (e) => React.DOM.div({}, "error: " + e.message),

+ 1
- 0
client/tsconfig.json 查看文件

@@ -30,6 +30,7 @@
30 30
         "./src/stores/id.ts",
31 31
         "./src/stores/store.ts",
32 32
         "./src/stores/template.ts",
33
+        "./src/views/components/deck.ts",
33 34
         "./src/views/decks.ts",
34 35
         "./src/views/header.ts"
35 36
     ]

Loading…
取消
儲存