0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2026-01-05 03:42:38 +00:00

Merge branch 'master' into pr/1401

This commit is contained in:
Trevor Buckner
2021-06-25 00:03:49 -04:00
4 changed files with 28 additions and 27 deletions

View File

@@ -3,17 +3,26 @@ const React = require('react');
const createClass = require('create-react-class'); const createClass = require('create-react-class');
const _ = require('lodash'); const _ = require('lodash');
const cx = require('classnames'); const cx = require('classnames');
const dedent = require('dedent-tabs').default;
const CodeEditor = require('naturalcrit/codeEditor/codeEditor.jsx'); const CodeEditor = require('naturalcrit/codeEditor/codeEditor.jsx');
const SnippetBar = require('./snippetbar/snippetbar.jsx'); const SnippetBar = require('./snippetbar/snippetbar.jsx');
const MetadataEditor = require('./metadataEditor/metadataEditor.jsx'); const MetadataEditor = require('./metadataEditor/metadataEditor.jsx');
const SNIPPETBAR_HEIGHT = 25;
const DEFAULT_STYLE_TEXT = dedent`
/*=======--- Example CSS styling ---=======*/
/* Any CSS here will apply to your document! */
.myExampleClass {
color: black;
}`;
const splice = function(str, index, inject){ const splice = function(str, index, inject){
return str.slice(0, index) + inject + str.slice(index); return str.slice(0, index) + inject + str.slice(index);
}; };
const SNIPPETBAR_HEIGHT = 25;
const Editor = createClass({ const Editor = createClass({
getDefaultProps : function() { getDefaultProps : function() {
@@ -176,7 +185,7 @@ const Editor = createClass({
return <CodeEditor key='style' return <CodeEditor key='style'
ref='codeEditor' ref='codeEditor'
language='css' language='css'
value={this.props.brew.style} value={this.props.brew.style ?? DEFAULT_STYLE_TEXT}
onChange={this.props.onStyleChange} />; onChange={this.props.onStyleChange} />;
} }
if(this.isMeta()){ if(this.isMeta()){

View File

@@ -4,7 +4,6 @@ const React = require('react');
const createClass = require('create-react-class'); const createClass = require('create-react-class');
const _ = require('lodash'); const _ = require('lodash');
const request = require('superagent'); const request = require('superagent');
const dedent = require('dedent-tabs').default;
const Markdown = require('naturalcrit/markdown.js'); const Markdown = require('naturalcrit/markdown.js');
@@ -26,14 +25,7 @@ const NewPage = createClass({
getDefaultProps : function() { getDefaultProps : function() {
return { return {
brew : { brew : {
text : '', text : '',
style : dedent`
/*=======--- Example CSS styling ---=======*/
/* Any CSS here will apply to your document! */
.myExampleClass {
color: black;
}`,
shareId : null, shareId : null,
editId : null, editId : null,
createdAt : null, createdAt : null,
@@ -54,7 +46,6 @@ const NewPage = createClass({
return { return {
brew : { brew : {
text : this.props.brew.text || '', text : this.props.brew.text || '',
style : this.props.brew.style || '',
gDrive : false, gDrive : false,
title : this.props.brew.title || '', title : this.props.brew.title || '',
description : this.props.brew.description || '', description : this.props.brew.description || '',
@@ -145,10 +136,18 @@ const NewPage = createClass({
console.log('saving new brew'); console.log('saving new brew');
const brew = this.state.brew;
// Split out CSS to Style if CSS codefence exists
if(brew.text.startsWith('```css') && brew.text.indexOf('```\n\n') > 0) {
const index = brew.text.indexOf('```\n\n');
brew.style = `${brew.style ? `${brew.style}\n` : ''}${brew.text.slice(7, index - 1)}`;
brew.text = brew.text.slice(index + 5);
};
if(this.state.saveGoogle) { if(this.state.saveGoogle) {
const res = await request const res = await request
.post('/api/newGoogle/') .post('/api/newGoogle/')
.send(this.state.brew) .send(brew)
.catch((err)=>{ .catch((err)=>{
console.log(err.status === 401 console.log(err.status === 401
? 'Not signed in!' ? 'Not signed in!'
@@ -163,7 +162,7 @@ const NewPage = createClass({
window.location = `/edit/${brew.googleId}${brew.editId}`; window.location = `/edit/${brew.googleId}${brew.editId}`;
} else { } else {
request.post('/api') request.post('/api')
.send(this.state.brew) .send(brew)
.end((err, res)=>{ .end((err, res)=>{
if(err){ if(err){
this.setState({ this.setState({

View File

@@ -9,7 +9,6 @@ const GoogleActions = require('./server/googleActions.js');
const serveCompressedStaticAssets = require('./server/static-assets.mv.js'); const serveCompressedStaticAssets = require('./server/static-assets.mv.js');
const sanitizeFilename = require('sanitize-filename'); const sanitizeFilename = require('sanitize-filename');
const asyncHandler = require('express-async-handler'); const asyncHandler = require('express-async-handler');
const dedent = require('dedent-tabs').default;
const brewAccessTypes = ['edit', 'share', 'raw']; const brewAccessTypes = ['edit', 'share', 'raw'];
@@ -37,14 +36,6 @@ const getBrewFromId = asyncHandler(async (id, accessType)=>{
const index = brew.text.indexOf('```\n\n'); const index = brew.text.indexOf('```\n\n');
brew.style = brew.text.slice(7, index - 1); brew.style = brew.text.slice(7, index - 1);
brew.text = brew.text.slice(index + 5); brew.text = brew.text.slice(index + 5);
} else {
brew.style = dedent`
/*=======--- Example CSS styling ---=======*/
/* Any CSS here will apply to your document! */
.myExampleClass {
color: black;
}`;
} }
return brew; return brew;
}); });

View File

@@ -20,10 +20,12 @@ const getGoodBrewTitle = (text)=>{
}; };
const mergeBrewText = (text, style)=>{ const mergeBrewText = (text, style)=>{
text = `\`\`\`css\n` + if(typeof style !== 'undefined') {
`${style}\n` + text = `\`\`\`css\n` +
`\`\`\`\n\n` + `${style}\n` +
`${text}`; `\`\`\`\n\n` +
`${text}`;
}
return text; return text;
}; };