Skip to content
Permalink
Browse files

action log share

  • Loading branch information...
Manuel-777 committed Jul 7, 2019
1 parent 00252ee commit 1eb5177233b1f53e00eddcf02da364e0ff0c7efb
Showing with 110 additions and 3 deletions.
  1. +5 −0 window_background/background.js
  2. +17 −1 window_background/http-api.js
  3. +11 −1 window_main/index.css
  4. +71 −1 window_main/match-details.js
  5. +6 −0 window_main/renderer.js
@@ -297,6 +297,11 @@ ipc.on("request_draft_link", function(event, obj) {
httpApi.httpDraftShareLink(obj.id, obj.expire);
});

//
ipc.on("request_log_link", function(event, obj) {
httpApi.httpLogShareLink(obj.id, obj.log, obj.expire);
});

//
ipc.on("windowBounds", (event, windowBounds) => {
if (firstPass) return;
@@ -231,6 +231,9 @@ function httpBasic() {
if (_headers.method == "share_draft") {
ipc_send("set_draft_link", parsedResult.url);
}
if (_headers.method == "share_log") {
ipc_send("set_log_link", parsedResult.url);
}
if (_headers.method == "home_get") {
ipc_send("set_home", parsedResult);
}
@@ -274,7 +277,7 @@ function httpBasic() {
parsedResult.ok == false &&
parsedResult.error != undefined
) {
if (_headers.method == "share_draft") {
if (_headers.method == "share_draft" || _headers.method == "share_log") {
ipc_send("popup", {
text: parsedResult.error,
time: 3000
@@ -546,6 +549,18 @@ function httpDraftShareLink(did, exp) {
});
}

function httpLogShareLink(lid, log, exp) {
var _id = makeId(6);
httpAsync.push({
reqId: _id,
method: "share_log",
method_path: "/api/get_share_log.php",
id: lid,
log: log,
expire: exp
});
}

function httpHomeGet(set) {
var _id = makeId(6);
httpAsync.unshift({
@@ -668,6 +683,7 @@ module.exports = {
httpGetDatabase,
httpHomeGet,
httpDraftShareLink,
httpLogShareLink,
httpTournamentGet,
httpTournamentJoin,
httpTournamentDrop,
@@ -530,7 +530,17 @@ span.top_nav_item_text {
-webkit-transition: all .2s ease-in;
}

.list_draft_share:hover {
.list_log_share {
cursor: pointer;
opacity: 0.75;
width: 40px;
height: 40px;
margin: auto auto auto 8px;
background: url(file:///C:/Users/Manuh/Desktop/MTG%20Arena%20Tool/MTG-Arena-Tool/window_main/../images/share.png);
-webkit-transition: all .2s ease-in;
}

.list_draft_share:hover, .list_log_share:hover {
opacity: 0.9;
}

@@ -7,7 +7,12 @@ const _ = require("lodash");
const { MANA, EASING_DEFAULT } = require("../shared/constants");
const db = require("../shared/database");
const pd = require("../shared/player-data");
const { createDiv, queryElements: $$ } = require("../shared/dom-fns");
const { createSelect } = require("../shared/select");
const {
createDiv,
createInput,
queryElements: $$
} = require("../shared/dom-fns");
const deckDrawer = require("../shared/deck-drawer");
const {
get_deck_export,
@@ -26,7 +31,9 @@ const {
drawCardList,
drawDeck,
ipcSend,
openDialog,
openActionLog,
showLoadingBars,
toggleVisibility
} = require("./renderer-util");

@@ -74,10 +81,46 @@ function openMatch(id) {
["button_simple", "openLog"],
"Action log"
);
actionLogButton.style.marginLeft = "auto";
actionLogButton.addEventListener("click", function() {
openActionLog(id, mainDiv);
});
flc.appendChild(actionLogButton);

const actionLogShareButton = createDiv(["list_log_share", match.id + "al"]);
actionLogShareButton.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"],
"",
() => logShareLink(match.id),
"expire_select"
);

openDialog(cont);
logShareLink(match.id);
});
flc.appendChild(actionLogShareButton);
}
mainDiv.appendChild(flc);

@@ -354,6 +397,33 @@ function openMatch(id) {
});
}

function logShareLink(id) {
const actionLogFile = path.join(actionLogDir, id + ".txt");
let log = fs.readFileSync(actionLogFile).toString("base64");

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_log_link", { expire, log, id });
}

//
function renderSeat(
container,
@@ -703,6 +703,12 @@ ipc.on("set_draft_link", function(event, arg) {
byId("share_input").value = arg;
});

//
ipc.on("set_log_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 1eb5177

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