Skip to content
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

fix eslint and prettier errors #216

Merged
merged 1 commit into from
Feb 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions web/src/activity-bar.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,19 @@ class ActivityBar extends Component {
let button;

if (activity.component) {
button = <activity.component key={activity.key} />
button = <activity.component key={activity.key} />;
} else {
button = <IconButton
key={activity.selector + activity.toggle}
action={() => this.props.buttonAction(activity)}
tooltipMessage={activity.tooltipMessage}
tooltipPosition={activity.tooltipPosition}
icon={activity.icon}
color="hsl(0, 0%, 59%)"
size="24"
/>
button = (
<IconButton
key={activity.selector + activity.toggle}
action={() => this.props.buttonAction(activity)}
tooltipMessage={activity.tooltipMessage}
tooltipPosition={activity.tooltipPosition}
icon={activity.icon}
color="hsl(0, 0%, 59%)"
size="24"
/>
);
}

if (activity.position && activity.position === 'lower') {
Expand Down
18 changes: 8 additions & 10 deletions web/src/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ function apiPath(p) {
export const DUST_CODE_RESOURCE = apiPath('dust/code');
export const DUST_AUDIO_RESOURCE = apiPath('dust/audio');
export const DUST_DATA_RESOURCE = apiPath('dust/data');
export const DUST_SOURCES_RESOURCE = apiPath('dust/data/sources')
export const DUST_CATALOGS_RESOURCE = apiPath('dust/data/catalogs')
export const DUST_SOURCES_RESOURCE = apiPath('dust/data/sources');
export const DUST_CATALOGS_RESOURCE = apiPath('dust/data/catalogs');

export const DUST_PROTECTED_RESOURCES = new Set([
DUST_AUDIO_RESOURCE,
Expand All @@ -20,9 +20,7 @@ export const DUST_PROTECTED_RESOURCES = new Set([
DUST_CATALOGS_RESOURCE,
]);

export const isProtectedResource = resource => (
DUST_PROTECTED_RESOURCES.has(resource)
);
export const isProtectedResource = resource => DUST_PROTECTED_RESOURCES.has(resource);

class API {
static siblingResourceForName(name, siblingResource, category = 'scripts') {
Expand Down Expand Up @@ -184,7 +182,7 @@ class API {

static updateCatalog(catalogURL, onSuccess, onFailure) {
const url = `${catalogURL}/update`;
fetch(url, {'method': 'POST'}).then(response => {
fetch(url, { method: 'POST' }).then(response => {
const cb = response.ok ? onSuccess : onFailure;
response.json().then(body => {
cb(body);
Expand Down Expand Up @@ -216,7 +214,7 @@ class API {
static installProject(catalogURL, name, onSuccess, onFailure) {
const encodedName = encodeURIComponent(name);
const url = `${catalogURL}/install/${encodedName}`;
fetch(url, {'method': 'POST'}).then(response => {
fetch(url, { method: 'POST' }).then(response => {
const cb = response.ok ? onSuccess : onFailure;
response.json().then(body => {
cb(body);
Expand All @@ -227,7 +225,7 @@ class API {
static installProjectFromURL(sourceURL, onSuccess, onFailure) {
const encodedURL = encodeURIComponent(sourceURL);
const url = `${API_ROOT}/project/install?url=${encodedURL}`;
fetch(url, {'method': 'POST'}).then(response => {
fetch(url, { method: 'POST' }).then(response => {
const cb = response.ok ? onSuccess : onFailure;
response.json().then(body => {
cb(body);
Expand All @@ -238,7 +236,7 @@ class API {
static updateProject(projectURL, onSuccess, onFailure) {
// FIXME: this really shouldn't be a GET verb
const url = `${projectURL}?update=`;
return fetch(url, {'method': 'GET'}).then(response => {
return fetch(url, { method: 'GET' }).then(response => {
const cb = response.ok ? onSuccess : onFailure;
response.json().then(body => {
cb(body);
Expand All @@ -247,7 +245,7 @@ class API {
}

static removeProject(projectURL, onSuccess, onFailure) {
fetch(projectURL, {'method': 'DELETE'}).then(response => {
fetch(projectURL, { method: 'DELETE' }).then(response => {
const cb = response.ok ? onSuccess : onFailure;
response.json().then(body => {
cb(body);
Expand Down
2 changes: 1 addition & 1 deletion web/src/api.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('siblingResourceForName', () => {
const r = api.siblingResourceForName('foo.lua', '/api/v1/scripts/one/two/three.lua');
expect(r).toEqual('/api/v1/scripts/one/two/foo.lua');
});
})
});

describe('fileFromResource', () => {
it('extracts basic path', () => {
Expand Down
2 changes: 1 addition & 1 deletion web/src/app.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { Component } from 'react';
import BoundWorkspace from './bound-workspace';
import BoundUrlHandler from './bound-url-handler'
import BoundUrlHandler from './bound-url-handler';
import activities from './activities';
import './app.css';
import './tool-tip.css';
Expand Down
6 changes: 4 additions & 2 deletions web/src/bound-edit-activity.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,9 @@ const mapDispatchToProps = dispatch => ({
dispatch(bufferSelect(resource));

const path = resourceToEditPath(resource);
path && dispatch(pushHistory(path));
if (path) {
dispatch(pushHistory(path));
}
},
bufferSave: (resource, code, completionCB = () => {}) => {
dispatch(bufferSave(resource, code, completionCB));
Expand All @@ -125,7 +127,7 @@ const mapDispatchToProps = dispatch => ({
if (file) {
if (file.includes('/lib/') || file.includes('/data/') || file.includes('/audio/')) {
console.log('files under /lib/, /data/, and /audio/ cannot be run as a script');
return undefined;
return;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eslint is expecting consistent return values, so we either need to explicitly return undefined in all code paths, or return void (which should end up being undefined anyway).

}
const cmd = `norns.script.load("${file}")`;
dispatch(replSend(MATRON_COMPONENT, cmd));
Expand Down
4 changes: 1 addition & 3 deletions web/src/bound-project-activity.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ import {
removeProject,
} from './model/project-actions';

import {
directoryRead,
} from './model/edit-actions';
import { directoryRead } from './model/edit-actions';

import { DUST_CODE_RESOURCE } from './api';

Expand Down
2 changes: 1 addition & 1 deletion web/src/bound-repl-activity.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const mapDispatchToProps = dispatch => ({
},
unitMapping: cb => {
dispatch(unitMapping(cb));
}
},
});

const BoundReplActivity = connect(mapStateToProps, mapDispatchToProps)(ReplActivity);
Expand Down
14 changes: 7 additions & 7 deletions web/src/bound-url-handler.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Component } from 'react';
import { connect } from 'react-redux';
import { bufferSelect, directoryReadRecursive } from './model/edit-actions'
import { isEditPath, pathToResource } from './url-utils'
import { bufferSelect, directoryReadRecursive } from './model/edit-actions';
import { isEditPath, pathToResource } from './url-utils';

// This might be better as a hook (not much of a class),
// This might be better as a hook (not much of a class),
// but they are only supported in react-redux ^7.1
class UrlHandler extends Component {
constructor(props) {
Expand Down Expand Up @@ -40,8 +40,8 @@ class UrlHandler extends Component {
const mapStateToProps = state => {
const { hash } = state.router.location;
return {
pathname: hash && hash[0] === '#' ? hash.substring(1) : ''
}
pathname: hash && hash[0] === '#' ? hash.substring(1) : '',
};
};

const mapDispatchToProps = dispatch => ({
Expand All @@ -50,8 +50,8 @@ const mapDispatchToProps = dispatch => ({
},
directoryReadRecursive: async resource => {
dispatch(directoryReadRecursive(resource));
}
},
});

const BoundUrlHandler = connect(mapStateToProps, mapDispatchToProps)(UrlHandler);
export default BoundUrlHandler;
export default BoundUrlHandler;
10 changes: 6 additions & 4 deletions web/src/bound-workspace.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@ const mapDispatchToProps = dispatch => ({
dispatch(replConnect(component, endpoint));
},
userDataList: () => {
dispatch(rootList(USER_DATA_PATH, () => {
// NB: this directory read is here to ensure that the dust/code directory is materialized ahead of any implicit "untitled.lua" buffer generation in order to ensure the implicity script lands in the code directory instead of the root directory.
dispatch(directoryRead(DUST_CODE_RESOURCE));
}));
dispatch(
rootList(USER_DATA_PATH, () => {
// NB: this directory read is here to ensure that the dust/code directory is materialized ahead of any implicit "untitled.lua" buffer generation in order to ensure the implicity script lands in the code directory instead of the root directory.
dispatch(directoryRead(DUST_CODE_RESOURCE));
}),
);
},
});

Expand Down
8 changes: 1 addition & 7 deletions web/src/components/badge.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
import React from 'react';
import './badge.css';

const Badge = (props) => {
return (
<span className='badge'>
{props.children}
</span>
);
}
const Badge = props => <span className="badge">{props.children}</span>;

export default Badge;
31 changes: 20 additions & 11 deletions web/src/components/catalog-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,31 @@ const CatalogList = props => {
const catalog = props.catalogs.get(name);
return (
<li key={name}>
<Catalog catalog={catalog} installedProjects={props.installedProjects} installAction={props.installAction} refreshAction={props.refreshAction} />
<Catalog
catalog={catalog}
installedProjects={props.installedProjects}
installAction={props.installAction}
refreshAction={props.refreshAction}
/>
</li>
);
});
return (
<div className='catalog-list-container'>
{catalogs.size ? (<TextButton
classes='catalog-refresh-all-button'
color='hsl(0, 0%, 45%)'
action={() => props.refreshAllAction(props.catalogSummary)}
>refresh all</TextButton>) : ''}
<ul className='catalog-list'>
{catalogs}
</ul>
<div className="catalog-list-container">
{catalogs.size ? (
<TextButton
classes="catalog-refresh-all-button"
color="hsl(0, 0%, 45%)"
action={() => props.refreshAllAction(props.catalogSummary)}
>
refresh all
</TextButton>
) : (
''
)}
<ul className="catalog-list">{catalogs}</ul>
</div>
);
};

export default CatalogList;
export default CatalogList;
56 changes: 25 additions & 31 deletions web/src/components/catalog.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,55 +9,49 @@ import ProjectControl from './project-control';

import './catalog.css';

const Catalog = (props) => {
const {catalog, installedProjects} = props;
const Catalog = props => {
const { catalog, installedProjects } = props;
const catalogURL = catalog.get('url');

const entries = catalog.get('entries').map(e => {
const projectName = e.get('project_name');
const projectURL = e.get('project_url');
const key = `${projectName}-${projectURL || ""}`; // to silence warnings
const key = `${projectName}-${projectURL || ''}`; // to silence warnings

return (
<li key={key}>
<ProjectControl>
<ProjectInfo project={e} />
{(installedProjects || []).indexOf(projectName) === -1 ? (
<TextButton
action={() => props.installAction(catalogURL, projectName)}
>
install
</TextButton>
) : (
<div className='catalog-installed-label'>
installed
</div>
)}
</ProjectControl>
<ProjectControl>
<ProjectInfo project={e} />
{(installedProjects || []).indexOf(projectName) === -1 ? (
<TextButton action={() => props.installAction(catalogURL, projectName)}>
install
</TextButton>
) : (
<div className="catalog-installed-label">installed</div>
)}
</ProjectControl>
</li>
);
});

return (
<div className='catalog-container'>
<div className='catalog-name'>
<div className="catalog-container">
<div className="catalog-name">
{catalog.get('name')}
<IconButton
tooltipMessage='update catalog'
tooltipPosition='right'
icon={ICONS['loop2']}
size='12'
padding='1'
color='hsl(0, 0%, 45%)'
dark={true}
tooltipMessage="update catalog"
tooltipPosition="right"
icon={ICONS.loop2}
size="12"
padding="1"
color="hsl(0, 0%, 45%)"
dark
action={() => props.refreshAction(catalogURL)}
/>
</div>
<ul className='catalog-entries'>
{entries}
</ul>
<ul className="catalog-entries">{entries}</ul>
</div>
);
}
};

export default Catalog;
export default Catalog;
16 changes: 6 additions & 10 deletions web/src/components/project-control.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,16 @@ import React from 'react';

import './project-control.css';

const ProjectControl = (props) => {
const ProjectControl = props => {
const summary = props.children[0];
const controls = props.children.slice(1);

return (
<div className='project-control'>
<div className='project-summary-container'>
{summary}
</div>
<div className='project-control-container'>
{controls}
</div>
<div className="project-control">
<div className="project-summary-container">{summary}</div>
<div className="project-control-container">{controls}</div>
</div>
)
);
};

export default ProjectControl;
export default ProjectControl;
Loading