Skip to content

Commit c8de60c

Browse files
authored
Merge pull request #78 from MarvNC/72-add-most-usedfavorites-icons
Add Most Used/Favorites Icons
2 parents 6c75981 + ab63287 commit c8de60c

File tree

4 files changed

+84
-42
lines changed

4 files changed

+84
-42
lines changed

dist/index.css

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,14 @@ body {
140140
overflow: scroll;
141141
}
142142
#app #main-content #leftbar #top-buttons {
143-
display: flex;
143+
display: grid;
144+
grid-template-columns: repeat(auto-fill, minmax(40px, 1fr));
144145
justify-content: space-evenly;
145-
margin: 5px;
146+
justify-items: center;
147+
align-content: space-evenly;
148+
align-items: center;
149+
margin: 10px;
150+
gap: 10px 0;
146151
}
147152
#app #main-content #leftbar #top-buttons .circle {
148153
height: 40px;

src/index.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@
3737
<div id="add-button" class="circle">
3838
<span class="material-symbols-outlined"> add </span>
3939
</div>
40+
<div id="most-used-icon" class="circle">
41+
<span class="material-symbols-outlined"> history </span>
42+
</div>
43+
<div id="favorites-icon" class="circle">
44+
<span class="material-symbols-outlined"> star </span>
45+
</div>
4046
</div>
4147
<div id="sticker-pack-list"></div>
4248
</div>

