Refactor client side commands
Co-Authored-By: Max Leiter <hello@maxleiter.com>
This commit is contained in:
parent
0a774758b9
commit
a54a726e93
@ -30,6 +30,7 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
const $ = require("jquery");
|
const $ = require("jquery");
|
||||||
|
const commands = require("../js/commands/index");
|
||||||
const socket = require("../js/socket");
|
const socket = require("../js/socket");
|
||||||
const Mousetrap = require("mousetrap");
|
const Mousetrap = require("mousetrap");
|
||||||
const {wrapCursor} = require("undate");
|
const {wrapCursor} = require("undate");
|
||||||
@ -121,11 +122,11 @@ export default {
|
|||||||
this.channel.pendingMessage = "";
|
this.channel.pendingMessage = "";
|
||||||
// resetInputHeight(input.get(0));
|
// resetInputHeight(input.get(0));
|
||||||
|
|
||||||
if (text.charAt(0) === "/") {
|
if (text[0] === "/") {
|
||||||
const args = text.substr(1).split(" ");
|
const args = text.substr(1).split(" ");
|
||||||
const cmd = args.shift().toLowerCase();
|
const cmd = args.shift().toLowerCase();
|
||||||
|
|
||||||
if (typeof utils.inputCommands[cmd] === "function" && utils.inputCommands[cmd](args)) {
|
if (commands[cmd] && commands[cmd].input(args)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
8
client/js/commands/collapse.js
Normal file
8
client/js/commands/collapse.js
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
|
const $ = require("jquery");
|
||||||
|
|
||||||
|
exports.input = function() {
|
||||||
|
$(".chan.active .toggle-button.toggle-preview.opened").click();
|
||||||
|
return true;
|
||||||
|
};
|
8
client/js/commands/expand.js
Normal file
8
client/js/commands/expand.js
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
|
const $ = require("jquery");
|
||||||
|
|
||||||
|
exports.input = function() {
|
||||||
|
$(".chan.active .toggle-button.toggle-preview:not(.opened)").click();
|
||||||
|
return true;
|
||||||
|
};
|
21
client/js/commands/index.js
Normal file
21
client/js/commands/index.js
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
|
// Taken from views/index.js
|
||||||
|
|
||||||
|
// This creates a version of `require()` in the context of the current
|
||||||
|
// directory, so we iterate over its content, which is a map statically built by
|
||||||
|
// Webpack.
|
||||||
|
// Second argument says it's recursive, third makes sure we only load javascript.
|
||||||
|
const commands = require.context("./", true, /\.js$/);
|
||||||
|
|
||||||
|
module.exports = commands.keys().reduce((acc, path) => {
|
||||||
|
const command = path.substring(2, path.length - 3);
|
||||||
|
|
||||||
|
if (command === "index") {
|
||||||
|
return acc;
|
||||||
|
}
|
||||||
|
|
||||||
|
acc[command] = commands(path);
|
||||||
|
|
||||||
|
return acc;
|
||||||
|
}, {});
|
26
client/js/commands/join.js
Normal file
26
client/js/commands/join.js
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
|
const $ = require("jquery");
|
||||||
|
|
||||||
|
exports.input = function(args) {
|
||||||
|
console.log(args);
|
||||||
|
const channel = args[0];
|
||||||
|
const utils = require("../utils");
|
||||||
|
const socket = require("../socket");
|
||||||
|
const {vueApp} = require("../vue");
|
||||||
|
|
||||||
|
if (channel) {
|
||||||
|
const chan = utils.findCurrentNetworkChan(channel);
|
||||||
|
|
||||||
|
if (chan) {
|
||||||
|
$(`#sidebar .chan[data-id="${chan.id}"]`).trigger("click");
|
||||||
|
}
|
||||||
|
} else if (vueApp.activeChannel.channel.type === "channel") {
|
||||||
|
socket.emit("input", {
|
||||||
|
target: vueApp.activeChannel.channel.id,
|
||||||
|
text: `/join ${vueApp.activeChannel.channel.name}`,
|
||||||
|
});
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
};
|
@ -11,7 +11,6 @@ var lastMessageId = -1; // eslint-disable-line no-var
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
// Same value as media query in CSS that forces sidebars to become overlays
|
// Same value as media query in CSS that forces sidebars to become overlays
|
||||||
mobileViewportPixels: 768,
|
mobileViewportPixels: 768,
|
||||||
inputCommands: {collapse, expand, join},
|
|
||||||
findCurrentNetworkChan,
|
findCurrentNetworkChan,
|
||||||
serverHash,
|
serverHash,
|
||||||
lastMessageId,
|
lastMessageId,
|
||||||
@ -58,28 +57,6 @@ function scrollIntoViewNicely(el) {
|
|||||||
el.scrollIntoView({block: "center", inline: "nearest"});
|
el.scrollIntoView({block: "center", inline: "nearest"});
|
||||||
}
|
}
|
||||||
|
|
||||||
function collapse() {
|
|
||||||
$(".chan.active .toggle-button.toggle-preview.opened").click();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
function expand() {
|
|
||||||
$(".chan.active .toggle-button.toggle-preview:not(.opened)").click();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
function join(args) {
|
|
||||||
const channel = args[0];
|
|
||||||
|
|
||||||
if (channel) {
|
|
||||||
const chan = findCurrentNetworkChan(channel);
|
|
||||||
|
|
||||||
if (chan) {
|
|
||||||
$(`#sidebar .chan[data-id="${chan.id}"]`).trigger("click");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const favicon = $("#favicon");
|
const favicon = $("#favicon");
|
||||||
|
|
||||||
function toggleNotificationMarkers(newState) {
|
function toggleNotificationMarkers(newState) {
|
||||||
|
Loading…
Reference in New Issue
Block a user