MOBILE-3320 DX: Fix lint warnings

main
Noel De Martin 2021-05-06 08:57:10 +02:00
parent 5b68977232
commit 61789f5550
11 changed files with 61 additions and 39 deletions

View File

@ -380,7 +380,9 @@ export class AddonModForumIndexComponent extends CoreCourseModuleMainActivityCom
} }
// Fill user data for Offline discussions (should be already cached). // Fill user data for Offline discussions (should be already cached).
const promises = offlineDiscussions.map(async (discussion: any) => { const promises = offlineDiscussions.map(async (offlineDiscussion) => {
const discussion = offlineDiscussion as unknown as AddonModForumDiscussion;
if (discussion.parent === 0 || forum.type === 'single') { if (discussion.parent === 0 || forum.type === 'single') {
// Do not show author for first post and type single. // Do not show author for first post and type single.
return; return;

View File

@ -71,8 +71,8 @@ export class AddonModForumPostComponent implements OnInit, OnDestroy, OnChanges
@Input() discussion?: AddonModForumDiscussion; // Post's' discussion, only for starting posts. @Input() discussion?: AddonModForumDiscussion; // Post's' discussion, only for starting posts.
@Input() component!: string; // Component this post belong to. @Input() component!: string; // Component this post belong to.
@Input() componentId!: number; // Component ID. @Input() componentId!: number; // Component ID.
@Input() replyData: any; // Object with the new post data. Usually shared between posts. @Input() replyData!: AddonModForumReply; // Object with the new post data. Usually shared between posts.
@Input() originalData: any; // Object with the original post data. Usually shared between posts. @Input() originalData!: Omit<AddonModForumReply, 'id'>; // Object with the original post data. Usually shared between posts.
@Input() trackPosts!: boolean; // True if post is being tracked. @Input() trackPosts!: boolean; // True if post is being tracked.
@Input() forum!: AddonModForumData; // The forum the post belongs to. Required for attachments and offline posts. @Input() forum!: AddonModForumData; // The forum the post belongs to. Required for attachments and offline posts.
@Input() accessInfo!: AddonModForumAccessInformation; // Forum access information. @Input() accessInfo!: AddonModForumAccessInformation; // Forum access information.
@ -103,7 +103,7 @@ export class AddonModForumPostComponent implements OnInit, OnDestroy, OnChanges
get showForm(): boolean { get showForm(): boolean {
return this.post.id > 0 return this.post.id > 0
? !this.replyData.isEditing && this.replyData.replyingTo === this.post.id ? !this.replyData.isEditing && this.replyData.replyingTo === this.post.id
: this.replyData.isEditing && this.replyData.replyingTo === this.post.parentid; : !!this.replyData.isEditing && this.replyData.replyingTo === this.post.parentid;
} }
/** /**
@ -275,7 +275,7 @@ export class AddonModForumPostComponent implements OnInit, OnDestroy, OnChanges
} }
// Add some HTML to the message if needed. // Add some HTML to the message if needed.
const message = CoreTextUtils.formatHtmlLines(data.message); const message = CoreTextUtils.formatHtmlLines(data.message!);
const files = data.files; const files = data.files;
const options: AddonModForumUpdateDiscussionPostWSOptionsObject = {}; const options: AddonModForumUpdateDiscussionPostWSOptionsObject = {};
@ -295,14 +295,14 @@ export class AddonModForumPostComponent implements OnInit, OnDestroy, OnChanges
} }
// Try to send it to server. // Try to send it to server.
const sent = await AddonModForum.updatePost(this.post.id, data.subject, message, options); const sent = await AddonModForum.updatePost(this.post.id, data.subject!, message, options);
if (sent && this.forum.id) { if (sent && this.forum.id) {
// Data sent to server, delete stored files (if any). // Data sent to server, delete stored files (if any).
AddonModForumHelper.deleteReplyStoredFiles(this.forum.id, this.post.id); AddonModForumHelper.deleteReplyStoredFiles(this.forum.id, this.post.id);
this.onPostChange.emit(); this.onPostChange.emit();
this.post.subject = data.subject; this.post.subject = data.subject!;
this.post.message = message; this.post.message = message;
this.post.attachments = data.files; this.post.attachments = data.files;
} }
@ -419,7 +419,7 @@ export class AddonModForumPostComponent implements OnInit, OnDestroy, OnChanges
let saveOffline = false; let saveOffline = false;
let message = this.replyData.message; let message = this.replyData.message;
const subject = this.replyData.subject; const subject = this.replyData.subject;
const replyingTo = this.replyData.replyingTo; const replyingTo = this.replyData.replyingTo!;
const files = this.replyData.files || []; const files = this.replyData.files || [];
const options: AddonModForumReplyOptions = {}; const options: AddonModForumReplyOptions = {};
const modal = await CoreDomUtils.showModalLoading('core.sending', true); const modal = await CoreDomUtils.showModalLoading('core.sending', true);

View File

@ -38,6 +38,7 @@ import {
AddonModForumDiscussion, AddonModForumDiscussion,
AddonModForumPost, AddonModForumPost,
AddonModForumProvider, AddonModForumProvider,
AddonModForumReply,
} from '../../services/forum'; } from '../../services/forum';
import { AddonModForumHelper } from '../../services/forum-helper'; import { AddonModForumHelper } from '../../services/forum-helper';
import { AddonModForumOffline } from '../../services/forum-offline'; import { AddonModForumOffline } from '../../services/forum-offline';
@ -72,18 +73,18 @@ export class AddonModForumDiscussionPage implements OnInit, AfterViewInit, OnDes
postHasOffline!: boolean; postHasOffline!: boolean;
sort: SortType = 'nested'; sort: SortType = 'nested';
trackPosts!: boolean; trackPosts!: boolean;
replyData = { replyData: Omit<AddonModForumReply, 'id'> = {
replyingTo: 0, replyingTo: 0,
isEditing: false, isEditing: false,
subject: '', subject: '',
message: null, // Null means empty or just white space. message: null,
files: [], files: [],
isprivatereply: false, isprivatereply: false,
}; };
originalData = { originalData: Omit<AddonModForumReply, 'id'> = {
subject: null, // Null means original data is not set. subject: null,
message: null, // Null means empty or just white space. message: null,
files: [], files: [],
isprivatereply: false, isprivatereply: false,
}; };

View File

@ -368,25 +368,25 @@ export class AddonModForumHelperProvider {
/** /**
* Check if the data of a post/discussion has changed. * Check if the data of a post/discussion has changed.
* *
* @param post Current data. * @param reply Current data.
* @param original Original ata. * @param original Original ata.
* @return True if data has changed, false otherwise. * @return True if data has changed, false otherwise.
*/ */
hasPostDataChanged(post: any, original?: any): boolean { hasPostDataChanged(reply: AddonModForumPostData, original?: AddonModForumPostData): boolean {
if (!original || original.subject == null) { if (!original || original.subject == null) {
// There is no original data, assume it hasn't changed. // There is no original data, assume it hasn't changed.
return false; return false;
} }
if (post.subject != original.subject || post.message != original.message) { if (reply.subject != original.subject || reply.message != original.message) {
return true; return true;
} }
if (post.isprivatereply != original.isprivatereply) { if (reply.isprivatereply != original.isprivatereply) {
return true; return true;
} }
return CoreFileUploader.areFileListDifferent(post.files, original.files); return CoreFileUploader.areFileListDifferent(reply.files ?? [], original.files ?? []);
} }
/** /**
@ -541,3 +541,13 @@ export class AddonModForumHelperProvider {
} }
export const AddonModForumHelper = makeSingleton(AddonModForumHelperProvider); export const AddonModForumHelper = makeSingleton(AddonModForumHelperProvider);
/**
* Forum post data used to check changes.
*/
type AddonModForumPostData = {
subject?: string | null;
message?: string | null;
isprivatereply?: boolean;
files?: CoreFileEntry[];
};

View File

@ -1407,7 +1407,7 @@ export type AddonModForumDiscussion = {
mailnow: number; // Mail now?. mailnow: number; // Mail now?.
userfullname: string | boolean; // Post author full name. userfullname: string | boolean; // Post author full name.
usermodifiedfullname: string; // Post modifier full name. usermodifiedfullname: string; // Post modifier full name.
userpictureurl: string; // Post author picture. userpictureurl?: string; // Post author picture.
usermodifiedpictureurl: string; // Post modifier picture. usermodifiedpictureurl: string; // Post modifier picture.
numreplies: number; // The number of replies in the discussion. numreplies: number; // The number of replies in the discussion.
numunread: number; // The number of unread discussions. numunread: number; // The number of unread discussions.
@ -1564,9 +1564,12 @@ export type AddonModForumAccessInformation = {
*/ */
export type AddonModForumReply = { export type AddonModForumReply = {
id: number; id: number;
subject: string; subject: string | null; // Null means original data is not set.
message: string; message: string | null; // Null means empty or just white space.
files: CoreFileEntry[]; files: CoreFileEntry[];
replyingTo?: number;
isEditing?: boolean;
isprivatereply?: boolean;
}; };
/** /**

View File

@ -45,7 +45,7 @@ export class AddonModForumDiscussionLinkHandlerService extends CoreContentLinksH
url: string, url: string,
params: Params, params: Params,
courseId?: number, courseId?: number,
data?: any, data?: { instance?: string; cmid?: string; postid?: string },
): CoreContentLinksAction[] | Promise<CoreContentLinksAction[]> { ): CoreContentLinksAction[] | Promise<CoreContentLinksAction[]> {
data = data || {}; data = data || {};
@ -56,13 +56,13 @@ export class AddonModForumDiscussionLinkHandlerService extends CoreContentLinksH
action: (siteId): void => { action: (siteId): void => {
const discussionId = parseInt(params.d, 10); const discussionId = parseInt(params.d, 10);
const pageParams: Params = { const pageParams: Params = {
forumId: data.instance && parseInt(data.instance, 10), forumId: data?.instance && parseInt(data.instance, 10),
cmId: data.cmid && parseInt(data.cmid, 10), cmId: data?.cmid && parseInt(data.cmid, 10),
courseId: courseId || parseInt(params.courseid, 10) || parseInt(params.cid, 10), courseId: courseId || parseInt(params.courseid, 10) || parseInt(params.cid, 10),
}; };
if (data.postid || params.urlHash) { if (data?.postid || params.urlHash) {
pageParams.postId = parseInt(data.postid || params.urlHash.replace('p', '')); pageParams.postId = parseInt(data?.postid || params.urlHash.replace('p', ''));
} }
if (params.parent) { if (params.parent) {

View File

@ -64,7 +64,7 @@ export class AddonModResourcePrefetchHandlerService extends CoreCourseResourcePr
dirPath = await CoreFilepool.getPackageDirPathByUrl(CoreSites.getCurrentSiteId(), module.url!); dirPath = await CoreFilepool.getPackageDirPathByUrl(CoreSites.getCurrentSiteId(), module.url!);
} }
const promises: Promise<any>[] = []; const promises: Promise<unknown>[] = [];
promises.push(super.downloadOrPrefetch(module, courseId, prefetch, dirPath)); promises.push(super.downloadOrPrefetch(module, courseId, prefetch, dirPath));

View File

@ -560,7 +560,7 @@ export class CoreSite {
return CoreUtils.clone(response); return CoreUtils.clone(response);
} }
const promise = this.getFromCache<T>(method, data, preSets, false).catch(() => { const promise = this.getFromCache<T>(method, data, preSets, false).catch(async () => {
if (preSets.forceOffline) { if (preSets.forceOffline) {
// Don't call the WS, just fail. // Don't call the WS, just fail.
throw new CoreError( throw new CoreError(
@ -569,13 +569,15 @@ export class CoreSite {
} }
// Call the WS. // Call the WS.
return this.callOrEnqueueRequest<T>(method, data, preSets, wsPreSets).then((response) => { try {
const response = await this.callOrEnqueueRequest<T>(method, data, preSets, wsPreSets);
if (preSets.saveToCache) { if (preSets.saveToCache) {
this.saveToCache(method, data, response, preSets); this.saveToCache(method, data, response, preSets);
} }
return response; return response;
}).catch((error) => { } catch (error) {
if (error.errorcode == 'invalidtoken' || if (error.errorcode == 'invalidtoken' ||
(error.errorcode == 'accessexception' && error.message.indexOf('Invalid token - token expired') > -1)) { (error.errorcode == 'accessexception' && error.message.indexOf('Invalid token - token expired') > -1)) {
if (initialToken !== this.token && !retrying) { if (initialToken !== this.token && !retrying) {
@ -585,7 +587,9 @@ export class CoreSite {
return this.request<T>(method, data, preSets, true); return this.request<T>(method, data, preSets, true);
} else if (CoreApp.isSSOAuthenticationOngoing()) { } else if (CoreApp.isSSOAuthenticationOngoing()) {
// There's an SSO authentication ongoing, wait for it to finish and try again. // There's an SSO authentication ongoing, wait for it to finish and try again.
return CoreApp.waitForSSOAuthentication().then(() => this.request<T>(method, data, preSets, true)); await CoreApp.waitForSSOAuthentication();
return this.request<T>(method, data, preSets, true);
} }
// Session expired, trigger event. // Session expired, trigger event.
@ -649,9 +653,7 @@ export class CoreSite {
if (preSets.deleteCacheIfWSError && CoreUtils.isWebServiceError(error)) { if (preSets.deleteCacheIfWSError && CoreUtils.isWebServiceError(error)) {
// Delete the cache entry and return the entry. Don't block the user with the delete. // Delete the cache entry and return the entry. Don't block the user with the delete.
this.deleteFromCache(method, data, preSets).catch(() => { CoreUtils.ignoreErrors(this.deleteFromCache(method, data, preSets));
// Ignore errors.
});
throw new CoreWSError(error); throw new CoreWSError(error);
} }
@ -660,10 +662,12 @@ export class CoreSite {
preSets.omitExpires = true; preSets.omitExpires = true;
preSets.getFromCache = true; preSets.getFromCache = true;
return this.getFromCache<T>(method, data, preSets, true).catch(() => { try {
return await this.getFromCache<T>(method, data, preSets, true);
} catch (e) {
throw new CoreWSError(error); throw new CoreWSError(error);
}); }
}); }
// eslint-disable-next-line @typescript-eslint/no-explicit-any // eslint-disable-next-line @typescript-eslint/no-explicit-any
}).then((response: any) => { }).then((response: any) => {
// Check if the response is an error, this happens if the error was stored in the cache. // Check if the response is an error, this happens if the error was stored in the cache.

View File

@ -34,10 +34,10 @@ export class CoreBlockComponent implements OnInit, OnDestroy, DoCheck {
@Input() block!: CoreCourseBlock; // The block to render. @Input() block!: CoreCourseBlock; // The block to render.
@Input() contextLevel!: string; // The context where the block will be used. @Input() contextLevel!: string; // The context where the block will be used.
@Input() instanceId!: number; // The instance ID associated with the context level. @Input() instanceId!: number; // The instance ID associated with the context level.
@Input() extraData: any; // Any extra data to be passed to the block. @Input() extraData!: Record<string, unknown>; // Any extra data to be passed to the block.
componentClass?: Type<unknown>; // The class of the component to render. componentClass?: Type<unknown>; // The class of the component to render.
data: any = {}; // Data to pass to the component. data: Record<string, unknown> = {}; // Data to pass to the component.
class?: string; // CSS class to apply to the block. class?: string; // CSS class to apply to the block.
loaded = false; loaded = false;

View File

@ -309,6 +309,7 @@ export class CoreNavigatorService {
* @return Value of the parameter, undefined if not found. * @return Value of the parameter, undefined if not found.
*/ */
getRouteParam<T = unknown>(name: string, routeOptions: CoreNavigatorCurrentRouteOptions = {}): T | undefined { getRouteParam<T = unknown>(name: string, routeOptions: CoreNavigatorCurrentRouteOptions = {}): T | undefined {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
let value: any; let value: any;
if (!routeOptions.params) { if (!routeOptions.params) {

View File

@ -19,6 +19,7 @@ declare module '@ionic/angular' {
export class NavController { export class NavController {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
navigateForward(url: string | UrlTree | any[], options?: NavigationOptions): Promise<boolean | null>; navigateForward(url: string | UrlTree | any[], options?: NavigationOptions): Promise<boolean | null>;
} }