From a16fc2d7fd774a23e6654cf2ba438fbd8e29effc Mon Sep 17 00:00:00 2001 From: Ben Moore Date: Fri, 11 Oct 2019 12:41:36 -0500 Subject: [PATCH] refactor: Notes work with Local Lightning wip: add typescript refactor: Notes work with Local Lightning Delete local.d.ts Remove unused `local.d.ts` file style: add semi-colon --- package.json | 29 +- src/Notes.jsx | 51 +- src/{main.js => main.ts} | 7 +- src/renderer.jsx | 5 +- tsconfig.json | 26 + yarn.lock | 3196 +++++++++----------------------------- 6 files changed, 824 insertions(+), 2490 deletions(-) rename src/{main.js => main.ts} (52%) create mode 100644 tsconfig.json diff --git a/package.json b/package.json index 9ee1005..56f3361 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "local-addon-notes", "productName": "Notes", - "version": "1.0.2", + "version": "1.1.2", "author": "Clay Griffiths", "keywords": [ "local-addon" @@ -21,21 +21,19 @@ }, "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", @@ -43,10 +41,13 @@ "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", @@ -55,6 +56,6 @@ "prop-types" ], "engines": { - "local-by-flywheel": "^3.0.0" + "local-by-flywheel": "^5.0.0" } } diff --git a/src/Notes.jsx b/src/Notes.jsx index 4906404..624d855 100644 --- a/src/Notes.jsx +++ b/src/Notes.jsx @@ -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); @@ -36,7 +36,7 @@ export default class Notes extends Component { } - componentDidUpdate (previousProps) { + componentDidUpdate(previousProps) { if (previousProps.site.id !== this.props.site.id) { this.setState({ @@ -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; @@ -70,7 +70,7 @@ export default class Notes extends Component { } - addNote (body) { + addNote(body) { const notes = this.state.notes.concat([{ date: new Date(), @@ -86,7 +86,7 @@ export default class Notes extends Component { } - openAddNew () { + openAddNew() { this.setState({ addNewOpen: true, @@ -96,7 +96,7 @@ export default class Notes extends Component { } - toggleAddNew () { + toggleAddNew() { if (this.state.addNewOpen) { return this.setState({ @@ -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; @@ -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?', @@ -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); @@ -166,7 +166,7 @@ export default class Notes extends Component { } - getNotesInOrder () { + getNotesInOrder() { const notes = this.state.notes.slice(0); @@ -186,48 +186,48 @@ export default class Notes extends Component { } - renderNotes () { + renderNotes() { if (!this.state.notes || !this.state.notes.length) { return !this.state.addNewOpen && - No notes added
- to this site

+ No notes added
+ to this site

; } return this.getNotesInOrder().map((note) => ( 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 this.setState({ promotePinned: !this.state.promotePinned })} - className={classnames('PromotePinned', { '--Enabled': this.state.promotePinned })}> + className={classnames('PromotePinned', { '--Enabled': this.state.promotePinned })}> - + {this.pinnedNotesCount() ? {this.pinnedNotesCount()} : ''} - + ; } - render () { + render() { return @@ -236,8 +236,8 @@ export default class Notes extends Component {