From e2fb62c068077866ce819cf70f819b51b1ae9aa9 Mon Sep 17 00:00:00 2001 From: Mike Fix Date: Mon, 19 Aug 2019 17:19:07 -0700 Subject: [PATCH] fix forking snippet with no code --- components/EditorContainer.js | 7 ++----- lib/api.js | 8 +++++++- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/components/EditorContainer.js b/components/EditorContainer.js index 7837ec2..d10e687 100644 --- a/components/EditorContainer.js +++ b/components/EditorContainer.js @@ -3,7 +3,7 @@ import React from 'react' import Editor from './Editor' import Toasts from './Toasts' -import { THEMES, DEFAULT_CODE } from '../lib/constants' +import { THEMES } from '../lib/constants' import { updateRouteState } from '../lib/routing' import { getThemes, saveThemes, clearSettings, saveSettings } from '../lib/util' @@ -76,10 +76,7 @@ function EditorContainer(props) { updateRouteState(props.router, state) saveSettings(state) } else { - const updates = { - ...state, - code: state.code != null ? state.code : DEFAULT_CODE - } + const updates = state if (!snippet) { update(snippetId, updates).then(newSnippet => { if (newSnippet && newSnippet.id) { diff --git a/lib/api.js b/lib/api.js index 982ab0b..9309812 100644 --- a/lib/api.js +++ b/lib/api.js @@ -2,6 +2,8 @@ import axios from 'axios' import debounce from 'lodash.debounce' import ms from 'ms' +import { DEFAULT_CODE } from './constants' + import { fileToDataURL } from './util' export const client = axios.create({ @@ -80,7 +82,11 @@ function getSnippet(uid, { host } = {}) { }) } -function updateSnippet(uid, data) { +function updateSnippet(uid, state) { + const data = { + ...state, + code: state.code != null ? state.code : DEFAULT_CODE + } if (uid) { return client .patch(`/snippets/${uid}`, data)