Skip to content

Commit d86e8cd

Browse files
feat: add support for cheers (#1)
1 parent 3735549 commit d86e8cd

File tree

14 files changed

+255
-67
lines changed

14 files changed

+255
-67
lines changed

.idea/inspectionProfiles/Project_Default.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ sudo: false
22
language: node_js
33
node_js:
44
- v4
5-
- v5
5+
- v6
66
notifications:
77
slack:
88
secure: ezTt+YKE1kxJPRFthZ7UTZuCyBI2Jw1CmiTeUKaKD3mDSc2jhUh70hjrG0kxykYKuomkYlS/fPxWEHSK5X28XtA18tEZqjOnDG+YNCizFIat6Uq8dwUPhTJ/WAnq7CaSpH29uq90xNNWk3MAbqJMpHdYkWfFMHGkIuGDblcSjcI=

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,25 @@ module.exports = function (nodecg) {
7171
}
7272
```
7373

74+
### Cheer (bits)
75+
```js
76+
{
77+
"name": "langeh",
78+
"timestamp": 1456809533513,
79+
"id": "8f2ea9cb-2e8f-45dd-8645-0b724b2774f6",
80+
"read": false,
81+
"type": "tip",
82+
"amount": 5,
83+
"currency": "$",
84+
"formattedAmount": "$5",
85+
"comment": "Hi streamer!",
86+
"email": "email@alexvan.camp",
87+
88+
// Will be "daily" or "monthly" if this tip is the top tip of the day or month.
89+
"top": null
90+
}
91+
```
92+
7493
### Tip
7594
```js
7695
{

bower.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"paper-input": "PolymerElements/paper-input#^1.1.11",
77
"paper-tabs": "PolymerElements/paper-tabs#^1.6.2",
88
"boe-list": "SupportClass/boe-list#^0.2.0",
9-
"iron-icons": "PolymerElements/iron-icons#^1.1.3"
9+
"iron-icons": "PolymerElements/iron-icons#^1.1.3",
10+
"paper-dialog": "PolymerElements/paper-dialog#^1.1.0"
1011
}
1112
}

dashboard/elements/list-note/list-note.html

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,6 @@
1212
@apply(--layout-center);
1313
}
1414

15-
:host[type="tip"] #info {
16-
background-color: #d9ead3;
17-
}
18-
19-
:host[type="subscription"] #info {
20-
background-color: #C9CDE0;
21-
}
22-
2315
#info {
2416
@apply(--layout-flex);
2517
@apply(--shadow-elevation-2dp);
@@ -28,6 +20,11 @@
2820
min-width: 0; /* this is required, otherwise #info overflows */
2921
}
3022

23+
#bitsIcon {
24+
width: 14px;
25+
height: 14px;
26+
}
27+
3128
#label {
3229
@apply(--paper-font-menu);
3330
padding-left: 5px;
@@ -87,7 +84,10 @@
8784

8885
<div id="info">
8986
<header>
90-
<span id="label">[[_computeLabel(type)]]</span>
87+
<span id="label">
88+
<iron-icon id="bitsIcon" src="../../img/bits.svg"></iron-icon>
89+
[[_computeLabel(type)]]
90+
</span>
9191

9292
<template is="dom-if" if="[[profileUrl]]">
9393
<a id="name" href="[[profileUrl]]" target="_blank">[[name]]</a>

