-
Notifications
You must be signed in to change notification settings - Fork 23
Save in gist #138
base: redux
Are you sure you want to change the base?
Save in gist #138
Changes from all commits
4d6711c
7f01cca
689e288
e4e126e
f2dd766
664d6c6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
module['exports'] = function myService (hook) { | ||
|
||
var github = require('octonode'); | ||
|
||
var filename = hook.params.filename; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. inline vars that are only used once |
||
var description = hook.params.description; | ||
var spec = hook.params.spec; | ||
|
||
var client = github.client(); | ||
|
||
var files = {}; | ||
|
||
files[filename] = {"content": spec}; | ||
|
||
var ghgist = client.gist(); | ||
|
||
ghgist.create({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fix indentation |
||
description: description, | ||
files: files, | ||
public: true | ||
}, function(err, g){ | ||
if (err) { | ||
return hook.res.json(err); | ||
} | ||
hook.res.json(g.files); | ||
|
||
}); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ export const TOGGLE_AUTO_PARSE = 'TOGGLE_AUTO_PARSE'; | |
export const CYCLE_RENDERER = 'CYCLE_RENDERER'; | ||
export const SHOW_COMPILED_VEGA_SPEC = 'SHOW_COMPILED_VEGA_SPEC' | ||
export const SET_MODE = 'SET_MODE' | ||
import { hashHistory } from 'react-router'; | ||
|
||
export function setMode (mode) { | ||
return { | ||
|
@@ -54,22 +55,67 @@ export function updateVegaLiteSpec (spec) { | |
}; | ||
}; | ||
|
||
export function setGistVegaSpec (gist, spec) { | ||
return { | ||
type: SET_GIST_VEGA_SPEC, | ||
gist: gist, | ||
spec: spec | ||
}; | ||
}; | ||
const getSpecFromGistURL = (gistUrl, mode, cb) => { | ||
let prefix = 'https://hook.io/tianyiii/vegaeditor/'; | ||
let hookUrl = prefix + mode + '/' | ||
+ gistUrl.substring(gistUrl.indexOf('.com/') + '.com/'.length); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is this doing? Could we use a regex instead? May be more readable. |
||
let suffix = hookUrl.substring(prefix.length); | ||
|
||
export function setGistVegaLiteSpec (gist, spec) { | ||
return { | ||
type: SET_GIST_VEGA_LITE_SPEC, | ||
gist: gist, | ||
spec: spec | ||
return fetch(hookUrl, { | ||
method: 'get', | ||
mode: 'cors' | ||
}) | ||
.then((response) => { | ||
if (response.status === 200) { | ||
return Promise.resolve(response); | ||
} else { | ||
return Promise.reject(new Error(response.statusText)); | ||
} | ||
}) | ||
.then((response) => { | ||
let arrayNames = suffix.split('/'); | ||
if (arrayNames.length < 3) { | ||
console.warn('invalid url'); | ||
return; | ||
} | ||
let username = arrayNames[1]; | ||
let id = arrayNames[2]; | ||
hashHistory.push('/gist/' + mode +'/' + username + '/' + id); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use string templates |
||
return response.text(); | ||
}) | ||
} | ||
|
||
export function setGistVegaLite(url) { | ||
return dispatch => { | ||
getSpecFromGistURL(url, 'vega-lite') | ||
.then((data) => { | ||
if (data['message'] !== 'Not Found') { | ||
dispatch({ | ||
type: SET_GIST_VEGA_LITE_SPEC, | ||
gist: url, | ||
spec: data | ||
}); | ||
} | ||
}); | ||
} | ||
} | ||
|
||
export function setGistVega (url) { | ||
return dispatch => { | ||
getSpecFromGistURL(url, 'vega') | ||
.then((data) => { | ||
if (data['message'] !== 'Not Found') { | ||
dispatch({ | ||
type: SET_GIST_VEGA_SPEC, | ||
gist: url, | ||
spec: data | ||
}); | ||
} | ||
}); | ||
}; | ||
}; | ||
|
||
|
||
export function toggleAutoParse () { | ||
return { | ||
type: TOGGLE_AUTO_PARSE | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -192,6 +192,21 @@ | |
color: white; | ||
} | ||
|
||
.gist-save-button:hover { | ||
background: rgb(92, 64, 141); | ||
color: white; | ||
} | ||
|
||
.gist-save-button { | ||
background: white; | ||
border: 1px solid #A9A9A9; | ||
cursor: pointer; | ||
width: 100%; | ||
height: 30px; | ||
font-size: 16px; | ||
outline: none; | ||
} | ||
|
||
.gist-text { | ||
margin-top: 25px; | ||
font-size: 12px; | ||
|
@@ -214,6 +229,31 @@ | |
padding: 5px; | ||
} | ||
|
||
.gist-save-input { | ||
display: inline; | ||
width: 100%; | ||
resize: none; | ||
font-size: 14px; | ||
margin-top: 5px; | ||
margin-bottom: 30px; | ||
padding: 5px; | ||
} | ||
|
||
.gist-filename { | ||
display: inline; | ||
} | ||
|
||
.gist-filename-text { | ||
font-size: 12px; | ||
font-style: italic; | ||
} | ||
|
||
.gist-filename-example { | ||
font-size: 12px; | ||
font-style: italic; | ||
color: rgb(6,69,173); | ||
} | ||
|
||
.customSubmenu { | ||
border-left: solid 1px #666; | ||
border-right: solid 1px #666; | ||
|
@@ -232,4 +272,33 @@ | |
|
||
#emptyButton:hover { | ||
border-bottom: solid 5px rgb(92, 64, 141); | ||
} | ||
|
||
|
||
|
||
@keyframes flickerAnimation { | ||
0% { opacity:1; } | ||
50% { opacity:0; } | ||
100% { opacity:1; } | ||
} | ||
@-o-keyframes flickerAnimation{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we need the prefixing or does some plugin take care of it? |
||
0% { opacity:1; } | ||
50% { opacity:0; } | ||
100% { opacity:1; } | ||
} | ||
@-moz-keyframes flickerAnimation{ | ||
0% { opacity:1; } | ||
50% { opacity:0; } | ||
100% { opacity:1; } | ||
} | ||
@-webkit-keyframes flickerAnimation{ | ||
0% { opacity:1; } | ||
50% { opacity:0; } | ||
100% { opacity:1; } | ||
} | ||
.save-gist-content { | ||
-webkit-animation: flickerAnimation 3s infinite; | ||
-moz-animation: flickerAnimation 3s infinite; | ||
-o-animation: flickerAnimation 3s infinite; | ||
animation: flickerAnimation 3s infinite; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could use const here.