Skip to content

Commit

Permalink
Merge pull request #28 from MarvNC/revert-25-master
Browse files Browse the repository at this point in the history
Revert "Add favorites section!"
  • Loading branch information
MarvNC authored Jul 7, 2023
2 parents d54b32c + 6515993 commit 90cb592
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 115 deletions.
14 changes: 0 additions & 14 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ const config = new Store({
const stickersDataStore = new Store({
name: 'stickers',
cwd: store.get('stickersPath'),
defaults: {
favorites: [],
}
});

// Handle creating/removing shortcuts on Windows when installing/uninstalling.
Expand Down Expand Up @@ -154,7 +151,6 @@ ipcMain.handle('ready', () => {
let stickerPacksOrder = [...new Set(config.get('stickerPacksOrder'))].filter(
(pack) => pack in stickerPacksMap
);
const favorites = stickersDataStore.get('favorites');
// check if there are any new sticker packs not in StickerPacksOrder
const newStickerPacks = Object.keys(stickerPacksMap).filter(
(pack) => !stickerPacksOrder.includes(pack)
Expand All @@ -168,7 +164,6 @@ ipcMain.handle('ready', () => {
return {
stickerPacksMap: stickerPacksMap,
stickerPacksOrder: config.get('stickerPacksOrder'),
favorites: favorites,
hotkey: config.get('hotkey'),
};
});
Expand All @@ -177,15 +172,6 @@ ipcMain.on('send-sticker', (event, stickerPath) => {
stickerHandler.pasteStickerFromPath(stickerPath, window);
});

ipcMain.on('favorite-sticker', (event, packID, stickerID) => {
stickersDataStore.set('favorites', [...config.get('favorites'), { packID, stickerID }]);
});

ipcMain.on('unfavorite-sticker', (event, packID, stickerID) => {
stickersDataStore.set('favorites', config.get('favorites').filter((sticker) => !(sticker.packID == packID && sticker.stickerID == stickerID)));
});


ipcMain.on('download-sticker-pack', (event, url) => {
const port = event.ports[0];
downloadPack(url, port, store.get('stickersPath'));
Expand Down
2 changes: 0 additions & 2 deletions src/preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ contextBridge.exposeInMainWorld('api', {
window.postMessage(event.data);
};
},
favoriteSticker: (packID, stickerID) => ipcRenderer.send('favorite-sticker', packID, stickerID),
unfavoriteSticker: (packID, stickerID) => ipcRenderer.send('unfavorite-sticker', packID, stickerID),
setStickerPackOrder: (stickerPackOrder) =>
ipcRenderer.send('set-sticker-pack-order', stickerPackOrder),
getHotkey: () => ipcRenderer.invoke('get-hotkey'),
Expand Down
100 changes: 1 addition & 99 deletions src/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,98 +51,11 @@ window.addEventListener('DOMContentLoaded', async () => {
});
}

const { stickerPacksMap, stickerPacksOrder, favorites } = await api.ready();
const { stickerPacksMap, stickerPacksOrder } = await api.ready();
const stickerContainer = document.getElementById('sticker-list');
const stickerPackListDiv = document.getElementById('sticker-pack-list');
let stickerPackIDsOrder = stickerPacksOrder;

//favorites
const favoriteDiv = document.createElement('div');
favoriteDiv.classList.add('sticker-pack');
favoriteDiv.dataset.packID = 'favorites';
favoriteDiv.id = `sticker-pack-container-favorites`;

const favoriteHeader = createElementFromHTML(/* html */ `
<div class="sticker-pack-header">
<span class="material-symbols-outlined sticker-pack-title"> star </span>
<a class="sticker-pack-author" href="" target="_blank"></a>
</div>
`);
favoriteDiv.appendChild(favoriteHeader);
favoriteDiv.style.display = 'none';
stickerContainer.appendChild(favoriteDiv);

//function for adding davorites to dom
function renderFav(favorite) {
favoriteDiv.style.display = 'grid';
const sticker = stickerPacksMap[favorite.packID].stickers[favorite.stickerID];
const stickerDiv = document.createElement('div');
stickerDiv.classList.add('sticker');
stickerDiv.classList.add(`${favorite.packID}-${favorite.stickerID}`)
stickerDiv.dataset.stickerID = favorite.stickerID;
stickerDiv.dataset.type = sticker.type;
stickerDiv.dataset.filepath = sticker.filepath;
stickerDiv.dataset.packID = favorite.packID;

const stickerImg = document.createElement('img');
stickerImg.src = sticker.filepath;

stickerDiv.appendChild(stickerImg);
favoriteDiv.appendChild(stickerDiv);

// if special type
if (sticker.type !== 'static') {
stickerDiv.classList.add('special');
stickerDiv.dataset.specialPath = sticker.specialPath;
stickerDiv.addEventListener('mouseover', async (e) => {
const { specialPath } = e.currentTarget.dataset;
e.currentTarget.firstChild.src = specialPath;
});
stickerDiv.addEventListener('mouseout', async (e) => {
const { filepath } = e.currentTarget.dataset;
e.currentTarget.firstChild.src = filepath;
});

}
// on click send sticker
stickerDiv.addEventListener('click', async (e) => {
// determine whether special or not, send appropriate sticker path
const { type, filepath, specialPath } = e.currentTarget.dataset;
let stickerPath = filepath;
if (type !== 'static') {
stickerPath = specialPath;
}
api.sendSticker(stickerPath);
});

//right click to remove favorite
stickerDiv.addEventListener('mousedown', async (e) => {
if (e.button == 2) {
api.unfavoriteSticker(stickerDiv.dataset.packID, stickerDiv.dataset.stickerID);
var existing = document.getElementsByClassName(`${stickerDiv.dataset.packID}-${stickerDiv.dataset.stickerID}`);
while (existing.length > 0) {
existing[0].remove();
}
if (favoriteDiv.children.length == 1) {
favoriteDiv.style.display = 'none';
}
}
}, false)
}
//render em
if (favorites.length > 0) {
favoriteDiv.style.display = 'grid';

for (const favorite of favorites) {
renderFav(favorite);
}


stickerContainer.appendChild(favoriteDiv);
}



for (const stickerPackID of stickerPackIDsOrder) {
const stickerPack = stickerPacksMap[stickerPackID];
const { title, mainIcon, stickers, author, authorURL, storeURL } = stickerPack;
Expand Down Expand Up @@ -212,17 +125,6 @@ window.addEventListener('DOMContentLoaded', async () => {
}
api.sendSticker(stickerPath);
});

//On right click, favorite sticker
stickerDiv.addEventListener('mousedown', async (e) => {
if (e.button == 2) {
if (document.getElementsByClassName(`${stickerDiv.dataset.packID}-${stickerDiv.dataset.stickerID}`).length == 0) {
api.favoriteSticker(stickerDiv.dataset.packID, stickerDiv.dataset.stickerID);
renderFav({ packID: stickerDiv.dataset.packID, stickerID: stickerDiv.dataset.stickerID })
}
}
}, false)

}

stickerContainer.appendChild(stickerPackDiv);
Expand Down

0 comments on commit 90cb592

Please sign in to comment.