Skip to content

Commit

Permalink
Auto-fix javascript to match Google style (#3)
Browse files Browse the repository at this point in the history
Google's style guide seemed the closest to the original, so I ran ESLint to standardize the code style
  • Loading branch information
landonepps committed Jun 12, 2023
1 parent 1ffc22a commit 562990f
Show file tree
Hide file tree
Showing 4 changed files with 186 additions and 156 deletions.
69 changes: 38 additions & 31 deletions api-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ class ApiClient {
this.config = new ElectronStore();
this.store = new JsonApiDataStore();
}

token() {
return this.config.get('token');
}

email() {
return this.config.get('email');
}

logIn(email, password, callback) {
var me = this;
const me = this;
this.config.set('email', email);
var req = https.request({
const req = https.request({
method: 'POST',
host: 'api.op1.fun',
path: '/v1/api_token',
Expand All @@ -28,53 +28,55 @@ class ApiClient {
'Accept': 'application/json'
}
}, function(res) {
var body = '';
res.on('data', function(d) { body += d; });
let body = '';
res.on('data', function(d) {
body += d;
});
res.on('end', function() {
var res = JSON.parse(body);
const res = JSON.parse(body);
if (res.api_token) {
me.config.set('token', res.api_token);
}
me.enableAppFeatureFlag();
callback(res);
});
});
req.write(JSON.stringify({ email: email, password: password }));
req.write(JSON.stringify({email: email, password: password}));
req.end();
}

enableAppFeatureFlag() {
this._post('feature_flags', { flags: { app: true } }, function() {});
this._post('feature_flags', {flags: {app: true}}, function() {});
}

logOut(callback) {
this.config.set('email', null);
this.config.set('token', null);
callback();
}

isLoggedIn() {
return (this.email() && this.token());
}

getPack(path, id, callback) {
var me = this;
const me = this;
this._get(path, function() {
var pack = me.store.find("packs", id);
const pack = me.store.find('packs', id);
callback(pack);
})
});
}

getPatch(path, id, callback) {
var me = this;
const me = this;
this._get(path, function() {
var patch = me.store.find("patches", id);
const patch = me.store.find('patches', id);
callback(patch);
})
});
}

_get(path, callback) {
var me = this;
const me = this;
return https.get({
host: 'api.op1.fun',
path: '/v1/' + path,
Expand All @@ -83,18 +85,19 @@ class ApiClient {
'X-User-Token': this.token()
}
}, function(res) {
var body = '';
res.on('data', function(d) { body += d; });
let body = '';
res.on('data', function(d) {
body += d;
});
res.on('end', function() {
me.store.sync(JSON.parse(body));
callback();
});
});
}

