updated code for mobile check and guid

This commit is contained in:
Arun Kumar Perumal 2022-06-02 18:46:57 +05:30
parent 11eeda7168
commit 4f8398055c
1 changed files with 6 additions and 29 deletions

View File

@ -1,6 +1,7 @@
import * as React from 'react'; import * as React from 'react';
import * as ReactDom from 'react-dom'; import * as ReactDom from 'react-dom';
import { Version } from '@microsoft/sp-core-library'; import { Version, Guid } from '@microsoft/sp-core-library';
import { BrowserUtilities } from '@microsoft/sp-core-library/lib-commonjs/BrowserUtilities';
import { import {
BaseClientSideWebPart, BaseClientSideWebPart,
@ -43,8 +44,9 @@ export default class FaqsWebPart extends BaseClientSideWebPart<IFaqsWebPartProps
super(); super();
//Initialize unique GUID //Initialize unique GUID
this.guid = this.getGuid(); this.guid = Guid.newGuid().toString();
this.isMobile = this.detectmob(); this.isMobile = BrowserUtilities.isMobileBrowser();
//Hack: to invoke correctly the onPropertyChange function outside this class //Hack: to invoke correctly the onPropertyChange function outside this class
//we need to bind this object on it first //we need to bind this object on it first
this.onPropertyPaneFieldChanged = this.onPropertyPaneFieldChanged.bind(this); this.onPropertyPaneFieldChanged = this.onPropertyPaneFieldChanged.bind(this);
@ -98,13 +100,7 @@ export default class FaqsWebPart extends BaseClientSideWebPart<IFaqsWebPartProps
} }
} }
private detectmob(): boolean {
if(window.innerWidth <= 480) {
return true;
} else {
return false;
}
}
protected onDispose(): void { protected onDispose(): void {
ReactDom.unmountComponentAtNode(this.domElement); ReactDom.unmountComponentAtNode(this.domElement);
@ -114,25 +110,6 @@ export default class FaqsWebPart extends BaseClientSideWebPart<IFaqsWebPartProps
return Version.parse('1.0'); return Version.parse('1.0');
} }
/**
* @function
* Generates a GUID
*/
private getGuid(): string {
return this.s4() + this.s4() + '-' + this.s4() + '-' + this.s4() + '-' +
this.s4() + '-' + this.s4() + this.s4() + this.s4();
}
/**
* @function
* Generates a GUID part
*/
private s4(): string {
return Math.floor((1 + Math.random()) * 0x10000)
.toString(16)
.substring(1);
}
//executes only before property pane is loaded. //executes only before property pane is loaded.
protected async loadPropertyPaneResources(): Promise<void> { protected async loadPropertyPaneResources(): Promise<void> {
// import additional controls/components // import additional controls/components