Skip to content
Permalink
Browse files

share decks

  • Loading branch information...
Manuel-777 committed Sep 29, 2019
1 parent 9de9daf commit 128a27d1eed05a8e4ef650ae2b0055b2959dafbc
Showing with 100 additions and 1 deletion.
  1. +5 −0 window_background/background.js
  2. +17 −1 window_background/http-api.js
  3. +72 −0 window_main/deck-details.js
  4. +6 −0 window_main/renderer.js
@@ -284,6 +284,11 @@ ipc.on("request_log_link", function(event, obj) {
httpApi.httpLogShareLink(obj.id, obj.log, obj.expire);
});

//
ipc.on("request_deck_link", function(event, obj) {
httpApi.httpDeckShareLink(obj.deckString, obj.expire);
});

//
ipc.on("windowBounds", (event, windowBounds) => {
if (firstPass) return;
@@ -263,6 +263,9 @@ function httpBasic() {
if (_headers.method == "share_log") {
ipc_send("set_log_link", parsedResult.url);
}
if (_headers.method == "share_deck") {
ipc_send("set_deck_link", parsedResult.url);
}
if (_headers.method == "home_get") {
ipc_send("set_home", parsedResult);
}
@@ -309,7 +312,8 @@ function httpBasic() {
) {
if (
_headers.method == "share_draft" ||
_headers.method == "share_log"
_headers.method == "share_log" ||
_headers.method == "share_deck"
) {
ipc_send("popup", {
text: parsedResult.error,
@@ -606,6 +610,17 @@ function httpLogShareLink(lid, log, exp) {
});
}

function httpDeckShareLink(deck, exp) {
var _id = makeId(6);
httpAsync.push({
reqId: _id,
method: "share_deck",
method_path: "/api/get_share_deck.php",
deck: deck,
expire: exp
});
}

function httpHomeGet(set) {
var _id = makeId(6);
httpAsync.unshift({
@@ -730,6 +745,7 @@ module.exports = {
httpHomeGet,
httpDraftShareLink,
httpLogShareLink,
httpDeckShareLink,
httpTournamentGet,
httpTournamentJoin,
httpTournamentDrop,
@@ -4,9 +4,11 @@ const _ = require("lodash");
const { MANA, CARD_RARITIES, EASING_DEFAULT } = require("../shared/constants");
const db = require("../shared/database");
const pd = require("../shared/player-data");
const { createSelect } = require("../shared/select");
const {
createDiv,
createSpan,
createInput,
queryElements: $$
} = require("../shared/dom-fns");
const deckDrawer = require("../shared/deck-drawer");
@@ -27,8 +29,10 @@ const {
colorPieChart,
drawDeck,
drawDeckVisual,
openDialog,
ipcSend,
makeResizable,
showLoadingBars,
pop
} = require("./renderer-util");

@@ -288,6 +292,47 @@ function openDeck(deck = currentOpenDeck, filters = currentFilters) {
top.appendChild(createDiv(["button", "back"]));
top.appendChild(createDiv(["deck_name"], deck.name));

if (!pd.offline) {
const deckShareButton = createDiv(["list_log_share", deck.id + "al"]);
deckShareButton.addEventListener("click", e => {
e.stopPropagation();
const cont = createDiv(["dialog_content"]);
cont.style.width = "500px";

cont.append(createDiv(["share_title"], "Link for sharing:"));
const icd = createDiv(["share_input_container"]);
const linkInput = createInput([], "", {
id: "share_input",
autocomplete: "off"
});
linkInput.addEventListener("click", () => linkInput.select());
icd.appendChild(linkInput);
const but = createDiv(["button_simple"], "Copy");
but.addEventListener("click", function() {
ipcSend("set_clipboard", byId("share_input").value);
});
icd.appendChild(but);
cont.appendChild(icd);

cont.appendChild(createDiv(["share_subtitle"], "<i>Expires in: </i>"));
createSelect(
cont,
["One day", "One week", "One month", "Never"],
"",
() => deckShareLink(deck),
"expire_select"
);

openDialog(cont);
deckShareLink(deck);
});
top.appendChild(deckShareButton);
} else {
const deckCantShare = createDiv(["list_log_cant_share"]);
deckCantShare.title = "You need to be logged in to share!";
top.appendChild(deckCantShare);
}

const deckColors = createDiv(["deck_top_colors"]);
deckColors.style.alignSelf = "center";
deck.colors.forEach(color => {
@@ -331,6 +376,33 @@ function openDeck(deck = currentOpenDeck, filters = currentFilters) {
});
}

//
function deckShareLink(deck) {
let deckString = JSON.stringify(deck);

const shareExpire = byId("expire_select").value;
let expire = 0;
switch (shareExpire) {
case "One day":
expire = 0;
break;
case "One week":
expire = 1;
break;
case "One month":
expire = 2;
break;
case "Never":
expire = -1;
break;
default:
expire = 0;
break;
}
showLoadingBars();
ipcSend("request_deck_link", { expire, deckString });
}

//
function setChangesTimeline(deckId) {
const cont = $$(".stats")[0];
@@ -734,6 +734,12 @@ ipc.on("set_log_link", function(event, arg) {
byId("share_input").value = arg;
});

//
ipc.on("set_deck_link", function(event, arg) {
hideLoadingBars();
byId("share_input").value = arg;
});

//
ipc.on("tou_set", function(event, arg) {
document.body.style.cursor = "auto";

0 comments on commit 128a27d

Please sign in to comment.
You can’t perform that action at this time.