dashboard/elements/list-note/list-note.js

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
(function () {
22
'use strict';
33

4+
const CHEER_COLORS = [
5+
'#d3d3d3', // 1 Bit
6+
'#f1b7ff', // 100 Bits
7+
'#75f7e0', // 1,000 Bits
8+
'#b4d1ff', // 5,000 Bits
9+
'#fab4b4', // 10,000 Bits
10+
'#fed75f' // 100,000 Bits
11+
];
12+
413
Polymer({
514
is: 'list-note',
615

@@ -22,7 +31,7 @@
2231
this.flagged = typeof note.flagged === 'undefined' ? false : note.flagged;
2332
this.timestamp = note.timestamp;
2433

25-
if (note.type === 'tip') {
34+
if (note.type === 'tip' || note.type === 'cheer') {
2635
this.amount = note.amount;
2736
this.formattedAmount = note.formattedAmount;
2837
this.comment = note.comment;
@@ -35,12 +44,27 @@
3544
this.comment = note.flagReason;
3645
}
3746

47+
this.$.bitsIcon.hidden = note.type !== 'cheer';
48+
49+
this._updateBackgroundColor(note);
50+
3851
// Set this last so the computed bindings have everything they need.
3952
this.type = note.type;
4053
},
4154

55+
_updateBackgroundColor(note) {
56+
if (note.type === 'subscription') {
57+
this.$.info.style.backgroundColor = '#C9CDE0';
58+
} else if (note.type === 'tip') {
59+
this.$.info.style.backgroundColor = '#d9ead3';
60+
} else if (note.type === 'cheer') {
61+
const cheerTier = calcCheerTier(note.amount);
62+
this.$.info.style.backgroundColor = CHEER_COLORS[cheerTier];
63+
}
64+
},
65+
4266
_computeLabel(type) {
43-
if (type === 'tip') {
67+
if (type === 'tip' || type === 'cheer') {
4468
return this.formattedAmount;
4569
}
4670

@@ -63,4 +87,28 @@
6387
nodecg.sendMessage('markRead', this.id);
6488
}
6589
});
90+
91+
function calcCheerTier(numBits) {
92+
if (numBits >= 100000) {
93+
return 5;
94+
}
95+
96+
if (numBits >= 10000) {
97+
return 4;
98+
}
99+
100+
if (numBits >= 5000) {
101+
return 3;
102+
}
103+
104+
if (numBits >= 1000) {
105+
return 2;
106+
}
107+
108+
if (numBits >= 100) {
109+
return 1;
110+
}
111+
112+
return 0;
113+
}
66114
})();

dashboard/elements/panel-body/panel-body.html

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<link rel="import" href="../../components/boe-list/boe-list.html">
2-
<link rel="import" href="../../components/iron-icons/iron-icons.html">
32
<link rel="import" href="../../components/iron-flex-layout/iron-flex-layout.html">
3+
<link rel="import" href="../../components/iron-icons/iron-icons.html">
44
<link rel="import" href="../../components/paper-button/paper-button.html">
5+
<link rel="import" href="../../components/paper-dialog/paper-dialog.html">
56
<link rel="import" href="../../components/paper-input/paper-input.html">
67
<link rel="import" href="../../components/paper-tabs/paper-tab.html">
78
<link rel="import" href="../../components/paper-tabs/paper-tabs.html">
@@ -35,6 +36,8 @@
3536

3637
#clear {
3738
@apply(--layout-flex);
39+
@apply(--layout-horizontal);
40+
@apply(--layout-center-center);
3841
margin-left: 8px;
3942
}
4043

@@ -70,30 +73,30 @@
7073

7174
<div id="leftColumn">
7275
<h5>MANUAL ENTRY</h5>
73-
<paper-tabs id="tabs" selected="{{selected}}">
74-
<paper-tab>SUBSCRIPTION</paper-tab>
75-
<paper-tab>TIP</paper-tab>
76+
<paper-tabs id="tabs" selected="{{selectedType}}" attr-for-selected="name">
77+
<paper-tab name="subscription">SUBSCRIPTION</paper-tab>
78+
<paper-tab name="tip">TIP</paper-tab>
79+
<paper-tab name="cheer">CHEER</paper-tab>
7680
</paper-tabs>
7781

7882
<div style="display: flex;">
7983
<paper-input id="name" label="Name" type="text" style="margin-right: 8px;"></paper-input>
80-
<paper-input id="months" label="Months" type="number" hidden="[[selected]]" style="flex-shrink: 4;"
84+
<paper-input id="months" label="Months" type="number" hidden="[[!isSubscription(selectedType)]]" style="flex-shrink: 4;"
8185
min="0"></paper-input>
82-
<paper-input id="amount" label="Amount" type="number" hidden="[[!selected]]" style="flex-shrink: 4;"
86+
<paper-input id="amount" label="Amount" type="number" hidden="[[isSubscription(selectedType)]]" style="flex-shrink: 4;"
8387
min="0"></paper-input>
8488
</div>
8589

8690
<paper-button id="send" class="nodecg-info" raised on-tap="send">
87-
<span hidden="[[selected]]">Send Subscription</span>
88-
<span hidden="[[!selected]]">Send Tip</span>
91+
<span>[[_calcSendButtonText(selectedType)]]</span>
8992
</paper-button>
9093

9194
<div id="buttons">
92-
<paper-button id="settings" class="nodecg-configure" nodecg-dialog="settings" raised>
95+
<paper-button id="settings" class="nodecg-configure" on-tap="openSettingsDialog" raised>
9396
&nbsp;Settings&nbsp;
9497
</paper-button>
9598

