import * as React from 'react';
import styles from './IocTests.module.scss';
import IListsService, { IList } from '../../../common/services/Lists/IListsService';
import ICacheProvider, { CacheTimeout } from '../../../common/providers/Cache/ICacheProvider';
import ILogProvider from '../../../common/providers/Log/ILogProvider';
export interface IocTestsProps {
cacheProvider: ICacheProvider;
logProvider: ILogProvider;
listsService: IListsService;
}
export interface IocTestsState {
lists: IList[];
}
export default class IocTests extends React.Component<IocTestsProps, IocTestsState> {
private className: string = "IocTests";
constructor(props: IocTestsProps) {
super(props);
this.state = {
lists: null
};
}
public async componentDidMount(): Promise<void> {
// LOG PROVIDER
await this.props.logProvider.Debug(this.className, "componentDidMount", null);
// CACHE PROVIDER
const cacheKey = "IocTestsGetLists";
let lists: IList[] = await this.props.cacheProvider.Get(cacheKey);
if (!lists) {
// LISTS SERVICE
lists = await this.props.listsService.GetLists();
// CACHE PROVIDER
await this.props.cacheProvider.Set(cacheKey, lists, CacheTimeout.default);
}
this.setState({
lists: lists
});
}
public render(): React.ReactElement<IocTestsProps> {
this.props.logProvider.Debug(this.className, "render", null);
return (
<div id={ styles.iocTests } className={ styles.iocTests }>
<div className={ styles.container }>
{ !this.state.lists &&
<span> Loading... </span>
}
{ !!this.state.lists && this.state.lists.map(l => {
return (
<div key={l.Title}>
<a href={l.DefaultViewUrl} target={"_blank"}>{l.Title}</a>
</div>
);
})
}
</div>
</div>
);
}
}
|