Skip to content

Commit 2a860af

Browse files
author
Bot
committed
stretch random lang btn to fill empty cells
1 parent 0f25bbd commit 2a860af

File tree

2 files changed

+43
-3
lines changed

2 files changed

+43
-3
lines changed

src/App.vue

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ export default {
3232
computed: {
3333
...mapGetters(['room', 'trackedContainers', 'smallScreen']),
3434
isThin() {
35-
console.log('UPDATE');
3635
const { path } = this.$route;
3736
// newGameRequest exception because of webkit bug with position: fixed and transfrom http://code.google.com/p/chromium/issues/detail?id=20574
3837
return !this.room.newGameRequest && (path === '/run' || (this.innerWidth < 1300 && !this.room.connected && path !== '/'));

src/components/LanguagesList.vue

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@
2626
>
2727
<button
2828
:disabled="room.connected && !room.owner"
29-
class="language random"
29+
class="language random-btn"
3030
:class="{'selected': language.index === null}"
31+
:style="{'--col-span': randomBtnColSpan}"
3132
@click="selectRandom"
3233
>
3334
<span class="language-name">
@@ -70,6 +71,7 @@ export default {
7071
return {
7172
searchText: '',
7273
forceStats: false,
74+
randomBtnColSpan: 1,
7375
};
7476
},
7577
computed: {
@@ -85,6 +87,10 @@ export default {
8587
}
8688
return [...Array(29)].map(() => ({ name: 'Loading...' }));
8789
},
90+
fillEmptyCellsReference() {
91+
// .bind spawns new reference and will not work with removeEventListener without saving it here
92+
return this.fillEmptyCells.bind(this);
93+
},
8894
},
8995
watch: {
9096
'room.owner': {
@@ -106,12 +112,18 @@ export default {
106112
}
107113
},
108114
},
115+
filteredList() {
116+
this.fillEmptyCells();
117+
},
109118
},
110119
activated() {
111120
this.$store.commit('ADD_TRACKED_CONTAINER', this.$refs.languagesList);
121+
window.addEventListener('resize', this.fillEmptyCellsReference);
112122
},
113123
deactivated() {
114124
this.$store.commit('REMOVE_TRACKED_CONTAINER', this.$refs.languagesList.className);
125+
console.log('DEACTIVATED');
126+
window.removeEventListener('resize', this.fillEmptyCellsReference);
115127
},
116128
methods: {
117129
clear() {
@@ -147,6 +159,32 @@ export default {
147159
this.$nextTick(() => this.$socket.client.emit('languageChange', ev.target.getAttribute('data-index')));
148160
}
149161
},
162+
fillEmptyCells() {
163+
// randomBtn prevents shrinking
164+
this.randomBtnColSpan = 1;
165+
166+
this.$nextTick(() => {
167+
const gridComputedStyle = window.getComputedStyle(this.$refs.languagesList);
168+
console.warn(gridComputedStyle.getPropertyValue('grid-template-columns'));
169+
170+
const columns = gridComputedStyle.getPropertyValue('grid-template-columns')
171+
.replace(/ 0px/g, '') // webkit bug return 0px for non existing columns
172+
.split(' ').length;
173+
174+
console.log(`cells: ${this.filteredList.length + 1}`);
175+
console.log(`columns: ${columns}`);
176+
177+
const mod = (this.filteredList.length + 1) % columns;
178+
console.log(`mod: ${mod}`);
179+
180+
if (mod) {
181+
const emptyCells = columns - mod;
182+
console.blue(emptyCells);
183+
184+
this.randomBtnColSpan = emptyCells + 1;
185+
}
186+
});
187+
},
150188
toggleStats() {
151189
this.forceStats = !this.forceStats;
152190
},
@@ -211,12 +249,15 @@ export default {
211249
.language-radio
212250
display: none
213251
214-
.showStats .language:hover:not(.random), .forceStats .language:not(.random)
252+
.showStats .language:hover:not(.random-btn), .forceStats .language:not(.random-btn)
215253
& > .language-name
216254
transform: translateX(-25%)
217255
& > .stat
218256
opacity: 1
219257
258+
.random-btn
259+
grid-column-start: span var(--col-span)
260+
220261
.language
221262
display: flex
222263
align-items: center

0 commit comments

Comments
 (0)