Skip to content

Commit

Permalink
Merge pull request #4 from getflywheel/BMO/LOC-1313-refactor
Browse files Browse the repository at this point in the history
LOC-1313 Local Lightning Refactor
  • Loading branch information
Ben Moore authored Oct 21, 2019
2 parents 00aac4f + a16fc2d commit b9dbcc9
Show file tree
Hide file tree
Showing 6 changed files with 824 additions and 2,490 deletions.
29 changes: 15 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "local-addon-notes",
"productName": "Notes",
"version": "1.0.2",
"version": "1.1.2",
"author": "Clay Griffiths",
"keywords": [
"local-addon"
Expand All @@ -21,32 +21,33 @@
},
"license": "MIT",
"scripts": {
"build": "babel src -d lib",
"watch": "yarn run build --watch",
"prepare": "npm run build"
"build": "tsc",
"watch": "yarn run build --watch"
},
"devDependencies": {
"@babel/cli": "^7.2.0",
"@babel/core": "^7.2.0",
"@babel/plugin-proposal-class-properties": "^7.2.0",
"@babel/preset-env": "^7.2.0",
"@babel/preset-react": "^7.0.0",
"@getflywheel/eslint-config-local": "1.0.4",
"babel-eslint": "^10.0.1",
"@getflywheel/local": "^5.1.0-alpha.3",
"@types/classnames": "^2.2.9",
"@types/dateformat": "^3.0.1",
"@types/node": "^12.7.12",
"eslint": "^5.0.0",
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-react": "^7.11.1"
"eslint-plugin-react": "^7.11.1",
"typescript": "^3.6.4"
},
"peerDependencies": {
"react": ">= 16.4.0",
"react-dom": ">= 16.4.0",
"react-router-dom": "^4.3.1"
},
"dependencies": {
"@getflywheel/local-components": "^6.1.3",
"@getflywheel/local-components": "^11.0.0",
"classnames": "^2.2.6",
"dateformat": "^3.0.3",
"prop-types": "^15.6.2"
"prop-types": "^15.6.2",
"react": "^16.10.2",
"react-dom": "^16.10.2",
"react-router-dom": "^5.1.2"
},
"bundledDependencies": [
"classnames",
Expand All @@ -55,6 +56,6 @@
"prop-types"
],
"engines": {
"local-by-flywheel": "^3.0.0"
"local-by-flywheel": "^5.0.0"
}
}
51 changes: 25 additions & 26 deletions src/Notes.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import React, { Component, Fragment } from 'react';
import Note from './Note';
import classnames from 'classnames';
import { ipcRenderer } from 'electron';
import confirm from 'local/renderer/confirm';
import { confirm } from '@getflywheel/local/renderer';
import path from 'path';

