-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Custom Overlay Color Editor #34
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { appendFile, existsSync, writeFile } from 'fs'; | ||
import { resolve as resolvePath } from 'path'; | ||
|
||
const FILE_NAME = resolvePath(__dirname, '../src/assets/custom-styles.css'); | ||
|
||
export function write(data: any) { | ||
if (existsSync(FILE_NAME)) { | ||
return new Promise((resolve, reject) => { | ||
appendFile(FILE_NAME, data, (err: any) => { | ||
if (err) reject(err); | ||
resolve(data); | ||
}); | ||
}); | ||
} | ||
return new Promise((resolve, reject) => { | ||
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. The complexity is high with this one, probably going to refactor moving forward, but pull request to me makes it seems like this code is going into master. |
||
writeFile(FILE_NAME, data, (err: any) => { | ||
if (err) reject(err); | ||
resolve(data); | ||
}); | ||
}); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import express from 'express'; | ||
import * as files from '../files'; | ||
|
||
export const saveCssRoute = (req: express.Request, res: express.Response) => { | ||
const captains = console; | ||
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. This can use the log class |
||
captains.log(req.body); | ||
const { colorName, hueRotateDeg } = req.body; | ||
const data = formatForCSS(colorName, hueRotateDeg); | ||
files | ||
.write(data) | ||
.then((result: any) => { | ||
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. You should be able to type what the result is going to be. |
||
res.send({ message: 'Saved' }); | ||
}) | ||
.catch((error: any) => { | ||
res.status(500).send(error); | ||
}); | ||
}; | ||
|
||
function formatForCSS(colorName: string, hueRotateDeg: string) { | ||
return `.${colorName} {\n filter: hue-rotate(${hueRotateDeg}deg);\n}\n`; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,50 @@ | ||
$(document).ready(() => { | ||
let hueValue = 0; | ||
const captains = console; | ||
$('#get-overlay').click(() => { | ||
const url = $('#overlay-url').val(); | ||
$('#overlay-frame').attr('src', url); | ||
}); | ||
|
||
$('#increase-hue').click(() => { | ||
hueValue = hueValue < 361 ? (hueValue += 1) : 360; | ||
$('#container').css('filter', `hue-rotate(${hueValue}deg)`); | ||
let currentHueValue = $('#rotation').val(); | ||
const hueValue = currentHueValue < 361 ? (currentHueValue += 1) : 360; | ||
applyHue(hueValue); | ||
}); | ||
|
||
$('#decrease-hue').click(() => { | ||
hueValue = hueValue > 0 ? (hueValue -= 1) : 0; | ||
$('#container').css('filter', `hue-rotate(${hueValue}deg)`); | ||
let currentHueValue = $('#rotation').val(); | ||
const hueValue = currentHueValue > 0 ? (currentHueValue -= 1) : 0; | ||
applyHue(hueValue); | ||
}); | ||
|
||
$('#save-color').click(() => { | ||
const hueRotateDeg = $('#rotation').val(); | ||
const colorName = $('#color-name').val(); | ||
const data = JSON.stringify({ colorName, hueRotateDeg }); | ||
const requestOptions = { | ||
url: '/save', | ||
method: 'POST', | ||
data, | ||
contentType: 'application/json' | ||
}; | ||
request(requestOptions).done(result => captains.log(result)); | ||
}); | ||
|
||
$('#update-hue').click(() => { | ||
const hueRotateDeg = $('#rotation').val(); | ||
applyHue(hueRotateDeg); | ||
}); | ||
|
||
function applyHue(hueRotateDeg) { | ||
$('#container').css('filter', `hue-rotate(${hueRotateDeg}deg)`); | ||
} | ||
|
||
function request(requestOptions) { | ||
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. I like this |
||
return $.ajax(requestOptions) | ||
.done(result => result) | ||
.fail(error => { | ||
captains.error(error); | ||
return error; | ||
}); | ||
} | ||
}); |
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.
The name of this file can be more descriptive. I don't know the future of the file, but its explicitly writing to a custom styles class