src/index.scss

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,15 @@ body {
162162
overflow: scroll;
163163

164164
#top-buttons {
165-
display: flex;
165+
display: grid;
166+
grid-template-columns: repeat(auto-fill, minmax(40px, 1fr));
166167
justify-content: space-evenly;
167-
margin: 5px;
168+
justify-items: center;
169+
align-content: space-evenly;
170+
align-items: center;
171+
margin: 10px;
172+
gap: 10px 0;
173+
168174

169175
.circle {
170176
height: 40px;

src/render/stickerRenderer.js

Lines changed: 63 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,28 @@ class StickerRenderer {
4545
storeURL: 'https://store.line.me/stickershop/',
4646
noIcon: true,
4747
});
48-
this.stickerContainer.appendChild(favoritesDiv);
49-
this.setUpDraggableFavorites(favoritesDiv);
48+
if (favoritesDiv) {
49+
this.stickerContainer.appendChild(favoritesDiv);
50+
this.setUpDraggableFavorites(favoritesDiv);
51+
}
52+
53+
// set click to scroll to pack on icon for most-used and favorite
54+
const icons = ['most-used', 'favorites'];
55+
for (const icon of icons) {
56+
const iconDiv = document.getElementById(`${icon}-icon`);
57+
iconDiv.addEventListener('click', (e) => {
58+
const stickerPackDiv = document.getElementById(`sticker-pack-container-${icon}`);
59+
stickerPackDiv.scrollIntoView({ behavior: 'instant' });
60+
});
61+
}
5062

5163
for (const stickerPackID of this.stickerPacksOrder) {
5264
const stickerPack = this.stickerPacksMap[stickerPackID];
5365

5466
const stickerPackDiv = this.makeAndSetUpStickerPack(stickerPackID, stickerPack);
55-
this.stickerContainer.appendChild(stickerPackDiv);
67+
if (stickerPackDiv) {
68+
this.stickerContainer.appendChild(stickerPackDiv);
69+
}
5670
}
5771

5872
// Scroll sticker pack icons list when scrolling sticker packs
@@ -174,47 +188,54 @@ class StickerRenderer {
174188

175189
// Sticker main icon
176190
if (!noIcon) {
177-
const stickerIconDiv = document.createElement('div');
178-
stickerIconDiv.classList.add('sticker-pack-icon-wrapper');
179-
stickerIconDiv.dataset.packID = stickerPackID;
191+
// Don't add icon if it already exists
192+
if (!document.getElementById(`sticker-pack-icon-${stickerPackID}`)) {
193+
const stickerIconDiv = document.createElement('div');
194+
stickerIconDiv.classList.add('sticker-pack-icon-wrapper');
195+
stickerIconDiv.dataset.packID = stickerPackID;
196+
stickerIconDiv.id = `sticker-pack-icon-${stickerPackID}`;
180197

181-
const stickerIconImg = document.createElement('img');
182-
stickerIconImg.src = mainIcon;
183-
stickerIconDiv.appendChild(stickerIconImg);
184-
this.stickerPackListDiv.appendChild(stickerIconDiv);
198+
const stickerIconImg = document.createElement('img');
199+
stickerIconImg.src = mainIcon;
200+
stickerIconDiv.appendChild(stickerIconImg);
201+
this.stickerPackListDiv.appendChild(stickerIconDiv);
185202

186-
// Scroll to sticker pack on hover
187-
stickerIconDiv.addEventListener('mouseover', (e) => {
188-
stickerPackDiv.scrollIntoView({ behavior: 'instant' });
189-
// remove active from all sticker pack icons
190-
document.querySelectorAll('.active').forEach((el) => el.classList.remove('active'));
191-
// add active to current sticker pack icon
192-
if (!this.sorting) {
193-
e.currentTarget.classList.add('active');
194-
}
195-
});
203+
// Scroll to sticker pack on hover
204+
stickerIconDiv.addEventListener('mouseover', (e) => {
205+
const stickerPackDiv = document.getElementById(`sticker-pack-container-${stickerPackID}`);
206+
stickerPackDiv.scrollIntoView({ behavior: 'instant' });
207+
// remove active from all sticker pack icons
208+
document.querySelectorAll('.active').forEach((el) => el.classList.remove('active'));
209+
// add active to current sticker pack icon
210+
if (!this.sorting) {
211+
e.currentTarget.classList.add('active');
212+
}
213+
});
214+
}
196215
}
197216

198-
// Sticker pack
199-
const stickerPackDiv = document.createElement('div');
200-
stickerPackDiv.classList.add('sticker-pack');
201-
stickerPackDiv.dataset.packID = stickerPackID;
202-
stickerPackDiv.id = `sticker-pack-container-${stickerPackID}`;
217+
// Make sticker pack if it doesn't exist
218+
if (!document.getElementById(`sticker-pack-container-${stickerPackID}`)) {
219+
const stickerPackDiv = document.createElement('div');
220+
stickerPackDiv.classList.add('sticker-pack');
221+
stickerPackDiv.dataset.packID = stickerPackID;
222+
stickerPackDiv.id = `sticker-pack-container-${stickerPackID}`;
203223

204-
const stickerPackHeader = createElementFromHTML(/* html */ `
224+
const stickerPackHeader = createElementFromHTML(/* html */ `
205225
<div class="sticker-pack-header">
206226
<a class="sticker-pack-title" href="${storeURL}" target="_blank">${title}</a>
207227
<a class="sticker-pack-author" href="${authorURL}" target="_blank">${author}</a>
208228
</div>
209229
`);
210-
stickerPackDiv.appendChild(stickerPackHeader);
230+
stickerPackDiv.appendChild(stickerPackHeader);
211231

212-
// loop through stickers
213-
for (const sticker of stickers) {
214-
stickerPackDiv.appendChild(this.createSticker(sticker));
215-
}
232+
// loop through stickers
233+
for (const sticker of stickers) {
234+
stickerPackDiv.appendChild(this.createSticker(sticker));
235+
}
216236

217-
return stickerPackDiv;
237+
return stickerPackDiv;
238+
}
218239
}
219240
/**
220241
* Fetches and updates the most used sticker pack section
@@ -231,7 +252,11 @@ class StickerRenderer {
231252
mostUsedDiv.innerHTML = '';
232253

233254
api.getMostUsed().then((mostUsed) => {
234-
const newDiv = this.makeAndSetUpStickerPack('most-used', {
255+
// delete old most used
256+
this.stickerContainer.removeChild(
257+
document.getElementById('sticker-pack-container-most-used')
258+
);
259+
const mostUsedDiv = this.makeAndSetUpStickerPack('most-used', {
235260
title: '<span class="material-symbols-outlined">history</span> Most Used',
236261
author: '',
237262
stickers: mostUsed.map(({ PackID, StickerID }) => {
@@ -243,10 +268,11 @@ class StickerRenderer {
243268
storeURL: 'https://store.line.me/stickershop/',
244269
noIcon: true,
245270
});
246-
// reinsert most used at the top
247-
this.stickerContainer.insertBefore(newDiv, mostUsedDiv);
248-
// delete old most used
249-
this.stickerContainer.removeChild(mostUsedDiv);
271+
// reinsert most used before favorites div
272+
this.stickerContainer.insertBefore(
273+
mostUsedDiv,
274+
document.getElementById('sticker-pack-container-favorites')
275+
);
250276
});
251277
}
252278
/**
@@ -376,7 +402,6 @@ class StickerRenderer {
376402
* Gets and refreshes all sticker packs
377403
*/
378404
refreshStickerPacks() {
379-
this.stickerContainer.innerHTML = '';
380405
this.populateStickerPacks();
381406
}
382407
}

0 commit comments

Comments
 (0)