0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2026-01-07 16:22:42 +00:00

Attempt to fix issue with saving Google brews.

This commit is contained in:
G.Ambatte
2021-06-28 19:37:06 +12:00
parent 63ea5a3e5f
commit 0cd4b730d7

View File

@@ -135,18 +135,18 @@ const NewPage = createClass({
console.log('saving new brew'); console.log('saving new brew');
const brew = this.state.brew; const saveBrew = this.state.brew;
// Split out CSS to Style if CSS codefence exists // Split out CSS to Style if CSS codefence exists
if(brew.text.startsWith('```css') && brew.text.indexOf('```\n\n') > 0) { if(saveBrew.text.startsWith('```css') && saveBrew.text.indexOf('```\n\n') > 0) {
const index = brew.text.indexOf('```\n\n'); const index = saveBrew.text.indexOf('```\n\n');
brew.style = `${brew.style ? `${brew.style}\n` : ''}${brew.text.slice(7, index - 1)}`; saveBrew.style = `${saveBrew.style ? `${saveBrew.style}\n` : ''}${saveBrew.text.slice(7, index - 1)}`;
brew.text = brew.text.slice(index + 5); saveBrew.text = saveBrew.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(brew) .send(saveBrew)
.catch((err)=>{ .catch((err)=>{
console.log(err.status === 401 console.log(err.status === 401
? 'Not signed in!' ? 'Not signed in!'
@@ -158,10 +158,10 @@ const NewPage = createClass({
const brew = res.body; const brew = res.body;
localStorage.removeItem(BREWKEY); localStorage.removeItem(BREWKEY);
localStorage.removeItem(STYLEKEY); localStorage.removeItem(STYLEKEY);
window.location = `/edit/${brew.googleId}${brew.editId}`; window.location = `/edit/${saveBrew.googleId}${saveBrew.editId}`;
} else { } else {
request.post('/api') request.post('/api')
.send(brew) .send(saveBrew)
.end((err, res)=>{ .end((err, res)=>{
if(err){ if(err){
this.setState({ this.setState({
@@ -173,7 +173,7 @@ const NewPage = createClass({
const brew = res.body; const brew = res.body;
localStorage.removeItem(BREWKEY); localStorage.removeItem(BREWKEY);
localStorage.removeItem(STYLEKEY); localStorage.removeItem(STYLEKEY);
window.location = `/edit/${brew.editId}`; window.location = `/edit/${saveBrew.editId}`;
}); });
} }
}, },