From af0d48de72e3b3bee17c8488c25167fae649cd63 Mon Sep 17 00:00:00 2001 From: Pavel Djundik Date: Thu, 17 Oct 2019 17:17:02 +0300 Subject: [PATCH] Create InlineChannel component --- client/components/InlineChannel.vue | 34 +++++++++++++++++++++++++ client/js/libs/handlebars/parse.js | 11 +++----- client/js/lounge.js | 14 ---------- test/client/js/libs/handlebars/parse.js | 26 +++++++++---------- 4 files changed, 51 insertions(+), 34 deletions(-) create mode 100644 client/components/InlineChannel.vue diff --git a/client/components/InlineChannel.vue b/client/components/InlineChannel.vue new file mode 100644 index 00000000..6a0b072e --- /dev/null +++ b/client/components/InlineChannel.vue @@ -0,0 +1,34 @@ + + + diff --git a/client/js/libs/handlebars/parse.js b/client/js/libs/handlebars/parse.js index 9488c020..0d925622 100644 --- a/client/js/libs/handlebars/parse.js +++ b/client/js/libs/handlebars/parse.js @@ -10,6 +10,7 @@ const colorClass = require("./colorClass"); const emojiMap = require("../fullnamemap.json"); const LinkPreviewToggle = require("../../../components/LinkPreviewToggle.vue").default; const LinkPreviewFileSize = require("../../../components/LinkPreviewFileSize.vue").default; +const InlineChannel = require("../../../components/InlineChannel.vue").default; const emojiModifiersRegex = /[\u{1f3fb}-\u{1f3ff}]/gu; // Create an HTML `span` with styling information for a given fragment @@ -151,14 +152,10 @@ module.exports = function parse(createElement, text, message = undefined, networ ); } else if (textPart.channel) { return createElement( - "span", + InlineChannel, { - class: ["inline-channel"], - attrs: { - role: "button", - dir: "auto", - tabindex: 0, - "data-chan": textPart.channel, + props: { + channel: textPart.channel, }, }, fragments diff --git a/client/js/lounge.js b/client/js/lounge.js index 94fbee7e..396a22a6 100644 --- a/client/js/lounge.js +++ b/client/js/lounge.js @@ -45,20 +45,6 @@ window.vueMounted = () => { $(document.body).addClass("is-apple"); } - viewport.on("click", ".inline-channel", function() { - const name = $(this).attr("data-chan"); - const chan = utils.findCurrentNetworkChan(name); - - if (chan) { - $(`#sidebar .chan[data-id="${chan.id}"]`).trigger("click"); - } - - socket.emit("input", { - target: vueApp.activeChannel.channel.id, - text: "/join " + name, - }); - }); - const openWindow = function openWindow(e, {pushState, replaceHistory} = {}) { const self = $(this); const target = self.attr("data-target"); diff --git a/test/client/js/libs/handlebars/parse.js b/test/client/js/libs/handlebars/parse.js index b8bde3c9..c06833e1 100644 --- a/test/client/js/libs/handlebars/parse.js +++ b/test/client/js/libs/handlebars/parse.js @@ -30,7 +30,7 @@ describe("parse Handlebars helper", () => { { input: '#&">bug', expected: - '#&">bug', + '#&">bug', }, ]; @@ -184,21 +184,21 @@ describe("parse Handlebars helper", () => { { input: "#a", expected: - '' + + '' + "#a" + "", }, { input: "#test", expected: - '' + + '' + "#test" + "", }, { input: "#äöü", expected: - '' + + '' + "#äöü" + "", }, @@ -206,7 +206,7 @@ describe("parse Handlebars helper", () => { input: "inline #channel text", expected: "inline " + - '' + + '' + "#channel" + "" + " text", @@ -214,7 +214,7 @@ describe("parse Handlebars helper", () => { { input: "#1,000", expected: - '' + + '' + "#1,000" + "", }, @@ -222,7 +222,7 @@ describe("parse Handlebars helper", () => { input: "@#a", expected: "@" + - '' + + '' + "#a" + "", }, @@ -378,7 +378,7 @@ describe("parse Handlebars helper", () => { users: ["MaxLeiter, test"], input: "#test-channelMaxLeiter", expected: - '' + + '' + "#test-channelMaxLeiter" + "", }, @@ -414,7 +414,7 @@ describe("parse Handlebars helper", () => { { input: "\x02#\x038,9thelounge", expected: - '' + + '' + '#' + 'thelounge' + "", @@ -477,7 +477,7 @@ describe("parse Handlebars helper", () => { input: "#i❤️thelounge", // FIXME: Emoji in text should be `❤️`. See https://github.com/thelounge/thelounge/issues/1784 expected: - '#i❤️thelounge', + '#i❤️thelounge', }, ].forEach((item) => { // TODO: In Node v6+, use `{name, input, expected}` @@ -493,7 +493,7 @@ describe("parse Handlebars helper", () => { 'test \x0312#\x0312\x0312"te\x0312st\x0312\x0312\x0312\x0312\x0312\x0312\x0312\x0312\x0312\x0312\x0312a', expected: "test " + - '' + + '' + '#"testa' + "", }, @@ -554,7 +554,7 @@ describe("parse Handlebars helper", () => { expect(actual).to.equal( 'Url: http://example.com/path ' + - 'Channel: ##channel' + 'Channel: ##channel' ); }); @@ -563,7 +563,7 @@ describe("parse Handlebars helper", () => { const actual = getParsedMessageContents(input); expect(actual).to.equal( - '' + + '' + "#test-https://example.com" + "" );