From 6309ec0bfafcf5fd0c18b72a2fc9b9b8a073e9df Mon Sep 17 00:00:00 2001 From: Rodrigo Kuerten Date: Sat, 24 Oct 2020 16:59:26 -0300 Subject: [PATCH 1/4] Updated makeBold and makeItalic functions to center cursor when selection is empty --- shared/naturalcrit/codeEditor/codeEditor.jsx | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/shared/naturalcrit/codeEditor/codeEditor.jsx b/shared/naturalcrit/codeEditor/codeEditor.jsx index 26ec17be5..e29c561bd 100644 --- a/shared/naturalcrit/codeEditor/codeEditor.jsx +++ b/shared/naturalcrit/codeEditor/codeEditor.jsx @@ -45,12 +45,24 @@ const CodeEditor = createClass({ makeBold : function() { const selection = this.codeMirror.getSelection(); - this.codeMirror.replaceSelection(`**${selection}**`, 'around'); + if (selection.length === 0){ + this.codeMirror.replaceSelection(`**${selection}**`, 'around'); + let cursor = this.codeMirror.getCursor(); + this.codeMirror.setCursor({ line: cursor.line, ch: cursor.ch - 2 }); + } else { + this.codeMirror.replaceSelection(`**${selection}**`, 'around'); + } }, makeItalic : function() { const selection = this.codeMirror.getSelection(); - this.codeMirror.replaceSelection(`*${selection}*`, 'around'); + if (selection.length === 0){ + this.codeMirror.replaceSelection(`*${selection}*`, 'around'); + let cursor = this.codeMirror.getCursor(); + this.codeMirror.setCursor({ line: cursor.line, ch: cursor.ch - 1 }); + } else { + this.codeMirror.replaceSelection(`*${selection}*`, 'around'); + } }, componentWillReceiveProps : function(nextProps){ From b908cd7cbdf54d48f2849f41c72f63400e5a557e Mon Sep 17 00:00:00 2001 From: Rodrigo Kuerten Date: Sun, 25 Oct 2020 13:52:02 -0300 Subject: [PATCH 2/4] Changed page title to show homebrew title whenever possible --- client/template.js | 8 ++++---- server.js | 34 +++++++++++++++++----------------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/client/template.js b/client/template.js index d797c61b1..de046a3ee 100644 --- a/client/template.js +++ b/client/template.js @@ -1,5 +1,5 @@ -module.exports = async (name, props={})=>{ - return ` +module.exports = async(name, title = "", props = {}) => { + return ` @@ -7,7 +7,7 @@ module.exports = async (name, props={})=>{ - The Homebrewery - NaturalCrit + ${title.length ? title + " - The Homebrewery": "The Homebrewery - NaturalCrit"}
${require(`../build/${name}/ssr.js`)(props)}
@@ -16,4 +16,4 @@ module.exports = async (name, props={})=>{ `; -}; +}; \ No newline at end of file diff --git a/server.js b/server.js index a268a3219..9906e1918 100644 --- a/server.js +++ b/server.js @@ -208,23 +208,23 @@ app.get('/source/:id', (req, res)=>{ //Render the page //const render = require('.build/render'); const templateFn = require('./client/template.js'); -app.use((req, res)=>{ - const props = { - version : require('./package.json').version, - url : req.originalUrl, - welcomeText : welcomeText, - changelog : changelogText, - brew : req.brew, - brews : req.brews, - googleBrews : req.googleBrews, - account : req.account, - }; - templateFn('homebrew', props) - .then((page)=>{res.send(page);}) - .catch((err)=>{ - console.log(err); - return res.sendStatus(500); - }); +app.use((req, res) => { + const props = { + version: require('./package.json').version, + url: req.originalUrl, + welcomeText: welcomeText, + changelog: changelogText, + brew: req.brew, + brews: req.brews, + googleBrews: req.googleBrews, + account: req.account, + }; + templateFn('homebrew', title = req.brew ? req.brew.title : "", props) + .then((page) => { res.send(page); }) + .catch((err) => { + console.log(err); + return res.sendStatus(500); + }); }); From af4ec3d096345d758539ef86e8d8293e7ca30b10 Mon Sep 17 00:00:00 2001 From: Rodrigo Kuerten Date: Sun, 25 Oct 2020 14:13:23 -0300 Subject: [PATCH 3/4] Added back the original codeEditor file --- shared/naturalcrit/codeEditor/codeEditor.jsx | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/shared/naturalcrit/codeEditor/codeEditor.jsx b/shared/naturalcrit/codeEditor/codeEditor.jsx index e29c561bd..26ec17be5 100644 --- a/shared/naturalcrit/codeEditor/codeEditor.jsx +++ b/shared/naturalcrit/codeEditor/codeEditor.jsx @@ -45,24 +45,12 @@ const CodeEditor = createClass({ makeBold : function() { const selection = this.codeMirror.getSelection(); - if (selection.length === 0){ - this.codeMirror.replaceSelection(`**${selection}**`, 'around'); - let cursor = this.codeMirror.getCursor(); - this.codeMirror.setCursor({ line: cursor.line, ch: cursor.ch - 2 }); - } else { - this.codeMirror.replaceSelection(`**${selection}**`, 'around'); - } + this.codeMirror.replaceSelection(`**${selection}**`, 'around'); }, makeItalic : function() { const selection = this.codeMirror.getSelection(); - if (selection.length === 0){ - this.codeMirror.replaceSelection(`*${selection}*`, 'around'); - let cursor = this.codeMirror.getCursor(); - this.codeMirror.setCursor({ line: cursor.line, ch: cursor.ch - 1 }); - } else { - this.codeMirror.replaceSelection(`*${selection}*`, 'around'); - } + this.codeMirror.replaceSelection(`*${selection}*`, 'around'); }, componentWillReceiveProps : function(nextProps){ From 8add76fb5028dfe171907025360caf6dc8503843 Mon Sep 17 00:00:00 2001 From: Trevor Buckner Date: Mon, 26 Oct 2020 13:27:37 -0400 Subject: [PATCH 4/4] Linting --- client/template.js | 6 +++--- server.js | 32 ++++++++++++++++---------------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/client/template.js b/client/template.js index de046a3ee..fec379b9d 100644 --- a/client/template.js +++ b/client/template.js @@ -1,5 +1,5 @@ -module.exports = async(name, title = "", props = {}) => { - return ` +module.exports = async(name, title = '', props = {})=>{ + return ` @@ -7,7 +7,7 @@ module.exports = async(name, title = "", props = {}) => { - ${title.length ? title + " - The Homebrewery": "The Homebrewery - NaturalCrit"} + ${title.length ? `${title} - The Homebrewery`: 'The Homebrewery - NaturalCrit'}
${require(`../build/${name}/ssr.js`)(props)}
diff --git a/server.js b/server.js index 9906e1918..d0c77528f 100644 --- a/server.js +++ b/server.js @@ -208,22 +208,22 @@ app.get('/source/:id', (req, res)=>{ //Render the page //const render = require('.build/render'); const templateFn = require('./client/template.js'); -app.use((req, res) => { - const props = { - version: require('./package.json').version, - url: req.originalUrl, - welcomeText: welcomeText, - changelog: changelogText, - brew: req.brew, - brews: req.brews, - googleBrews: req.googleBrews, - account: req.account, - }; - templateFn('homebrew', title = req.brew ? req.brew.title : "", props) - .then((page) => { res.send(page); }) - .catch((err) => { - console.log(err); - return res.sendStatus(500); +app.use((req, res)=>{ + const props = { + version : require('./package.json').version, + url : req.originalUrl, + welcomeText : welcomeText, + changelog : changelogText, + brew : req.brew, + brews : req.brews, + googleBrews : req.googleBrews, + account : req.account, + }; + templateFn('homebrew', title = req.brew ? req.brew.title : '', props) + .then((page)=>{ res.send(page); }) + .catch((err)=>{ + console.log(err); + return res.sendStatus(500); }); });