96-
<paper-button id="clear" class="nodecg-configure" nodecg-dialog="clear-history" raised>
99+
<paper-button id="clear" class="nodecg-configure" on-tap="openClearHistoryDialog" raised>
97100
Clear History
98101
</paper-button>
99102
</div>
@@ -114,6 +117,37 @@ <h5>RECENT NOTES</h5>
114117
</template>
115118
</boe-list>
116119
</div>
120+
121+
<paper-dialog id="settingsDialog" with-backdrop>
122+
<h2>Settings</h2>
123+
124+
<paper-input
125+
id="minimumTipThreshold"
126+
label="Minimum Tip Threshold"
127+
type="number">
128+
</paper-input>
129+
130+
<paper-input
131+
id="minimumCheerThreshold"
132+
label="Minimum Cheer Threshold"
133+
type="number">
134+
</paper-input>
135+
136+
<div class="buttons">
137+
<paper-button dialog-dismiss>Cancel</paper-button>
138+
<paper-button dialog-confirm autofocus on-tap="_settingsDialogAccepted">Accept</paper-button>
139+
</div>
140+
</paper-dialog>
141+
142+
<paper-dialog id="clearHistoryDialog" with-backdrop>
143+
<h2>Clear History</h2>
144+
<p>Are you sure you wish to clear the <b>subscriber</b>, <b>tip</b>, and <b>cheer</b> history?</p>
145+
<p>This cannot be undone!</p>
146+
<div class="buttons">
147+
<paper-button dialog-dismiss>No, cancel</paper-button>
148+
<paper-button dialog-confirm autofocus on-tap="_clearHistoryDialogAccepted">Yes, clear</paper-button>
149+
</div>
150+
</paper-dialog>
117151
</template>
118152

119153
<script src="panel-body.js"></script>

dashboard/elements/panel-body/panel-body.js

Lines changed: 52 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,16 @@
33

44
const history = nodecg.Replicant('history');
55
const flaggedNotes = nodecg.Replicant('flaggedNotes');
6+
const tipThreshold = nodecg.Replicant('tipThreshold');
7+
const cheerThreshold = nodecg.Replicant('cheerThreshold');
68

79
Polymer({
810
is: 'panel-body',
911

1012
properties: {
11-
selected: {
12-
type: Number,
13-
value: 0
13+
selectedType: {
14+
type: String,
15+
value: 'subscription'
1416
}
1517
},
1618

@@ -26,7 +28,6 @@
2628
});
2729

2830
history.on('change', newVal => {
29-
console.log(newVal);
3031
this._pruneList(this.$.recentList, history, true);
3132

3233
newVal.slice(0).reverse().forEach(note => {
@@ -37,6 +38,14 @@
3738
}
3839
});
3940
});
41+
42+
tipThreshold.on('change', newVal => {
43+
this.$.minimumTipThreshold.value = newVal;
44+
});
45+
46+
cheerThreshold.on('change', newVal => {
47+
this.$.minimumCheerThreshold.value = newVal;
48+
});
4049
},
4150

4251
_addToListIfNotPresent(list, node) {
@@ -67,10 +76,10 @@
6776
},
6877

6978
send() {
70-
const name = document.getElementById('name').value;
71-
const type = document.getElementById('tabs').selected === 0 ? 'subscription' : 'tip';
72-
const months = document.getElementById('months').value;
73-
const amount = document.getElementById('amount').value;
79+
const name = this.$.name.value;
80+
const type = this.selectedType;
81+
const months = this.$.months.value;
82+
const amount = this.$.amount.value;
7483

7584
const noteOpts = {
7685
name,
@@ -85,7 +94,7 @@
8594
} else {
8695
noteOpts.resub = false;
8796
}
88-
} else if (type === 'tip') {
97+
} else if (type === 'tip' || type === 'cheer') {
8998
noteOpts.amount = parseFloat(amount);
9099
} else {
91100
console.error('[lfg-nucleus] Invalid manual note type:', type);
@@ -101,6 +110,40 @@
101110

102111
newestFirst(a, b) {
103112
return b.timestamp - a.timestamp;
113+
},
114+
115+
_calcSendButtonText(selectedType) {
116+
switch (selectedType) {
117+
case 'subscription':
118+
return 'Send Subscription';
119+
case 'tip':
120+
return 'Send Tip';
121+
case 'cheer':
122+
return 'Send Cheer';
123+
default:
124+
return;
125+
}
126+
},
127+
128+
isSubscription(selectedType) {
129+
return selectedType === 'subscription';
130+
},
131+
132+
openSettingsDialog() {
133+
this.$.settingsDialog.open();
134+
},
135+
136+
openClearHistoryDialog() {
137+
this.$.clearHistoryDialog.open();
138+
},
139+
140+
_settingsDialogAccepted() {
141+
tipThreshold.value = this.$.minimumTipThreshold.value;
142+
cheerThreshold.value = this.$.minimumCheerThreshold.value;
143+
},
144+
145+
_clearHistoryDialogAccepted() {
146+
nodecg.sendMessage('clearHistory');
104147
}
105148
});
106149
})();

dashboard/img/bits.svg

Lines changed: 7 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)