Skip to content

Commit

Permalink
fix: Fix eslint errors for typescript files
Browse files Browse the repository at this point in the history
Signed-off-by: Julius Härtl <[email protected]>
  • Loading branch information
juliusknorr committed Jun 14, 2024
1 parent 369c33c commit 4158fbe
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 31 deletions.
2 changes: 2 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,7 @@ module.exports = {
'jsdoc/require-param-description': 'off',
'jsdoc/require-param-type': 'off',
'jsdoc/require-property-description': 'off',
'@typescript-eslint/no-unused-vars': 'off',
'@typescript-eslint/no-explicit-any': 'off',
}
}
4 changes: 1 addition & 3 deletions src/helpers/getLoggedInUser.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
import { loadState } from '@nextcloud/initial-state'

/**
* Gets the current user's display name if logged in.
*
* @return boolean | string
* @return {boolean|string} Gets the current user's display name if logged in.
*/
function getLoggedInUser() {
return loadState('richdocuments', 'loggedInUser')
Expand Down
17 changes: 9 additions & 8 deletions src/services/config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,20 @@ import { loadState } from '@nextcloud/initial-state'

class ConfigService {

private values: {[name: string]: any}
private values: {[name: string]: any}

constructor () {
constructor() {
this.values = loadState('richdocuments', 'document', {})
}

update(key: string, value: any) {
this.values[key] = value
}
update(key: string, value: any) {
this.values[key] = value
}

get(key: string): any {
return this.values[key]
}

get(key: string): any {
return this.values[key]
}
}

const Config = new ConfigService()
Expand Down
38 changes: 22 additions & 16 deletions src/services/postMessage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,31 @@
* SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import { emit } from "@nextcloud/event-bus"
import { emit } from '@nextcloud/event-bus'

type MessageEventSource = Window | MessagePort | ServiceWorker;

export interface WopiPostValues {
Deprecated?: boolean;
}
export interface WopiPost {
MessageId: string;
Values: WopiPostValues;
}

export interface WopiPostValues {
Deprecated?: boolean;
interface WindowCallbackHandler { (): Window}

interface PostMessageHandlerParam {
data: any;
parsed: { msgId: string, args: WopiPostValues, deprecated: boolean }
}

interface WindowCallbackHandler { (): Window}
type PostMessageHandler = (values: PostMessageHandlerParam) => void;

export default class PostMessageService {
private readonly targets: {[name: string]: (Window|WindowCallbackHandler)};
private postMessageHandlers: Function[] = [];

private readonly targets: {[name: string]: (Window|WindowCallbackHandler)}
private postMessageHandlers: PostMessageHandler[] = []

constructor(targets: {[name: string]: (Window|WindowCallbackHandler)}) {
this.targets = targets
Expand All @@ -29,7 +36,7 @@ export default class PostMessageService {
}

sendPostMessage(target: string, message: any, targetOrigin: string = '*') {
let targetElement: Window;
let targetElement: Window
if (typeof this.targets[target] === 'function') {
targetElement = (this.targets[target] as WindowCallbackHandler)()
} else {
Expand All @@ -39,12 +46,11 @@ export default class PostMessageService {
console.debug('PostMessageService.sendPostMessage', target, message)
}


sendWOPIPostMessage(target: string, msgId: string, values: any = {}) {
const msg = {
MessageId: msgId,
SendTime: Date.now(),
Values: values
Values: values,
}

this.sendPostMessage(target, JSON.stringify(msg))
Expand All @@ -66,17 +72,17 @@ export default class PostMessageService {
return { msgId, args, deprecated }
}

registerPostMessageHandler(callback: Function) {
registerPostMessageHandler(callback: PostMessageHandler) {
this.postMessageHandlers.push(callback)
}

unregisterPostMessageHandler(callback: Function) {
unregisterPostMessageHandler(callback: PostMessageHandler) {
const handlerIndex = this.postMessageHandlers.findIndex(cb => cb === callback)
delete this.postMessageHandlers[handlerIndex]
}

private handlePostMessage(data: any) {
const parsed = PostMessageService.parsePostMessage(data);
const parsed = PostMessageService.parsePostMessage(data)
if (typeof parsed === 'undefined' || parsed === null) {
return
}
Expand All @@ -88,15 +94,15 @@ export default class PostMessageService {
}
} catch (e) {}

this.postMessageHandlers.forEach((fn: Function): void => {
this.postMessageHandlers.forEach((fn: PostMessageHandler): void => {
if (parsed.deprecated) {
console.debug('PostMessageService.handlePostMessage', 'Ignoring deprecated post message', parsed.msgId)
return;
return
}
try {
fn({
data: data,
parsed
data,
parsed,
})
} catch (e) {
console.error('Error during post message handler', parsed, e)
Expand Down
5 changes: 2 additions & 3 deletions src/view/DocumentTargetPicker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,15 @@ export default {
}
},
async openFilePicker() {
const self = this
await getFilePickerBuilder(t('files', 'Select file or folder to link to'))
.setMimeTypeFilter(getCapabilities().mimetypes)
.addButton({
label: t('richdocuments', 'Insert image'),
callback: (files) => {
const file = files[0]
this.fileId = file.fileid
self.filePath = file.path
self.fetchReferences()
this.filePath = file.path
this.fetchReferences()
},
})
.setContainer(this.$refs.picker)
Expand Down
2 changes: 1 addition & 1 deletion src/viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ if (OCA.Viewer) {
})
}

autoSetupBuiltInCodeServerIfNeeded()
autoSetupBuiltInCodeServerIfNeeded()

0 comments on commit 4158fbe

Please sign in to comment.