Refactor import statements and improve code formatting in ModernPromotedLinks components
This commit is contained in:
Vendored
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
declare module '*.module.scss' {
|
declare module '*.module.scss' {
|
||||||
const styles: { [className: string]: string };
|
const styles: { [className: string]: string };
|
||||||
export = styles;
|
export default styles;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ import { PromotedLinksDataService } from './PromotedLinksDataService';
|
|||||||
import { IPromotedLinkItem, IPromotedLinksListOption } from './PromotedLinkTypes';
|
import { IPromotedLinkItem, IPromotedLinksListOption } from './PromotedLinkTypes';
|
||||||
import ModernPromotedLinks from './components/ModernPromotedLinks';
|
import ModernPromotedLinks from './components/ModernPromotedLinks';
|
||||||
import { IModernPromotedLinksProps } from './components/IModernPromotedLinksProps';
|
import { IModernPromotedLinksProps } from './components/IModernPromotedLinksProps';
|
||||||
import styles = require('./components/ModernPromotedLinks.module.scss');
|
import styles from './components/ModernPromotedLinks.module.scss';
|
||||||
|
|
||||||
export interface IModernPromotedLinksWebPartProps {
|
export interface IModernPromotedLinksWebPartProps {
|
||||||
listId: string;
|
listId: string;
|
||||||
@@ -31,11 +31,6 @@ export default class ModernPromotedLinksWebPart extends BaseClientSideWebPart<IM
|
|||||||
private requestVersion: number = 0;
|
private requestVersion: number = 0;
|
||||||
private disposed: boolean = false;
|
private disposed: boolean = false;
|
||||||
|
|
||||||
protected onInit(): Promise<void> {
|
|
||||||
this.service = new PromotedLinksDataService(this.context);
|
|
||||||
return super.onInit().then((): Promise<void> => this.loadLists());
|
|
||||||
}
|
|
||||||
|
|
||||||
public render(): void {
|
public render(): void {
|
||||||
const version: number = ++this.requestVersion;
|
const version: number = ++this.requestVersion;
|
||||||
if (!this.properties.listId) { this.renderStatus(strings.ConfigureMessage, false); return; }
|
if (!this.properties.listId) { this.renderStatus(strings.ConfigureMessage, false); return; }
|
||||||
@@ -58,6 +53,11 @@ export default class ModernPromotedLinksWebPart extends BaseClientSideWebPart<IM
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected onInit(): Promise<void> {
|
||||||
|
this.service = new PromotedLinksDataService(this.context);
|
||||||
|
return super.onInit().then((): Promise<void> => this.loadLists());
|
||||||
|
}
|
||||||
|
|
||||||
protected onDispose(): void {
|
protected onDispose(): void {
|
||||||
this.disposed = true;
|
this.disposed = true;
|
||||||
this.requestVersion++;
|
this.requestVersion++;
|
||||||
|
|||||||
@@ -34,7 +34,9 @@ export class PromotedLinksDataService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private get webUrl(): string { return this.context.pageContext.web.absoluteUrl.replace(/\/$/, ''); }
|
private get webUrl(): string { return this.context.pageContext.web.absoluteUrl.replace(/\/$/, ''); }
|
||||||
private get headers(): any { return { 'Accept': 'application/json;odata=verbose', 'OData-Version': '3.0' }; } // tslint:disable-line:no-any
|
private get headers(): any { // tslint:disable-line:no-any
|
||||||
|
return { 'Accept': 'application/json;odata=verbose', 'OData-Version': '3.0' };
|
||||||
|
}
|
||||||
|
|
||||||
private getJson(url: string): Promise<any> { // tslint:disable-line:no-any
|
private getJson(url: string): Promise<any> { // tslint:disable-line:no-any
|
||||||
return this.context.spHttpClient.get(url, SPHttpClient.configurations.v1, { headers: this.headers })
|
return this.context.spHttpClient.get(url, SPHttpClient.configurations.v1, { headers: this.headers })
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import { isDialogLaunch, isNewTabLaunch } from '../PromotedLinkCore';
|
import { isDialogLaunch, isNewTabLaunch } from '../PromotedLinkCore';
|
||||||
import { IPromotedLinkItem } from '../PromotedLinkTypes';
|
import { IPromotedLinkItem } from '../PromotedLinkTypes';
|
||||||
import styles = require('./ModernPromotedLinks.module.scss');
|
import styles from './ModernPromotedLinks.module.scss';
|
||||||
import { IModernPromotedLinksProps } from './IModernPromotedLinksProps';
|
import { IModernPromotedLinksProps } from './IModernPromotedLinksProps';
|
||||||
|
|
||||||
export default class ModernPromotedLinks extends React.Component<IModernPromotedLinksProps, {}> {
|
export default class ModernPromotedLinks extends React.Component<IModernPromotedLinksProps, {}> {
|
||||||
@@ -19,17 +19,21 @@ export default class ModernPromotedLinks extends React.Component<IModernPromoted
|
|||||||
private renderTile(item: IPromotedLinkItem): JSX.Element {
|
private renderTile(item: IPromotedLinkItem): JSX.Element {
|
||||||
const newTab: boolean = isNewTabLaunch(item.launchBehavior);
|
const newTab: boolean = isNewTabLaunch(item.launchBehavior);
|
||||||
const dialog: boolean = isDialogLaunch(item.launchBehavior);
|
const dialog: boolean = isDialogLaunch(item.launchBehavior);
|
||||||
const imageStyle: React.CSSProperties = item.imageUrl ? { backgroundImage: 'url("' + this.cssUrl(item.imageUrl) + '")' } : {};
|
const imageStyle: React.CSSProperties = item.imageUrl ? {
|
||||||
|
backgroundImage: 'url("' + this.cssUrl(item.imageUrl) + '")'
|
||||||
|
} : {};
|
||||||
const label: string = item.description ? item.title + '. ' + item.description : item.title;
|
const label: string = item.description ? item.title + '. ' + item.description : item.title;
|
||||||
return (
|
return (
|
||||||
<li key={item.id} className={styles.tile} style={{ height: this.props.tileHeight + 'px' }}>
|
<li key={item.id} className={styles.tile} style={{ height: this.props.tileHeight + 'px' }}>
|
||||||
<a className={styles.link} href={item.linkUrl} style={imageStyle} aria-label={label}
|
<a className={styles.link} href={item.linkUrl} style={imageStyle} aria-label={label}
|
||||||
target={newTab ? '_blank' : undefined} rel={newTab ? 'noopener noreferrer' : undefined}
|
target={newTab ? '_blank' : undefined} rel={newTab ? 'noopener noreferrer' : undefined}
|
||||||
onClick={dialog ? (event: React.MouseEvent<HTMLAnchorElement>): void => this.openDialog(event, item) : undefined}>
|
onClick={dialog ? (event: React.MouseEvent<HTMLAnchorElement>): void =>
|
||||||
|
this.openDialog(event, item) : undefined}>
|
||||||
{!item.imageUrl && <span className={styles.fallbackIcon} aria-hidden='true'>↗</span>}
|
{!item.imageUrl && <span className={styles.fallbackIcon} aria-hidden='true'>↗</span>}
|
||||||
<span className={styles.overlay}>
|
<span className={styles.overlay}>
|
||||||
<span className={styles.title}>{item.title || item.linkUrl}</span>
|
<span className={styles.title}>{item.title || item.linkUrl}</span>
|
||||||
{this.props.showDescriptions && item.description && <span className={styles.description}>{item.description}</span>}
|
{this.props.showDescriptions && item.description &&
|
||||||
|
<span className={styles.description}>{item.description}</span>}
|
||||||
</span>
|
</span>
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
@@ -42,7 +46,7 @@ export default class ModernPromotedLinks extends React.Component<IModernPromoted
|
|||||||
const height: number = Math.min(800, Math.max(480, window.innerHeight - 80));
|
const height: number = Math.min(800, Math.max(480, window.innerHeight - 80));
|
||||||
const child: Window = window.open(item.linkUrl, this.props.dialogWindowLabel + item.id,
|
const child: Window = window.open(item.linkUrl, this.props.dialogWindowLabel + item.id,
|
||||||
'width=' + width + ',height=' + height + ',resizable=yes,scrollbars=yes') as Window;
|
'width=' + width + ',height=' + height + ',resizable=yes,scrollbars=yes') as Window;
|
||||||
if (child) { child.opener = null; }
|
if (child) { child.opener = undefined; }
|
||||||
}
|
}
|
||||||
|
|
||||||
private cssUrl(value: string): string {
|
private cssUrl(value: string): string {
|
||||||
|
|||||||
Reference in New Issue
Block a user