Refactoring and fixes

This commit is contained in:
ポール ウェッブ 2018-09-28 14:07:59 -05:00
parent d23f0390ec
commit c2f5ea82c2
7 changed files with 129 additions and 83 deletions

View file

@ -27,7 +27,7 @@ $("[data-action]").on("click", event => {
function open(ecosystemComponentClassName) {
switch (true) {
switch(true) {
case (ecosystemComponentClassName === "lbrycrd"):
resetClassesAndStorage();
document.getElementsByClassName("lbrycrd")[0].classList.add("active");
@ -82,7 +82,7 @@ function openSubmodule(ecosystemComponentClassName) {
document.querySelectorAll(".ecosystem__module").forEach(n => n.classList.remove("active"));
switch (true) {
switch(true) {
case (ecosystemComponentClassName === "chainquery"):
setSubmoduleConnectionTitle(ecosystemComponentClassName);

View file

@ -24,9 +24,8 @@ document.querySelector("body").addEventListener("click", event => {
event.explicitOriginalTarget.classList &&
event.explicitOriginalTarget.classList[0] === "tour__content__meme__canvas__thumbnail"
) {
for (const thumbnail of document.querySelectorAll(".tour__content__meme__canvas__thumbnail")) {
for (const thumbnail of document.querySelectorAll(".tour__content__meme__canvas__thumbnail"))
thumbnail.classList.remove("selected");
}
event.explicitOriginalTarget.classList.add("selected");
updateCanvas(event.explicitOriginalTarget);
@ -50,6 +49,9 @@ document.getElementById("fetch-claim-uri").addEventListener("keyup", event => {
document.getElementById("fetch-claim-uri").value.length > 0
) fetchMetadata(3, document.getElementById("fetch-claim-uri").value);
break;
default:
break;
}
});
@ -85,7 +87,8 @@ function detectLanguageAndUpdate() { // eslint-disable-line
for (const language of navigator.languages) userLocales.push(language);
for (const key in memeLocaleObject) {
if (memeLocaleObject[key] && memeLocaleObject[key].value) memeLocales.push(memeLocaleObject[key].value);
if (memeLocaleObject[key] && memeLocaleObject[key].value)
memeLocales.push(memeLocaleObject[key].value);
}
if (
@ -169,8 +172,8 @@ curl --header <span class="token string">"Content-Type: application/json"</span>
document.getElementById("tour-results").innerHTML = `
<pre><code class="language-bash">
<span class="token comment"># With the LBRY app/daemon running locally, you can use this in your Terminal</span>
curl --header <span class="token string">"Content-Type: application/json"</span> --data <span class="token string">'{ "method": "publish", "params": { "name": "TITLE_OF_YOUR_CONTENT", "file_path": "ABSOLUTE_PATH_TO_MEDIA_ON_YOUR_COMPUTER", "bid": "0.001", "metadata": { "description": "DESCRIPTION_OF_YOUR_CONTENT", "title": "TITLE_OF_YOUR_CONTENT", "language": "en", "license": "", "nsfw": false }}}'</span> <span class="token url">http://localhost:5279 </span>
<span class="token comment"># With the LBRY app/daemon running locally, you can use this in your Terminal</span>
curl --header <span class="token string">"Content-Type: application/json"</span> --data <span class="token string">'{ "method": "publish", "params": { "name": "TITLE_OF_YOUR_CONTENT", "file_path": "ABSOLUTE_PATH_TO_MEDIA_ON_YOUR_COMPUTER", "bid": "0.001", "metadata": { "description": "DESCRIPTION_OF_YOUR_CONTENT", "title": "TITLE_OF_YOUR_CONTENT", "language": "en", "license": "", "nsfw": false }}}'</span> <span class="token url">http://localhost:5279 </span>
</code></pre>
<div class="loader" id="temp-loader"></div>
@ -189,12 +192,11 @@ curl --header <span class="token string">"Content-Type: application/json"</span>
}));
document.getElementById("fetch-claim-uri").value = data;
// $("#fetch-claim-uri").val(data);
document.getElementById("tour-results").innerHTML = `
<pre><code class="language-bash">
<span class="token comment"># With the LBRY app/daemon running locally, you can use this in your Terminal</span>
curl --header <span class="token string">"Content-Type: application/json"</span> --data <span class="token string">'{ "method": "wallet_send", "params": { "amount": "0.01", "claim_id": "${data}" }}'</span> <span class="token url">http://localhost:5279 </span>
<span class="token comment"># With the LBRY app/daemon running locally, you can use this in your Terminal</span>
curl --header <span class="token string">"Content-Type: application/json"</span> --data <span class="token string">'{ "method": "wallet_send", "params": { "amount": "0.01", "claim_id": "${data}" }}'</span> <span class="token url">http://localhost:5279 </span>
</code></pre>
<div class="loader" id="temp-loader"></div>
@ -270,18 +272,24 @@ const handleExamples = debounce(event => {
break;
case "tour, example 2":
if ($("#tour-loader").hasClass("tour__content__trends")) {
$("#tour-loader").removeClass("tour__content__trends").addClass("tour__content__meme");
if (document.getElementById("tour-loader").classList.contains("tour__content__trends")) {
document.getElementById("tour-loader").classList.remove("tour__content__trends");
document.getElementById("tour-loader").classList.add("tour__content__meme");
}
$("#fetch-claim-uri").val(""); // reset URL bar
$("#tour-url").hide();
document.getElementById("fetch-claim-uri").value = ""; // reset URL bar
document.getElementById("tour-url").style.display = "none";
$(".tour__navigation__example").removeClass("active");
$(".tour__navigation__example:nth-child(2)").addClass("active");
for (const example of document.querySelectorAll(".tour__navigation__example"))
example.classList.remove("active");
$("#tour-loader").empty().show();
$("#tour-results").empty().show();
document.querySelector(".tour__navigation__example:nth-child(2)").classList.add("active");
document.getElementById("tour-loader").innerHTML = "";
document.getElementById("tour-results").innerHTML = "";
document.getElementById("tour-loader").removeAttribute("style");
document.getElementById("tour-results").removeAttribute("style");
send(JSON.stringify({
"message": `request for ${data.action}`
@ -290,19 +298,27 @@ const handleExamples = debounce(event => {
break;
case "tour, example 3":
if ($("#tour-loader").hasClass("tour__content__meme")) {
$("#tour-loader").removeClass("tour__content__meme").addClass("tour__content__trends");
if (document.getElementById("tour-loader").classList.contains("tour__content__meme")) {
document.getElementById("tour-loader").classList.remove("tour__content__meme");
document.getElementById("tour-loader").classList.add("tour__content__trends");
}
$("#fetch-claim-uri").val(""); // reset URL bar
$("#tour-url button").text("Tip");
if ($("#tour-url")[0].style.display === "none") $("#tour-url").show();
document.getElementById("fetch-claim-uri").value = ""; // reset URL bar
document.querySelector("#tour-url button").textContent = "Tip";
$(".tour__navigation__example").removeClass("active");
$(".tour__navigation__example:nth-child(3)").addClass("active");
if (document.getElementById("tour-url").style.display === "none")
document.getElementById("tour-url").removeAttribute("style");
$("#tour-loader").empty().show();
$("#tour-results").empty().show();
for (const example of document.querySelectorAll(".tour__navigation__example"))
example.classList.remove("active");
document.querySelector(".tour__navigation__example:nth-child(3)").classList.add("active");
document.getElementById("tour-loader").innerHTML = "";
document.getElementById("tour-results").innerHTML = "";
document.getElementById("tour-loader").removeAttribute("style");
document.getElementById("tour-results").removeAttribute("style");
send(JSON.stringify({
"message": `request for ${data.action}`
@ -321,8 +337,8 @@ const handleExamples = debounce(event => {
function initCanvas() { // eslint-disable-line
const canvas = document.getElementById("meme-canvas");
const canvasWidth = 400;
const canvasHeight = 300;
const canvasWidth = 400;
const ctx = canvas.getContext("2d");
const img = document.getElementById("base-image");
@ -336,16 +352,18 @@ function initCanvas() { // eslint-disable-line
ctx.strokeStyle = "black";
ctx.textAlign = "center";
ctx.textBaseline = "top";
ctx.strokeText($("#meme-top-line").val().toUpperCase(), canvasWidth / 2, 20);
ctx.strokeText($("#meme-bottom-line").val().toUpperCase(), canvasWidth / 2, (canvasHeight - 40));
ctx.fillText($("#meme-top-line").val().toUpperCase(), canvasWidth / 2, 20);
ctx.fillText($("#meme-bottom-line").val().toUpperCase(), canvasWidth / 2, (canvasHeight - 40));
ctx.strokeText(document.getElementById("meme-top-line").value.toUpperCase(), canvasWidth / 2, 20);
ctx.fillText(document.getElementById("meme-top-line").value.toUpperCase(), canvasWidth / 2, 20);
ctx.strokeText(document.getElementById("meme-bottom-line").value.toUpperCase(), canvasWidth / 2, (canvasHeight - 40));
ctx.fillText(document.getElementById("meme-bottom-line").value.toUpperCase(), canvasWidth / 2, (canvasHeight - 40));
}
function updateCanvas(imageSource) {
const canvas = document.getElementById("meme-canvas");
const canvasWidth = 400;
const canvasHeight = 300;
const canvasWidth = 400;
const ctx = canvas.getContext("2d");
const img = document.getElementById("base-image");
@ -356,8 +374,9 @@ function updateCanvas(imageSource) {
img.src = imageSource.src;
} ctx.drawImage(img, 0, 0, canvasWidth, canvasHeight, 0, 0, canvasWidth, canvasHeight);
ctx.strokeText($("#meme-top-line").val().toUpperCase(), canvasWidth / 2, 20);
ctx.strokeText($("#meme-bottom-line").val().toUpperCase(), canvasWidth / 2, (canvasHeight - 40));
ctx.fillText($("#meme-top-line").val().toUpperCase(), canvasWidth / 2, 20);
ctx.fillText($("#meme-bottom-line").val().toUpperCase(), canvasWidth / 2, (canvasHeight - 40));
ctx.strokeText(document.getElementById("meme-top-line").value.toUpperCase(), canvasWidth / 2, 20);
ctx.fillText(document.getElementById("meme-top-line").value.toUpperCase(), canvasWidth / 2, 20);
ctx.strokeText(document.getElementById("meme-bottom-line").value.toUpperCase(), canvasWidth / 2, (canvasHeight - 40));
ctx.fillText(document.getElementById("meme-bottom-line").value.toUpperCase(), canvasWidth / 2, (canvasHeight - 40));
}

View file

@ -25,34 +25,48 @@ function initializeWebSocketConnection() {
ws.onmessage = socket => {
const data = JSON.parse(socket.data);
switch (true) {
switch(true) {
case data.message === "show result":
if (!data.example) return;
document.querySelector(data.selector).innerHTML = data.html;
if (!document.querySelector(`[data-example="${data.example}"`).classList.contains("completed"))
document.getElementById("tour-example-description").classList.remove("success");
document.querySelector(`[data-example="${data.example}"`).classList.add("completed");
document.getElementById("tour-example-description").classList.add("success");
document.getElementById("tour-example-description").innerHTML =
document.querySelector(`[data-example="${data.example}"`).dataset.success;
if (document.getElementById("temp-loader"))
document.getElementById("temp-loader").style.display = "none";
if (document.querySelector(".tour"))
document.querySelector(".tour").classList.remove("waiting");
break;
case data.message === "updated html":
document.querySelector(data.selector).innerHTML = data.html;
document.getElementById("emailAddress").value = "";
document.getElementById("emailMessage").innerHTML = "";
// `data.example` is added when updating HTML.
// This is when the results of an example are sent to the client.
if (data.example) {
if (!document.querySelector(`[data-example="${data.example}"`).classList.contains("completed")) {
document.getElementById("tour-example-description").classList.remove("success");
}
if (data.example === 2) {
detectLanguageAndUpdate(); // eslint-disable-line
initCanvas(); // eslint-disable-line
document.querySelector(`[data-example="${data.example}"`).classList.add("completed");
document.getElementById("tour-example-description").classList.add("success");
document.getElementById("tour-example-description").innerHTML =
document.querySelector(`[data-example="${data.example}"`).dataset.success;
setTimeout(() => {
document.querySelector(".tour__content__meme__canvas__thumbnail").click();
}, 100);
}
// If `data.example` isn't found, reset the description area.
else {
if (document.getElementById("tour-example-description")) {
document.getElementById("tour-example-description").classList.remove("success");
if (document.getElementById("tour-example-description")) {
document.getElementById("tour-example-description").classList.remove("success");
document.getElementById("tour-example-description").innerHTML =
document.querySelector(".tour__navigation__example.active").dataset.description;
}
document.getElementById("tour-example-description").innerHTML =
document.querySelector(".tour__navigation__example.active").dataset.description;
}
if (document.getElementById("temp-loader"))
@ -60,6 +74,7 @@ function initializeWebSocketConnection() {
if (document.querySelector(".tour"))
document.querySelector(".tour").classList.remove("waiting");
break;
case data.message === "notification": // TODO: Make work with appending so multiple notifications can be sent

View file

@ -63,7 +63,7 @@ module.exports = exports = (data, socket) => {
body.description = dataDetails.description;
body.language = dataDetails.language;
body.license = dataDetails.license;
body.name = dataDetails.name.replace(/\s/g, "-") + randomString(10); // underscores are not allowed?
body.name = dataDetails.name + randomString(10); // underscores are not allowed?
body.nsfw = dataDetails.nsfw;
body.title = dataDetails.title;
@ -110,15 +110,29 @@ module.exports = exports = (data, socket) => {
return;
}
const renderedCode = prism.highlight(stringifyObject(publishResponse, { indent: " ", singleQuotes: false }), prism.languages.json, "json");
const renderedCode = prism.highlight(
stringifyObject(publishResponse, { indent: " ", singleQuotes: false }),
prism.languages.json,
"json"
);
let explorerNotice = "";
if (
publishResponse.result &&
publishResponse.result.claim_address
) explorerNotice = `
<p class="tour__description success">To see Proof of Work (lol) that your meme is on the LBRY blockchain, <a href="https://explorer.lbry.io/address/${publishResponse.result.claim_address}" rel="noopener noreferrer" target="_blank" title="Your meme, on our blockchain explorer">check it out</a> on our blockchain explorer! Please note that it may take a couple minutes for the transaction to be confirmed.</p><br/>
`;
return socket.send(JSON.stringify({
"example": data.example,
"html": raw(`
<h3>Response</h3>
${explorerNotice}
<pre><code class="language-json">${renderedCode}</code></pre>
`),
"message": "updated html",
"message": "show result",
"selector": `#example${data.example}-result`
}));
});
@ -151,7 +165,7 @@ module.exports = exports = (data, socket) => {
<h3>Response</h3>
<pre><code class="language-text">Tipping creators not in the whitelist for this example is not allowed.</code></pre>
`),
"message": "updated html",
"message": "show result",
"selector": `#example${data.example}-result`
}));
}
@ -162,6 +176,8 @@ module.exports = exports = (data, socket) => {
body.claim_id = claimAddress;
}
return new Promise((resolve, reject) => { // eslint-disable-line
request({
body: body,
@ -193,26 +209,31 @@ module.exports = exports = (data, socket) => {
return resolve(body.error);
}
/*
let explorerNotice = "";
if (
data.example === 3 &&
body.result &&
body.result.txid
) explorerNotice = `
<p>If you want proof of the tip you just gave on behalf of LBRY, <a href="https://explorer.lbry.io/tx/${body.result.txid}" target="_blank" title="Your tip, on our blockchain explorer" rel="noopener noreferrer">check it out</a> on our blockchain explorer!</p>
<p class="tour__description success">If you want proof of the tip you just gave on behalf of LBRY, <a href="https://explorer.lbry.io/tx/${body.result.txid}" rel="noopener noreferrer" target="_blank" title="Your tip, on our blockchain explorer">check it out</a> on our blockchain explorer! Please note that it may take a couple minutes for the transaction to be confirmed.</p><br/>
`;
*/
if (socket) {
const renderedCode = prism.highlight(stringifyObject(body, { indent: " ", singleQuotes: false }), prism.languages.json, "json");
const renderedCode = prism.highlight(
stringifyObject(body, { indent: " ", singleQuotes: false }),
prism.languages.json,
"json"
);
return socket.send(JSON.stringify({
"example": data.example,
"html": raw(`
<h3>Response</h3>
${explorerNotice}
<pre><code class="language-json">${renderedCode}</code></pre>
`),
"message": "updated html",
"message": "show result",
"selector": `#example${data.example}-result`
}));
}

View file

@ -45,7 +45,7 @@ if (typeof process.env.REDISCLOUD_URL !== "undefined") {
// P R O G R A M
function generateEvent(event) {
switch (event.type) {
switch(event.type) {
case "CommitCommentEvent":
return `
<strong><a
@ -289,7 +289,7 @@ function generateGitHubFeed(displayGitHubFeed) {
}
function generateUrl(type, event) {
switch (type) {
switch(type) {
case "actor":
return `https://github.com/${event.actor.display_login}`;

View file

@ -479,4 +479,8 @@
text-transform: uppercase;
}
}
a {
font-weight: 700;
}
}

View file

@ -143,9 +143,8 @@ function generateContent(exampleNumber, displayTrendingContent) {
const rawContentCollection = [];
const renderedContentCollection = [];
for (const url of approvedUrls) {
for (const url of approvedUrls)
rawContentCollection.push(fetchMetadata({ claim: url, method: "resolve", example: exampleNumber }));
}
return Promise.all(rawContentCollection).then(collection => {
for (const part of collection) {
@ -215,9 +214,8 @@ function generateMemeCreator(socket) {
const renderedImages = [];
for (const image of images) {
for (const image of images)
renderedImages.push(`<img alt="${image.alt}" class="tour__content__meme__canvas__thumbnail" src="${image.src}"/>`);
}
const memeCreator = html`
<div class="tour__content__meme__canvas">
@ -290,21 +288,10 @@ function generateMemeCreator(socket) {
<button data-action="upload image" class="__button-black" type="button">Submit</button>
</fieldset>
</form>
<script>
detectLanguageAndUpdate();
initCanvas();
document.getElementById("tour-example-description").innerHTML =
document.querySelector("[data-action='tour, example 2']").dataset.description;
setTimeout(() => {
document.querySelector(".tour__content__meme__canvas__thumbnail").click();
}, 100);
</script>
`;
return socket.send(JSON.stringify({
"example": 2,
"html": memeCreator,
"message": "updated html",
"selector": "#tour-loader"