_post(path, data, callback) {
var me = this;
var req = https.request({
const req = https.request({
method: 'POST',
host: 'api.op1.fun',
path: '/v1/' + path,
Expand All @@ -105,9 +108,13 @@ class ApiClient {
'Accept': 'application/json'
}
}, function(res) {
var body = '';
res.on('data', function(d) { body += d; });
res.on('end', function() { callback(body); });
let body = '';
res.on('data', function(d) {
body += d;
});
res.on('end', function() {
callback(body);
});
});
console.log(data);
console.log(JSON.stringify(data));
Expand Down
126 changes: 73 additions & 53 deletions front-end.js
Original file line number Diff line number Diff line change
@@ -1,46 +1,64 @@
const { ipcRenderer, webFrame } = require('electron');
const {ipcRenderer, webFrame} = require('electron');
const ApiClient = require('./api-client');
const groupBy = require('./lib/group-by');
const api = new ApiClient();
const version = require('./package.json').version;

var app;

// disable zoom
webFrame.setVisualZoomLevelLimits(1, 1);

var categoryFilter = function (patches, category) {
var filtered = patches.filter((p) => { return p.category === category });
return filtered.sort(function (a, b) {
const categoryFilter = function(patches, category) {
const filtered = patches.filter((p) => {
return p.category === category;
});
return filtered.sort(function(a, b) {
// "/000" makes root level patches sort to the top
var _a = (a.packDir || "/000") + a.name.toLowerCase();
var _b = (b.packDir || "/000") + b.name.toLowerCase();
if (_a < _b) { return -1 } else if (_a > _b) { return 1 }
const _a = (a.packDir || '/000') + a.name.toLowerCase();
const _b = (b.packDir || '/000') + b.name.toLowerCase();
if (_a < _b) {
return -1;
} else if (_a > _b) {
return 1;
}
return 0;
});
}
};

app = new Vue({
const app = new Vue({
el: '#app',
data: {
patches: [],
downloading: false,
currentView: api.isLoggedIn() ? 'browser' : 'login',
currentListId: 'synth',
loginError: '',
isLoggedIn: api.isLoggedIn(),
connected: false
data: function() {
return {
patches: [],
downloading: false,
currentView: api.isLoggedIn() ? 'browser' : 'login',
currentListId: 'synth',
loginError: '',
isLoggedIn: api.isLoggedIn(),
connected: false
};
},
methods: {
goToView: function (e) { this.currentView = e },
showList: function (e) { this.currentListId = e },
setLoginError: function (error) { this.loginError = error; },
setLoggedInFalse: function () { this.isLoggedIn = false; },
setLoggedInTrue: function () { this.isLoggedIn = true; },
mountOP1: function () { ipcRenderer.send('mount-op1'); },
showPopupMenu: function () {
ipcRenderer.send('show-popup-menu', { view: this.currentView });
goToView: function(e) {
this.currentView = e;
},
showList: function(e) {
this.currentListId = e;
},
setLoginError: function(error) {
this.loginError = error;
},
setLoggedInFalse: function() {
this.isLoggedIn = false;
},
setLoggedInTrue: function() {
this.isLoggedIn = true;
},
mountOP1: function() {
ipcRenderer.send('mount-op1');
},
showPopupMenu: function() {
ipcRenderer.send('show-popup-menu', {view: this.currentView});
}
},
components: {

Expand All @@ -49,16 +67,16 @@ app = new Vue({
//
login: {
template: '#login',
data: function () {
data: function() {
return {
email: api.email(),
version: version,
password: ''
}
};
},
props: ['loginError', 'isLoggedIn'],
methods: {
logIn: function (e) {
logIn: function(e) {
api.logIn(this.email, this.password, (res) => {
if (res.error) {
this.$emit('error', res.error);
Expand All @@ -69,7 +87,7 @@ app = new Vue({
}
});
},
logOut: function () {
logOut: function() {
api.logOut(() => {
this.$emit('log-out');
});
Expand All @@ -84,38 +102,38 @@ app = new Vue({
template: '#browser',
props: ['patches', 'downloading', 'currentListId', 'connected'],
computed: {
filteredPatches: function () {
filteredPatches: function() {
return categoryFilter(this.patches, this.currentListId);
},
}
},
components: {
sideNav: {
template: '#side-nav',
props: ['patches', 'currentListId'],
data: function () {
data: function() {
return {
limits: { drum: 42, synth: 100, sampler: 42 },
}
limits: {drum: 42, synth: 100, sampler: 42}
};
},
computed: {
navItems: function () {
var sub = (cat) => {
return categoryFilter(this.patches, cat).length + " of " + this.limits[cat];
}
navItems: function() {
const sub = (cat) => {
return categoryFilter(this.patches, cat).length + ' of ' + this.limits[cat];
};
return [
{ id: 'synth', title: 'Synth', subtitle: sub('synth') },
{ id: 'drum', title: 'Drum', subtitle: sub('drum') },
{ id: 'sampler', title: 'Sampler', subtitle: sub('sampler') },
{id: 'synth', title: 'Synth', subtitle: sub('synth')},
{id: 'drum', title: 'Drum', subtitle: sub('drum')},
{id: 'sampler', title: 'Sampler', subtitle: sub('sampler')}
// { id: 'backups', title: 'Backups', subtitle: 'ok' },
]
];
}
}
},
contentArea: {
template: "<component :is='currentComponent' :patches='patches' :id='id'></component>",
template: '<component :is=\'currentComponent\' :patches=\'patches\' :id=\'id\'></component>',
props: ['currentListId', 'patches', 'id'],
computed: {
currentComponent: function () {
currentComponent: function() {
return (this.currentListId === 'backups') ? 'backups' : 'patch-list';
}
},
Expand All @@ -125,15 +143,17 @@ app = new Vue({
template: '#patch-list',
props: ['patches', 'id'],
computed: {
packs: function () { return groupBy(this.patches, 'packName') }
packs: function() {
return groupBy(this.patches, 'packName');
}
},
methods: {
showInFinder: function (e) {
showInFinder: function(e) {
if (e) {
ipcRenderer.send('show-in-finder', e.target.getAttribute("href"));
ipcRenderer.send('show-in-finder', e.target.getAttribute('href'));
}
},
},
}
}
},
backups: {
template: '#backups'
Expand Down Expand Up @@ -172,9 +192,9 @@ ipcRenderer.on('show-login', (event, data) => {

ipcRenderer.on('start-download', (event, message) => {
if (message['pack']) {
app.downloading = "Downloading Pack: " + message.pack.name;
app.downloading = 'Downloading Pack: ' + message.pack.name;
} else if (message['patch']) {
app.downloading = "Downloading Patch: " + message.patch.name;
app.downloading = 'Downloading Patch: ' + message.patch.name;
}
});

Expand Down
Loading

0 comments on commit 562990f

Please sign in to comment.