fix forking snippet with no code

main
Mike Fix 5 years ago
parent da5c77b0e1
commit e2fb62c068

@ -3,7 +3,7 @@ import React from 'react'
import Editor from './Editor' import Editor from './Editor'
import Toasts from './Toasts' import Toasts from './Toasts'
import { THEMES, DEFAULT_CODE } from '../lib/constants' import { THEMES } from '../lib/constants'
import { updateRouteState } from '../lib/routing' import { updateRouteState } from '../lib/routing'
import { getThemes, saveThemes, clearSettings, saveSettings } from '../lib/util' import { getThemes, saveThemes, clearSettings, saveSettings } from '../lib/util'
@ -76,10 +76,7 @@ function EditorContainer(props) {
updateRouteState(props.router, state) updateRouteState(props.router, state)
saveSettings(state) saveSettings(state)
} else { } else {
const updates = { const updates = state
...state,
code: state.code != null ? state.code : DEFAULT_CODE
}
if (!snippet) { if (!snippet) {
update(snippetId, updates).then(newSnippet => { update(snippetId, updates).then(newSnippet => {
if (newSnippet && newSnippet.id) { if (newSnippet && newSnippet.id) {

@ -2,6 +2,8 @@ import axios from 'axios'
import debounce from 'lodash.debounce' import debounce from 'lodash.debounce'
import ms from 'ms' import ms from 'ms'
import { DEFAULT_CODE } from './constants'
import { fileToDataURL } from './util' import { fileToDataURL } from './util'
export const client = axios.create({ 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) { if (uid) {
return client return client
.patch(`/snippets/${uid}`, data) .patch(`/snippets/${uid}`, data)

Loading…
Cancel
Save