Skip to content

Commit

Permalink
Cleanup some eslint issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
chenilim committed Oct 20, 2020
1 parent 9255bd4 commit c95ab68
Show file tree
Hide file tree
Showing 11 changed files with 159 additions and 153 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,5 @@ __debug_bin
files
octo*.db
.eslintcache
.vscode/settings.json
.prettierrc.json
5 changes: 0 additions & 5 deletions webapp/.prettierrc.json

This file was deleted.

6 changes: 3 additions & 3 deletions webapp/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import {MenuOption} from './menu'

class Constants {
static menuColors: MenuOption[] = [
{id: 'propColorDefault', name: 'Default', type: 'color'},
{id: 'propColorDefault', name: 'Default', type: 'color'},
{id: 'propColorGray', name: 'Gray', type: 'color'},
{id: 'propColorBrown', name: 'Brown', type: 'color'},
{id: 'propColorOrange', name: 'Orange', type: 'color'},
{id: 'propColorOrange', name: 'Orange', type: 'color'},
{id: 'propColorYellow', name: 'Yellow', type: 'color'},
{id: 'propColorGreen', name: 'Green', type: 'color'},
{id: 'propColorBlue', name: 'Blue', type: 'color'},
{id: 'propColorPurple', name: 'Purple', type: 'color'},
{id: 'propColorPink', name: 'Pink', type: 'color'},
{id: 'propColorPink', name: 'Pink', type: 'color'},
{id: 'propColorRed', name: 'Red', type: 'color'},
]
}
Expand Down
2 changes: 1 addition & 1 deletion webapp/src/flashMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class FlashMessage {
//
// Show a temporary status message
//
static show(text: string, delay = 800) {
static show(text: string, delay = 800): void {
const flashPanel = document.createElement('div')
flashPanel.innerText = text
flashPanel.classList.add('flashPanel')
Expand Down
70 changes: 37 additions & 33 deletions webapp/src/propertyMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,84 +14,88 @@ class PropertyMenu extends Menu {

constructor() {
super()
const typeMenuOptions = [
const typeMenuOptions = [
{id: 'text', name: 'Text'},
{id: 'number', name: 'Number'},
{id: 'number', name: 'Number'},
{id: 'select', name: 'Select'},
{id: 'createdTime', name: 'Created Time'},
{id: 'updatedTime', name: 'Updated Time'},
]
this.subMenuOptions.set('type', typeMenuOptions)
]
this.subMenuOptions.set('type', typeMenuOptions)
}

createMenuElement() {
createMenuElement(): HTMLElement {
const menu = Utils.htmlToElement('<div class="menu noselect" style="min-width: 200px;"></div>')

const ul = menu.appendChild(Utils.htmlToElement('<ul class="menu-options"></ul>'))

const nameTextbox = ul.appendChild(Utils.htmlToElement('<li class="menu-textbox"></li>'))
this.nameTextbox = nameTextbox
this.nameTextbox = nameTextbox
let propertyValue = this.property ? this.property.name : ''
nameTextbox.innerText = propertyValue
nameTextbox.innerText = propertyValue
nameTextbox.contentEditable = 'true'
nameTextbox.onclick = (e) => {
e.stopPropagation()
}
nameTextbox.onblur = () => {
if (nameTextbox.innerText !== propertyValue) {
propertyValue = nameTextbox.innerText
nameTextbox.onclick = (e) => {
e.stopPropagation()
}
nameTextbox.onblur = () => {
if (nameTextbox.innerText !== propertyValue) {
propertyValue = nameTextbox.innerText
if (this.onNameChanged) {
this.onNameChanged(nameTextbox.innerText)
}
}
}
}
nameTextbox.onmouseenter = () => {
this.hideSubMenu()
}
nameTextbox.onkeydown = (e) => {
}
nameTextbox.onkeydown = (e) => {
if (e.keyCode === 13 || e.keyCode === 27) {
nameTextbox.blur(); e.stopPropagation()
nameTextbox.blur()
e.stopPropagation()
}
}

ul.appendChild(Utils.htmlToElement('<li class="menu-separator"></li>'))
ul.appendChild(Utils.htmlToElement('<li class="menu-separator"></li>'))

this.appendMenuOptions(ul)
this.appendMenuOptions(ul)

return menu
return menu
}

showAt(left: number, top: number) {
showAt(left: number, top: number): void {
this.options = [
{id: 'type', name: this.typeDisplayName(this.property.type), type: 'submenu'},
{id: 'delete', name: 'Delete'},
]
]

super.showAt(left, top)
super.showAt(left, top)
setTimeout(() => {
this.nameTextbox.focus()
document.execCommand('selectAll', false, null)
document.execCommand('selectAll', false, null)
}, 20)
}

private typeDisplayName(type: PropertyType): string {
switch (type) {
case 'text': return 'Text'
case 'number': return 'Number'
case 'select': return 'Select'
case 'multiSelect': return 'Multi Select'
case 'person': return 'Person'
case 'text': return 'Text'
case 'number': return 'Number'
case 'select': return 'Select'
case 'multiSelect': return 'Multi Select'
case 'person': return 'Person'
case 'file': return 'File or Media'
case 'checkbox': return 'Checkbox'
case 'url': return 'URL'
case 'email': return 'Email'
case 'email': return 'Email'
case 'phone': return 'Phone'
case 'createdTime': return 'Created Time'
case 'createdTime': return 'Created Time'
case 'createdBy': return 'Created By'
case 'updatedTime': return 'Updated Time'
case 'updatedBy': return 'Updated By'
case 'updatedBy': return 'Updated By'
default: {
Utils.assertFailure(`typeDisplayName, unhandled type: ${type}`)
return type
}
}
Utils.assertFailure(`typeDisplayName, unhandled type: ${type}`)
}
}

Expand Down
4 changes: 1 addition & 3 deletions webapp/src/undomanager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,7 @@ class UndoManager {
let checkpoint: number
if (isDiscardable) {
checkpoint =
this.commands.length > 1 ?
this.commands[this.commands.length - 1].checkpoint :
0
this.commands.length > 1 ? this.commands[this.commands.length - 1].checkpoint : 0
} else {
checkpoint = Date.now()
}
Expand Down
27 changes: 14 additions & 13 deletions webapp/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ declare global {
}

class Utils {
static createGuid() {
static createGuid(): string {
const crypto = window.crypto || window.msCrypto
function randomDigit() {
if (crypto && crypto.getRandomValues) {
Expand All @@ -25,8 +25,7 @@ class Utils {

static htmlToElement(html: string): HTMLElement {
const template = document.createElement('template')
html = html.trim()
template.innerHTML = html
template.innerHTML = html.trim()
return template.content.firstChild as HTMLElement
}

Expand All @@ -36,11 +35,11 @@ class Utils {
return element!
}

static htmlEncode(text: string) {
static htmlEncode(text: string): string {
return String(text).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;')
}

static htmlDecode(text: string) {
static htmlDecode(text: string): string {
return String(text).replace(/&amp;/g, '&').replace(/&lt;/g, '<').replace(/&gt;/g, '>').replace(/&quot;/g, '"')
}

Expand Down Expand Up @@ -77,15 +76,15 @@ class Utils {

// Errors

static assertValue(valueObject: any) {
static assertValue(valueObject: any): void {
const name = Object.keys(valueObject)[0]
const value = valueObject[name]
if (!value) {
Utils.logError(`ASSERT VALUE [${name}]`)
}
}

static assert(condition: any, tag = '') {
static assert(condition: any, tag = ''): void {
/// #!if ENV !== "production"
if (!condition) {
Utils.logError(`ASSERT [${tag ?? new Error().stack}]`)
Expand All @@ -94,32 +93,34 @@ class Utils {
/// #!endif
}

static assertFailure(tag = '') {
static assertFailure(tag = ''): void {
/// #!if ENV !== "production"
Utils.assert(false, tag)

/// #!endif
}

static log(message: string) {
static log(message: string): void {
/// #!if ENV !== "production"
const timestamp = (Date.now() / 1000).toFixed(2)
// eslint-disable-next-line no-console
console.log(`[${timestamp}] ${message}`)

/// #!endif
}

static logError(message: any) {
static logError(message: string): void {
/// #!if ENV !== "production"
const timestamp = (Date.now() / 1000).toFixed(2)
// eslint-disable-next-line no-console
console.error(`[${timestamp}] ${message}`)

/// #!endif
}

// favicon

static setFavicon(icon?: string) {
static setFavicon(icon?: string): void {
const href = icon ?
`data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><text y=".9em" font-size="90">${icon}</text></svg>` :
''
Expand All @@ -132,7 +133,7 @@ class Utils {

// File names

static sanitizeFilename(filename: string) {
static sanitizeFilename(filename: string): string {
// TODO: Use an industrial-strength sanitizer
let sanitizedFilename = filename
const illegalCharacters = ['\\', '/', '?', ':', '<', '>', '*', '|', '"', '.']
Expand Down Expand Up @@ -162,7 +163,7 @@ class Utils {

// Arrays

static arraysEqual(a: any[], b: any[]) {
static arraysEqual(a: any[], b: any[]): boolean {
if (a === b) {
return true
}
Expand Down
6 changes: 3 additions & 3 deletions webapp/src/workspaceTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import {OctoUtils} from './octoUtils'
class WorkspaceTree {
boards: Board[] = []

async sync() {
async sync(): Promise<void> {
const blocks = await octoClient.getBlocks(undefined, 'board')
this.rebuild(OctoUtils.hydrateBlocks(blocks))
this.rebuild(OctoUtils.hydrateBlocks(blocks))
}

private rebuild(blocks: Block[]) {
private rebuild(blocks: Block[]): void {
this.boards = blocks.filter((block) => block.type === 'board') as Board[]
}
}
Expand Down
Loading

0 comments on commit c95ab68

Please sign in to comment.