export default class Notes extends Component {

constructor (props) {
constructor(props) {

super(props);

Expand All @@ -36,7 +36,7 @@ export default class Notes extends Component {

}

componentDidUpdate (previousProps) {
componentDidUpdate(previousProps) {

if (previousProps.site.id !== this.props.site.id) {
this.setState({
Expand All @@ -46,11 +46,11 @@ export default class Notes extends Component {

}

syncNotesToSite () {
syncNotesToSite() {
ipcRenderer.send('update-site-notes', this.props.site.id, this.state.notes);
}

fetchSiteNotes () {
fetchSiteNotes() {

const notes = this.props.site.notes;

Expand All @@ -70,7 +70,7 @@ export default class Notes extends Component {

}

addNote (body) {
addNote(body) {

const notes = this.state.notes.concat([{
date: new Date(),
Expand All @@ -86,7 +86,7 @@ export default class Notes extends Component {

}

openAddNew () {
openAddNew() {

this.setState({
addNewOpen: true,
Expand All @@ -96,7 +96,7 @@ export default class Notes extends Component {

}

toggleAddNew () {
toggleAddNew() {

if (this.state.addNewOpen) {
return this.setState({
Expand All @@ -108,13 +108,13 @@ export default class Notes extends Component {

}

onTextareaChange (event) {
onTextareaChange(event) {
this.setState({
textareaValue: event.target.value,
});
}

onTextareaKeyPress (event) {
onTextareaKeyPress(event) {

if (event.key !== 'Enter' || event.altKey || event.shiftKey) {
return;
Expand All @@ -126,7 +126,7 @@ export default class Notes extends Component {

}

onDeleteNote (note) {
onDeleteNote(note) {

confirm({
title: 'Are you sure you want to delete this note?',
Expand All @@ -149,7 +149,7 @@ export default class Notes extends Component {

}

onPinNote (note) {
onPinNote(note) {

const notes = this.state.notes;
const noteIndex = this.state.notes.indexOf(note);
Expand All @@ -166,7 +166,7 @@ export default class Notes extends Component {

}

getNotesInOrder () {
getNotesInOrder() {

const notes = this.state.notes.slice(0);

Expand All @@ -186,48 +186,48 @@ export default class Notes extends Component {

}

renderNotes () {
renderNotes() {

if (!this.state.notes || !this.state.notes.length) {
return !this.state.addNewOpen && <EmptyArea border={false}>
No notes added<br/>
to this site<br/><br/>
No notes added<br />
to this site<br /><br />
<Button className="--GrayOutline" onClick={this.openAddNew}>+ Add Note</Button>
</EmptyArea>;
}

return this.getNotesInOrder().map((note) => (
<Note key={note.date.toJSON()} date={note.date} body={note.body}
pinned={note.pinned} onDelete={() => this.onDeleteNote(note)} onPin={() => this.onPinNote(note)}/>
pinned={note.pinned} onDelete={() => this.onDeleteNote(note)} onPin={() => this.onPinNote(note)} />
));

}

pinnedNotesCount () {
pinnedNotesCount() {
return this.state.notes.filter((note) => note.pinned).length;
}

renderButtons () {
renderButtons() {

return <Fragment>
<span onClick={() => this.setState({ promotePinned: !this.state.promotePinned })}
className={classnames('PromotePinned', { '--Enabled': this.state.promotePinned })}>
className={classnames('PromotePinned', { '--Enabled': this.state.promotePinned })}>
<svg>
<use href={`file://${path.resolve(__filename, '../../assets/pin.svg')}#pin`}/>
<use href={`file://${path.resolve(__filename, '../../assets/pin.svg')}#pin`} />
</svg>
{this.pinnedNotesCount() ? <strong>{this.pinnedNotesCount()}</strong> : ''}
</span>

<span onClick={this.toggleAddNew} className="InnerPaneSidebarHeaderButtons_Add">
<svg viewBox="0 0 24 24">
<use href={`file://${path.resolve(__filename, '../../assets/add.svg')}#add`}/>
<use href={`file://${path.resolve(__filename, '../../assets/add.svg')}#add`} />
</svg>
</span>
</Fragment>;

}

render () {
render() {

return <InnerPaneSidebar className={classnames({ '__AddNewOpen': this.state.addNewOpen })}>
<InnerPaneSidebarHeader title="Notes">
Expand All @@ -236,8 +236,8 @@ export default class Notes extends Component {

<InnerPaneSidebarAddNew>
<textarea placeholder="Add a note..." value={this.state.textareaValue} onChange={this.onTextareaChange}
ref={this.textareaRef}
onKeyPress={this.onTextareaKeyPress}/>
ref={this.textareaRef}
onKeyPress={this.onTextareaKeyPress} />

<p className="FormattingHelp">
<a href="https://en.wikipedia.org/wiki/Markdown#Example"><strong>Markdown</strong></a> supported
Expand All @@ -252,4 +252,3 @@ export default class Notes extends Component {
}

}

7 changes: 4 additions & 3 deletions src/main.js → src/main.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import siteData from 'local/helpers/site-data';
import { SiteData } from '@getflywheel/local/main';

export default function (context) {
export default function(context) {

const { electron } = context;
const { ipcMain } = electron;

ipcMain.on('update-site-notes', (event, siteId, notes) => {
siteData.updateSite(siteId, {
SiteData.updateSite(siteId, {
id: siteId,
notes,
});
});
Expand Down
5 changes: 2 additions & 3 deletions src/renderer.jsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import Notes from './Notes';
import path from 'path';
import React from 'react';

export default function (context) {
export default function(context) {

const { React, hooks } = context;
const stylesheetPath = path.resolve(__dirname, '../style.css');

hooks.addContent('stylesheets', () => <link rel="stylesheet" key="notes-addon-styleesheet" href={stylesheetPath}/>);
hooks.addContent('stylesheets', () => <link rel="stylesheet" key="notes-addon-styleesheet" href={stylesheetPath} />);

hooks.addContent('SiteInfoOverview', (site) => <Notes key="notes" site={site} />);

Expand Down
26 changes: 26 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"compilerOptions": {
"allowJs": true,
"checkJs": false,
"declaration": false,
"esModuleInterop": true,
"experimentalDecorators": true,
"jsx": "react",
"lib": ["es2017", "esnext.asynciterable", "dom"],
"module": "commonjs",
"noImplicitReturns": true,
"noImplicitAny": false,
"outDir": "./lib",
"resolveJsonModule": true,
"rootDir": "./src",
"sourceMap": true,
"strict": false,
"target": "es2015"
},
"exclude": [
"node_modules"
],
"include": [
"src"
]
}
Loading

0 comments on commit b9dbcc9

Please sign in to comment.