From 9913adc75688d539fe8f798857fab2fe7c294882 Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Fri, 22 Feb 2019 09:38:12 +0000 Subject: [PATCH] Update tslint config and update code to conform. --- package.json | 2 + src/App.tsx | 76 +++++++++---------- src/components/AddressBook.tsx | 20 ++--- src/components/Calendar.tsx | 50 ++++++------- src/etesync-helpers.ts | 4 +- src/journal-processors.ts | 10 +-- src/pim-types.ts | 28 +++---- src/routes.ts | 10 ++- src/store/actions.ts | 38 +++++----- src/store/construct.ts | 10 +-- src/store/index.test.ts | 6 +- src/store/index.ts | 2 +- src/store/reducers.ts | 10 +-- src/types/ical.js.d.ts | 126 +++++++++++++++---------------- src/widgets/DateTimePicker.tsx | 32 ++++---- tslint.json | 133 +++++++++------------------------ yarn.lock | 43 ++++++++++- 17 files changed, 289 insertions(+), 311 deletions(-) diff --git a/package.json b/package.json index 94c639f..75f119d 100644 --- a/package.json +++ b/package.json @@ -52,6 +52,8 @@ "@types/sjcl": "^1.0.28", "@types/urijs": "^1.15.38", "@types/uuid": "^3.4.3", + "tslint": "^5.12.1", + "tslint-react": "^3.6.0", "typescript": "^3.3.3" }, "browserslist": [ diff --git a/src/App.tsx b/src/App.tsx index f1a70d9..e893392 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -96,7 +96,7 @@ export const routeResolver = new RouteResolver({ const AppBarWitHistory = withRouter( class extends React.PureComponent { - props: { + public props: { title: string, toggleDrawerIcon: any, history?: History; @@ -110,19 +110,7 @@ const AppBarWitHistory = withRouter( this.canGoBack = this.canGoBack.bind(this); } - canGoBack() { - return ( - (this.props.history!.length > 1) && - (this.props.history!.location.pathname !== routeResolver.getRoute('pim')) && - (this.props.history!.location.pathname !== routeResolver.getRoute('home')) - ); - } - - goBack() { - this.props.history!.goBack(); - } - - render() { + public render() { const { staticContext, toggleDrawerIcon, @@ -136,7 +124,7 @@ const AppBarWitHistory = withRouter( {...props} > -
+
{!this.canGoBack() ? toggleDrawerIcon : @@ -152,17 +140,29 @@ const AppBarWitHistory = withRouter( ); } - } + + private canGoBack() { + return ( + (this.props.history!.length > 1) && + (this.props.history!.location.pathname !== routeResolver.getRoute('pim')) && + (this.props.history!.location.pathname !== routeResolver.getRoute('home')) + ); + } + + private goBack() { + this.props.history!.goBack(); + } + }, ); const IconRefreshWithSpin = withSpin(NavigationRefresh); class App extends React.PureComponent { - state: { + public state: { drawerOpen: boolean, }; - props: { + public props: { credentials: store.CredentialsType; entries: store.EntriesType; fetchCount: number; @@ -177,19 +177,7 @@ class App extends React.PureComponent { this.refresh = this.refresh.bind(this); } - toggleDrawer() { - this.setState({drawerOpen: !this.state.drawerOpen}); - } - - closeDrawer() { - this.setState({drawerOpen: false}); - } - - refresh() { - store.store.dispatch(actions.fetchAll(this.props.credentials.value!, this.props.entries)); - } - - render() { + public render() { const credentials = (this.props.credentials) ? this.props.credentials.value : null; const fetching = this.props.fetchCount > 0; @@ -198,7 +186,7 @@ class App extends React.PureComponent { main: { backgroundColor: muiTheme.palette.background.default, color: muiTheme.palette.text.primary, - flexGrow: 1 + flexGrow: 1, }, }; @@ -229,6 +217,18 @@ class App extends React.PureComponent { ); } + + private toggleDrawer() { + this.setState({drawerOpen: !this.state.drawerOpen}); + } + + private closeDrawer() { + this.setState({drawerOpen: false}); + } + + private refresh() { + store.store.dispatch(actions.fetchAll(this.props.credentials.value!, this.props.entries)); + } } const credentialsSelector = createSelector( @@ -242,14 +242,14 @@ const credentialsSelector = createSelector( } return { - error: error, - fetching: fetching, + error, + fetching, value: { ...value, - encryptionKey: encryptionKey, - } + encryptionKey, + }, }; - } + }, ); const mapStateToProps = (state: store.StoreState) => { @@ -261,5 +261,5 @@ const mapStateToProps = (state: store.StoreState) => { }; export default connect( - mapStateToProps + mapStateToProps, )(App); diff --git a/src/components/AddressBook.tsx b/src/components/AddressBook.tsx index df48473..e1c493a 100644 --- a/src/components/AddressBook.tsx +++ b/src/components/AddressBook.tsx @@ -59,7 +59,7 @@ const AddressBookItem = pure((_props: any) => { }); const sortSelector = createSelector( - (entries: Array) => entries, + (entries: ContactType[]) => entries, (entries) => { return entries.sort((_a, _b) => { const a = _a.fn; @@ -73,24 +73,24 @@ const sortSelector = createSelector( return 0; } }); - }, + } ); -class AddressBook extends React.PureComponent { - props: { - entries: Array, - onItemClick: (contact: ContactType) => void, - filter?: (a: ContactType) => boolean, - }; +interface PropsType { + entries: ContactType[]; + onItemClick: (contact: ContactType) => void; + filter?: (a: ContactType) => boolean; +} - render() { +class AddressBook extends React.PureComponent { + public render() { const sortedEntries = sortSelector(this.props.entries); const entries = (this.props.filter) ? sortedEntries.filter(this.props.filter) : sortedEntries; - let itemList = entries.map((entry, idx, array) => { + const itemList = entries.map((entry, idx, array) => { const uid = entry.uid; return ( diff --git a/src/components/Calendar.tsx b/src/components/Calendar.tsx index f58b736..7f0d46d 100644 --- a/src/components/Calendar.tsx +++ b/src/components/Calendar.tsx @@ -17,7 +17,7 @@ function eventPropGetter(event: EventType) { return { style: { backgroundColor: event.color, - } + }, }; } @@ -26,18 +26,18 @@ function agendaHeaderFormat(date: {start: Date, end: Date}, culture: string, loc return localizer.format(date.start, format) + ' - ' + localizer.format(date.end, format); } -class Calendar extends React.PureComponent { - state: { +interface PropsType { + entries: EventType[]; + onItemClick: (contact: EventType) => void; + onSlotClick?: (start: Date, end: Date) => void; +} + +class Calendar extends React.PureComponent { + public state: { currentDate?: Date; view?: View; }; - props: { - entries: Array, - onItemClick: (contact: EventType) => void, - onSlotClick?: (start: Date, end: Date) => void, - }; - constructor(props: any) { super(props); this.state = {}; @@ -47,22 +47,8 @@ class Calendar extends React.PureComponent { this.slotClicked = this.slotClicked.bind(this); } - onNavigate(currentDate: Date) { - this.setState({currentDate}); - } - - onView(view: string) { - this.setState({view}); - } - - slotClicked(slotInfo: {start: Date, end: Date}) { - if (this.props.onSlotClick) { - this.props.onSlotClick(slotInfo.start, slotInfo.end); - } - } - - render() { - const entries = [] as Array; + public render() { + const entries = [] as EventType[]; this.props.entries.forEach((event) => { entries.push(event); @@ -103,6 +89,20 @@ class Calendar extends React.PureComponent {
); } + + private onNavigate(currentDate: Date) { + this.setState({currentDate}); + } + + private onView(view: string) { + this.setState({view}); + } + + private slotClicked(slotInfo: {start: Date, end: Date}) { + if (this.props.onSlotClick) { + this.props.onSlotClick(slotInfo.start, slotInfo.end); + } + } } export default Calendar; diff --git a/src/etesync-helpers.ts b/src/etesync-helpers.ts index cb26568..8b3ecf8 100644 --- a/src/etesync-helpers.ts +++ b/src/etesync-helpers.ts @@ -11,7 +11,7 @@ export function createJournalEntry( action: EteSync.SyncEntryAction, content: string) { - let syncEntry = new EteSync.SyncEntry(); + const syncEntry = new EteSync.SyncEntry(); syncEntry.action = action; syncEntry.content = content; @@ -27,7 +27,7 @@ export function createJournalEntry( } else { cryptoManager = new EteSync.CryptoManager(derived, journal.uid, journal.version); } - let entry = new EteSync.Entry(); + const entry = new EteSync.Entry(); entry.setSyncEntry(cryptoManager, syncEntry, prevUid); return createEntries(etesync, journal.uid, [entry], prevUid); diff --git a/src/journal-processors.ts b/src/journal-processors.ts index 6c3c475..c8c2bf2 100644 --- a/src/journal-processors.ts +++ b/src/journal-processors.ts @@ -8,10 +8,10 @@ import * as EteSync from './api/EteSync'; export function syncEntriesToItemMap( collection: EteSync.CollectionInfo, entries: List, base: {[key: string]: ContactType} = {}) { - let items = base; + const items = base; entries.forEach((syncEntry) => { - let comp = new ContactType(new ICAL.Component(ICAL.parse(syncEntry.content))); + const comp = new ContactType(new ICAL.Component(ICAL.parse(syncEntry.content))); const uid = comp.uid; @@ -42,7 +42,7 @@ function colorIntToHtml(color: number) { // tslint:enable function toHex(num: number) { - let ret = num.toString(16); + const ret = num.toString(16); return (ret.length === 1) ? '0' + ret : ret; } @@ -53,12 +53,12 @@ function colorIntToHtml(color: number) { function syncEntriesToCalendarItemMap( ItemType: any, collection: EteSync.CollectionInfo, entries: List, base: {[key: string]: T} = {}) { - let items = base; + const items = base; const color = colorIntToHtml(collection.color); entries.forEach((syncEntry) => { - let comp = ItemType.fromVCalendar(new ICAL.Component(ICAL.parse(syncEntry.content))); + const comp = ItemType.fromVCalendar(new ICAL.Component(ICAL.parse(syncEntry.content))); if (comp === null) { return; diff --git a/src/pim-types.ts b/src/pim-types.ts index d18a15f..a8a681d 100644 --- a/src/pim-types.ts +++ b/src/pim-types.ts @@ -7,16 +7,16 @@ export interface PimType { } export class EventType extends ICAL.Event implements PimType { - color: string; - - static isEvent(comp: ICAL.Component) { + public static isEvent(comp: ICAL.Component) { return !!comp.getFirstSubcomponent('vevent'); } - static fromVCalendar(comp: ICAL.Component) { + public static fromVCalendar(comp: ICAL.Component) { return new EventType(comp.getFirstSubcomponent('vevent')); } + public color: string; + get timezone() { if (this.startDate) { return this.startDate.timezone; @@ -47,8 +47,8 @@ export class EventType extends ICAL.Event implements PimType { return this.description; } - toIcal() { - let comp = new ICAL.Component(['vcalendar', [], []]); + public toIcal() { + const comp = new ICAL.Component(['vcalendar', [], []]); comp.updatePropertyWithValue('prodid', '-//iCal.js EteSync Web'); comp.updatePropertyWithValue('version', '4.0'); @@ -56,7 +56,7 @@ export class EventType extends ICAL.Event implements PimType { return comp.toString(); } - clone() { + public clone() { const ret = new EventType(new ICAL.Component(this.component.toJSON())); ret.color = this.color; return ret; @@ -71,12 +71,12 @@ export enum TaskStatusType { } export class TaskType extends EventType { - color: string; - - static fromVCalendar(comp: ICAL.Component) { + public static fromVCalendar(comp: ICAL.Component) { return new TaskType(comp.getFirstSubcomponent('vtodo')); } + public color: string; + constructor(comp: ICAL.Component | null) { super(comp ? comp : new ICAL.Component('vtodo')); } @@ -106,7 +106,7 @@ export class TaskType extends EventType { return this.component.getFirstPropertyValue('due'); } - clone() { + public clone() { const ret = new TaskType(new ICAL.Component(this.component.toJSON())); ret.color = this.color; return ret; @@ -114,17 +114,17 @@ export class TaskType extends EventType { } export class ContactType implements PimType { - comp: ICAL.Component; + public comp: ICAL.Component; constructor(comp: ICAL.Component) { this.comp = comp; } - toIcal() { + public toIcal() { return this.comp.toString(); } - clone() { + public clone() { return new ContactType(new ICAL.Component(this.comp.toJSON())); } diff --git a/src/routes.ts b/src/routes.ts index 0154acd..7a0379a 100644 --- a/src/routes.ts +++ b/src/routes.ts @@ -1,13 +1,15 @@ -export type RouteKeysType = { [Identifier: string]: any }; +export interface RouteKeysType { + [Identifier: string]: any; +} export class RouteResolver { - routes: {}; + public routes: {}; constructor(routes: {}) { this.routes = routes; } - getRoute(name: string, _keys?: RouteKeysType): string { + public getRoute(name: string, _keys?: RouteKeysType): string { let dict = this.routes; let path: string[] = []; @@ -19,7 +21,7 @@ export class RouteResolver { }); if (_keys) { - let keys = Object.assign({}, _keys); + const keys = Object.assign({}, _keys); path = path.map((pathComponent) => { return pathComponent.split('/').map((val) => { diff --git a/src/store/actions.ts b/src/store/actions.ts index 10b1a2b..5965a13 100644 --- a/src/store/actions.ts +++ b/src/store/actions.ts @@ -48,7 +48,7 @@ export const { fetchListJournal } = createActions({ FETCH_LIST_JOURNAL: (etesync: CredentialsData) => { const creds = etesync.credentials; const apiBase = etesync.serviceApiUrl; - let journalManager = new EteSync.JournalManager(creds, apiBase); + const journalManager = new EteSync.JournalManager(creds, apiBase); return journalManager.list(); }, @@ -59,13 +59,13 @@ export const addJournal = createAction( (etesync: CredentialsData, journal: EteSync.Journal) => { const creds = etesync.credentials; const apiBase = etesync.serviceApiUrl; - let journalManager = new EteSync.JournalManager(creds, apiBase); + const journalManager = new EteSync.JournalManager(creds, apiBase); return journalManager.create(journal); }, (etesync: CredentialsData, journal: EteSync.Journal) => { return { item: journal }; - }, + } ); export const updateJournal = createAction( @@ -73,13 +73,13 @@ export const updateJournal = createAction( (etesync: CredentialsData, journal: EteSync.Journal) => { const creds = etesync.credentials; const apiBase = etesync.serviceApiUrl; - let journalManager = new EteSync.JournalManager(creds, apiBase); + const journalManager = new EteSync.JournalManager(creds, apiBase); return journalManager.update(journal); }, (etesync: CredentialsData, journal: EteSync.Journal) => { return { item: journal }; - }, + } ); export const deleteJournal = createAction( @@ -87,13 +87,13 @@ export const deleteJournal = createAction( (etesync: CredentialsData, journal: EteSync.Journal) => { const creds = etesync.credentials; const apiBase = etesync.serviceApiUrl; - let journalManager = new EteSync.JournalManager(creds, apiBase); + const journalManager = new EteSync.JournalManager(creds, apiBase); return journalManager.delete(journal); }, (etesync: CredentialsData, journal: EteSync.Journal) => { return { item: journal }; - }, + } ); export const { fetchEntries, createEntries } = createActions({ @@ -101,33 +101,33 @@ export const { fetchEntries, createEntries } = createActions({ (etesync: CredentialsData, journalUid: string, prevUid: string | null) => { const creds = etesync.credentials; const apiBase = etesync.serviceApiUrl; - let entryManager = new EteSync.EntryManager(creds, apiBase, journalUid); + const entryManager = new EteSync.EntryManager(creds, apiBase, journalUid); return entryManager.list(prevUid); }, (etesync: CredentialsData, journalUid: string, prevUid: string | null) => { return { journal: journalUid, prevUid }; - } + }, ], CREATE_ENTRIES: [ - (etesync: CredentialsData, journalUid: string, newEntries: Array, prevUid: string | null) => { + (etesync: CredentialsData, journalUid: string, newEntries: EteSync.Entry[], prevUid: string | null) => { const creds = etesync.credentials; const apiBase = etesync.serviceApiUrl; - let entryManager = new EteSync.EntryManager(creds, apiBase, journalUid); + const entryManager = new EteSync.EntryManager(creds, apiBase, journalUid); - return entryManager.create(newEntries, prevUid).then(response => newEntries); + return entryManager.create(newEntries, prevUid).then((response) => newEntries); }, - (etesync: CredentialsData, journalUid: string, newEntries: Array, prevUid: string | null) => { + (etesync: CredentialsData, journalUid: string, newEntries: EteSync.Entry[], prevUid: string | null) => { return { journal: journalUid, entries: newEntries, prevUid }; - } - ] + }, + ], }); export const { fetchUserInfo } = createActions({ FETCH_USER_INFO: (etesync: CredentialsData, owner: string) => { const creds = etesync.credentials; const apiBase = etesync.serviceApiUrl; - let userInfoManager = new EteSync.UserInfoManager(creds, apiBase); + const userInfoManager = new EteSync.UserInfoManager(creds, apiBase); return userInfoManager.fetch(owner); }, @@ -138,13 +138,13 @@ export const createUserInfo = createAction( (etesync: CredentialsData, userInfo: UserInfo) => { const creds = etesync.credentials; const apiBase = etesync.serviceApiUrl; - let userInfoManager = new EteSync.UserInfoManager(creds, apiBase); + const userInfoManager = new EteSync.UserInfoManager(creds, apiBase); return userInfoManager.create(userInfo); }, (etesync: CredentialsData, userInfo: UserInfo) => { return { userInfo }; - }, + } ); export function fetchAll(etesync: CredentialsData, currentEntries: EntriesType) { @@ -176,5 +176,5 @@ export const setSettings = createAction( 'SET_SETTINGS', (settings: SettingsType) => { return {...settings}; - }, + } ); diff --git a/src/store/construct.ts b/src/store/construct.ts index d070fb6..dde55ae 100644 --- a/src/store/construct.ts +++ b/src/store/construct.ts @@ -77,7 +77,7 @@ const entriesDeserialize = (state: EteSync.EntryJson[]): FetchType } return new EntriesFetchRecord({value: List(state.map((x: any) => { - let ret = new EteSync.Entry(); + const ret = new EteSync.Entry(); ret.deserialize(x); return ret; }))}); @@ -96,14 +96,14 @@ const userInfoDeserialize = (state: EteSync.UserInfoJson) => { return null; } - let ret = new EteSync.UserInfo(state.owner!, state.version); + const ret = new EteSync.UserInfo(state.owner!, state.version); ret.deserialize(state); return ret; }; const cacheSerialize = (state: any, key: string) => { if (key === 'entries') { - let ret = {}; + const ret = {}; state.forEach((value: FetchType, mapKey: string) => { ret[mapKey] = entriesSerialize(value); }); @@ -119,7 +119,7 @@ const cacheSerialize = (state: any, key: string) => { const cacheDeserialize = (state: any, key: string) => { if (key === 'entries') { - let ret = {}; + const ret = {}; Object.keys(state).forEach((mapKey) => { ret[mapKey] = entriesDeserialize(state[mapKey]); }); @@ -137,7 +137,7 @@ const cacheMigrations = { 0: (state: any) => { return { ...state, - journals: undefined + journals: undefined, }; }, }; diff --git a/src/store/index.test.ts b/src/store/index.test.ts index 527c094..a55a3f5 100644 --- a/src/store/index.test.ts +++ b/src/store/index.test.ts @@ -9,13 +9,13 @@ it('Entries reducer', () => { const jId = '24324324324'; let state = Map({}) as EntriesTypeImmutable; - let entry = new EteSync.Entry(); + const entry = new EteSync.Entry(); entry.deserialize({ content: 'someContent', - uid: '6355209e2a2c26a6c1e6e967c2032737d538f602cf912474da83a2902f8a0a83' + uid: '6355209e2a2c26a6c1e6e967c2032737d538f602cf912474da83a2902f8a0a83', }); - let action = { + const action = { type: fetchEntries.toString(), meta: {journal: jId, prevUid: null as string | null}, payload: [entry], diff --git a/src/store/index.ts b/src/store/index.ts index 835e67e..1c9ad0a 100644 --- a/src/store/index.ts +++ b/src/store/index.ts @@ -11,7 +11,7 @@ import reducers from './construct'; export * from './reducers'; export * from './construct'; -let middleware = [ +const middleware = [ thunkMiddleware, promiseMiddleware, ]; diff --git a/src/store/reducers.ts b/src/store/reducers.ts index 8bf8d23..9b57d09 100644 --- a/src/store/reducers.ts +++ b/src/store/reducers.ts @@ -208,7 +208,7 @@ export const journals = handleActions( { ...mapReducerActionsMapCreator('Journal'), }, - new JournalsFetchRecord(), + new JournalsFetchRecord() ); export const userInfo = handleAction( @@ -233,7 +233,7 @@ export const userInfo = handleAction( return state.set('value', payload); } }, - new UserInfoFetchRecord(), + new UserInfoFetchRecord() ); const fetchActions = [ @@ -252,7 +252,7 @@ for (const func in actions) { // Indicates network activity, not just fetch export const fetchCount = handleAction( combineActions( - ...fetchActions, + ...fetchActions ), (state: number, action: any) => { if (action.payload === undefined) { @@ -261,13 +261,13 @@ export const fetchCount = handleAction( return state - 1; } }, - 0, + 0 ); // FIXME Move all the below (potentially the fetchCount ones too) to their own file export interface SettingsType { locale: string; -}; +} export const settingsReducer = handleActions( { diff --git a/src/types/ical.js.d.ts b/src/types/ical.js.d.ts index 3041a88..088f571 100644 --- a/src/types/ical.js.d.ts +++ b/src/types/ical.js.d.ts @@ -1,114 +1,112 @@ declare module 'ical.js' { - function parse(input: string): Array; + function parse(input: string): any[]; class Component { - name: string; + static public fromString(str: string): Component; - static fromString(str: string): Component; + public name: string; - constructor(jCal: Array | string, parent?: Component); + constructor(jCal: any[] | string, parent?: Component); - toJSON(): Array; + public toJSON(): any[]; - getFirstSubcomponent(name?: string): Component | null; + public getFirstSubcomponent(name?: string): Component | null; - getFirstPropertyValue(name?: string): any; + public getFirstPropertyValue(name?: string): any; - getFirstProperty(name?: string): Property; - getAllProperties(name?: string): Array; + public getFirstProperty(name?: string): Property; + public getAllProperties(name?: string): Property[]; - addProperty(property: Property): Property; - addPropertyWithValue(name: string, value: string | number | object): Property; + public addProperty(property: Property): Property; + public addPropertyWithValue(name: string, value: string | number | object): Property; - updatePropertyWithValue(name: string, value: string | number | object): Property; + public updatePropertyWithValue(name: string, value: string | number | object): Property; - removeAllProperties(name?: string): boolean; + public removeAllProperties(name?: string): boolean; - addSubcomponent(component: Component): Component; + public addSubcomponent(component: Component): Component; } class Event { - uid: string; - summary: string; - startDate: Time; - endDate: Time; - description: string; - location: string; - attendees: Array; + public uid: string; + public summary: string; + public startDate: Time; + public endDate: Time; + public description: string; + public location: string; + public attendees: Property[]; - component: Component; + public component: Component; - isRecurring(): boolean; - iterator(startTime?: Time): RecurExpansion; + public constructor(component?: Component | null, options?: {strictExceptions: boolean, exepctions: Array}); - constructor(component?: Component | null, - options?: {strictExceptions: boolean, exepctions: Array}); + public isRecurring(): boolean; + public iterator(startTime?: Time): RecurExpansion; } class Property { - name: string; - type: string; + public name: string; + public type: string; - constructor(jCal: Array | string, parent?: Component); + constructor(jCal: any[] | string, parent?: Component); - getFirstValue(): any; - getValues(): Array; + public getFirstValue(): any; + public getValues(): any[]; - setParameter(name: string, value: string | Array): void; - setValue(value: string | object): void; - toJSON(): any; + public setParameter(name: string, value: string | string[]): void; + public setValue(value: string | object): void; + public toJSON(): any; } - type TimeJsonData = { - year?: number, - month?: number, - day?: number, - hour?: number, - minute?: number, - second?: number, - isDate?: boolean - }; + interface TimeJsonData { + year?: number; + month?: number; + day?: number; + hour?: number; + minute?: number; + second?: number; + isDate?: boolean; + } class Time { - isDate: boolean; - timezone: string; - zone: Timezone; + static public fromString(str: string): Time; + static public fromJSDate(aDate: Date | null, useUTC: boolean): Time; + static public fromData(aData: TimeJsonData): Time; - static fromString(str: string): Time; - static fromJSDate(aDate: Date | null, useUTC: boolean): Time; - static fromData(aData: TimeJsonData): Time; + static public now(): Time; - static now(): Time; + public isDate: boolean; + public timezone: string; + public zone: Timezone; constructor(data?: TimeJsonData); + public compare(aOther: Time): number; - compare(aOther: Time): number; - - clone(): Time; + public clone(): Time; - adjust( + public adjust( aExtraDays: number, aExtraHours: number, aExtraMinutes: number, aExtraSeconds: number, aTimeopt?: Time): void; - addDuration(aDuration: Duration): void; - subtractDateTz(aDate: Time): Duration; + public addDuration(aDuration: Duration): void; + public subtractDateTz(aDate: Time): Duration; - toJSDate(): Date; - toJSON(): TimeJsonData; + public toJSDate(): Date; + public toJSON(): TimeJsonData; } class Duration { - days: number; + public days: number; } class RecurExpansion { - complete: boolean; + public complete: boolean; - next(): Time; + public next(): Time; } class Timezone { - static localTimezone: Timezone; - static convert_time(tt: Time, from_zone: Timezone, to_zone: Timezone): Time; + static public localTimezone: Timezone; + static public convert_time(tt: Time, fromZone: Timezone, toZone: Timezone): Time; - tzid: string; + public tzid: string; } } diff --git a/src/widgets/DateTimePicker.tsx b/src/widgets/DateTimePicker.tsx index 77d6ba7..3b1fc7e 100644 --- a/src/widgets/DateTimePicker.tsx +++ b/src/widgets/DateTimePicker.tsx @@ -5,28 +5,20 @@ import Datetime from 'react-datetime'; import 'react-datetime/css/react-datetime.css'; -class DateTimePicker extends React.PureComponent { - props: { - placeholder: string, - value?: Date, - dateOnly?: boolean, - onChange: (date?: Date) => void; - }; +interface PropsType { + placeholder: string; + value?: Date; + dateOnly?: boolean; + onChange: (date?: Date) => void; +} +class DateTimePicker extends React.PureComponent { constructor(props: any) { super(props); this.handleInputChange = this.handleInputChange.bind(this); } - handleInputChange(newDate: string | moment.Moment) { - if (moment.isMoment(newDate)) { - this.props.onChange(newDate.toDate()); - } else { - this.props.onChange(undefined); - } - } - - render() { + public render() { const inputProps = { placeholder: this.props.placeholder, readOnly: true, @@ -40,6 +32,14 @@ class DateTimePicker extends React.PureComponent { /> ); } + + private handleInputChange(newDate: string | moment.Moment) { + if (moment.isMoment(newDate)) { + this.props.onChange(newDate.toDate()); + } else { + this.props.onChange(undefined); + } + } } export default DateTimePicker; diff --git a/tslint.json b/tslint.json index 86d1520..1d970d9 100644 --- a/tslint.json +++ b/tslint.json @@ -1,99 +1,38 @@ { - "extends": ["tslint-react"], - "rules": { - "align": [ - true, - "parameters", - "arguments", - "statements" - ], - "ban": false, - "class-name": true, - "comment-format": [ - true, - "check-space" - ], - "curly": true, - "eofline": false, - "forin": true, - "indent": [ true, "spaces" ], - "interface-name": [true, "never-prefix"], - "jsdoc-format": true, - "jsx-no-lambda": false, - "jsx-no-multiline-js": false, - "label-position": true, - "max-line-length": [ true, 120 ], - "member-ordering": [ - true, - "public-before-private", - "static-before-instance", - "variables-before-functions" - ], - "no-any": false, - "no-arg": true, - "no-bitwise": true, - "no-console": [ - true, - "log", - "error", - "debug", - "info", - "time", - "timeEnd", - "trace" - ], - "no-consecutive-blank-lines": true, - "no-construct": true, - "no-debugger": true, - "no-duplicate-variable": true, - "no-empty": true, - "no-eval": true, - "no-shadowed-variable": true, - "no-string-literal": true, - "no-switch-case-fall-through": true, - "no-trailing-whitespace": false, - "no-unused-expression": true, - "no-use-before-declare": true, - "one-line": [ - true, - "check-catch", - "check-else", - "check-open-brace", - "check-whitespace" - ], - "quotemark": [true, "single", "jsx-double"], - "radix": true, - "semicolon": [true, "always"], - "switch-default": true, - - "trailing-comma": false, - - "triple-equals": [ true, "allow-null-check" ], - "typedef": [ - true, - "parameter", - "property-declaration" - ], - "typedef-whitespace": [ - true, - { - "call-signature": "nospace", - "index-signature": "nospace", - "parameter": "nospace", - "property-declaration": "nospace", - "variable-declaration": "nospace" - } - ], - "variable-name": [true, "ban-keywords", "check-format", "allow-leading-underscore", "allow-pascal-case"], - "whitespace": [ - true, - "check-branch", - "check-decl", - "check-module", - "check-operator", - "check-separator", - "check-type", - "check-typecast" - ] - } + "extends": ["tslint:recommended", "tslint-react"], + "rules": { + "interface-name": [true, "never-prefix"], + "ordered-imports": false, + "jsx-curly-spacing": [true, "never"], + "jsx-no-bind": [true, "allowArrowFunctions"], + "jsx-no-lambda": [false], + "jsx-no-multiline-js": false, + "max-classes-per-file": [false, 0], + "max-line-length": false, + "no-consecutive-blank-lines": false, + "no-conditional-assignment": false, + "object-literal-sort-keys": false, + "quotemark": [true, "single", "jsx-double", "avoid-escape", "avoid-template"], + "semicolon": [true, "always", "ignore-bound-class-methods"], + "variable-name": [true, "ban-keywords", "check-format", "allow-pascal-case", "allow-leading-underscore"], + "trailing-comma": [ + true, + { + "multiline": { + "objects": "always", + "arrays": "always", + "functions": "never", + "typeLiterals": "ignore" + }, + "esSpecCompliant": true + } + ], + "whitespace": [true,"check-branch", "check-decl", "check-operator", "check-module", "check-separator", "check-rest-spread", "check-type", "check-typecast", "check-type-operator", "check-preblock"] + }, + "linterOptions": { + "exclude": [ + "config/**/*.js", + "node_modules/**/*.ts" + ] + } } diff --git a/yarn.lock b/yarn.lock index d7917df..8a1e90c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2151,6 +2151,11 @@ buffer@^4.3.0: ieee754 "^1.1.4" isarray "^1.0.0" +builtin-modules@^1.1.1: + version "1.1.1" + resolved "https://registry.yarnpkg.com/builtin-modules/-/builtin-modules-1.1.1.tgz#270f076c5a72c02f5b65a47df94c5fe3a278892f" + integrity sha1-Jw8HbFpywC9bZaR9+Uxf46J4iS8= + builtin-status-codes@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/builtin-status-codes/-/builtin-status-codes-3.0.0.tgz#85982878e21b98e1c66425e03d0174788f569ee8" @@ -2280,7 +2285,7 @@ ccount@^1.0.3: resolved "https://registry.yarnpkg.com/ccount/-/ccount-1.0.3.tgz#f1cec43f332e2ea5a569fd46f9f5bde4e6102aff" integrity sha512-Jt9tIBkRc9POUof7QA/VwWd+58fKkEEfI+/t1/eOlxKM7ZhrczNzMFefge7Ai+39y1pR/pP6cI19guHy3FSLmw== -chalk@2.4.2, chalk@^2.0.0, chalk@^2.0.1, chalk@^2.1.0, chalk@^2.4.1, chalk@^2.4.2: +chalk@2.4.2, chalk@^2.0.0, chalk@^2.0.1, chalk@^2.1.0, chalk@^2.3.0, chalk@^2.4.1, chalk@^2.4.2: version "2.4.2" resolved "https://registry.yarnpkg.com/chalk/-/chalk-2.4.2.tgz#cd42541677a54333cf541a49108c1432b44c9424" integrity sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ== @@ -2527,7 +2532,7 @@ commander@2.17.x, commander@~2.17.1: resolved "https://registry.yarnpkg.com/commander/-/commander-2.17.1.tgz#bd77ab7de6de94205ceacc72f1716d29f20a77bf" integrity sha512-wPMUt6FnH2yzG95SA6mzjQOEKUU3aLaDEmzs1ti+1E9h+CsrZghRlqEM/EJ4KscsQVG8uNN4uVreUeT8+drlgg== -commander@^2.11.0: +commander@^2.11.0, commander@^2.12.1: version "2.19.0" resolved "https://registry.yarnpkg.com/commander/-/commander-2.19.0.tgz#f6198aa84e5b83c46054b94ddedbfed5ee9ff12a" integrity sha512-6tvAOO+D6OENvRAh524Dh9jcfKTYDQAqvqezbCW82xj5X0pSrcpxtvRKHLG0yBY6SD7PSDrJaj+0AiOcKVd1Xg== @@ -9936,11 +9941,43 @@ ts-pnp@^1.0.0: resolved "https://registry.yarnpkg.com/ts-pnp/-/ts-pnp-1.0.0.tgz#44a3a9e8c13fcb711bcda75d7b576c21af120c9d" integrity sha512-qgwM7eBrxFvZSXLtSvjf3c2mXwJOOGD49VlE+KocUGX95DuMdLc/psZHBnPpZL5b2NU7VtQGHRCWF3cNfe5kxQ== -tslib@^1.9.0: +tslib@^1.8.0, tslib@^1.8.1, tslib@^1.9.0: version "1.9.3" resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.9.3.tgz#d7e4dd79245d85428c4d7e4822a79917954ca286" integrity sha512-4krF8scpejhaOgqzBEcGM7yDIEfi0/8+8zDRZhNZZ2kjmHJ4hv3zCbQWxoJGz1iw5U0Jl0nma13xzHXcncMavQ== +tslint-react@^3.6.0: + version "3.6.0" + resolved "https://registry.yarnpkg.com/tslint-react/-/tslint-react-3.6.0.tgz#7f462c95c4a0afaae82507f06517ff02942196a1" + integrity sha512-AIv1QcsSnj7e9pFir6cJ6vIncTqxfqeFF3Lzh8SuuBljueYzEAtByuB6zMaD27BL0xhMEqsZ9s5eHuCONydjBw== + dependencies: + tsutils "^2.13.1" + +tslint@^5.12.1: + version "5.12.1" + resolved "https://registry.yarnpkg.com/tslint/-/tslint-5.12.1.tgz#8cec9d454cf8a1de9b0a26d7bdbad6de362e52c1" + integrity sha512-sfodBHOucFg6egff8d1BvuofoOQ/nOeYNfbp7LDlKBcLNrL3lmS5zoiDGyOMdT7YsEXAwWpTdAHwOGOc8eRZAw== + dependencies: + babel-code-frame "^6.22.0" + builtin-modules "^1.1.1" + chalk "^2.3.0" + commander "^2.12.1" + diff "^3.2.0" + glob "^7.1.1" + js-yaml "^3.7.0" + minimatch "^3.0.4" + resolve "^1.3.2" + semver "^5.3.0" + tslib "^1.8.0" + tsutils "^2.27.2" + +tsutils@^2.13.1, tsutils@^2.27.2: + version "2.29.0" + resolved "https://registry.yarnpkg.com/tsutils/-/tsutils-2.29.0.tgz#32b488501467acbedd4b85498673a0812aca0b99" + integrity sha512-g5JVHCIJwzfISaXpXE1qvNalca5Jwob6FjI4AoPlqMusJ6ftFE7IkkFoMhVLRgK+4Kx3gkzb8UZK5t5yTTvEmA== + dependencies: + tslib "^1.8.1" + tty-browserify@0.0.0: version "0.0.0" resolved "https://registry.yarnpkg.com/tty-browserify/-/tty-browserify-0.0.0.tgz#a157ba402da24e9bf957f9aa69d524eed42901a6"