|
| 1 | +/* |
| 2 | + Copyright 2018 Propel http://propel.site/. All rights reserved. |
| 3 | + Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | + you may not use this file except in compliance with the License. |
| 5 | + You may obtain a copy of the License at |
| 6 | +
|
| 7 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +
|
| 9 | + Unless required by applicable law or agreed to in writing, software |
| 10 | + distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | + See the License for the specific language governing permissions and |
| 13 | + limitations under the License. |
| 14 | + */ |
| 15 | + |
| 16 | +/** |
| 17 | + * This is where Profile component is defined. |
| 18 | + * It can be used to render profile of a user. |
| 19 | + */ |
| 20 | + |
| 21 | +import { Component, h } from "preact"; |
| 22 | +import { newNotebookButton, UserTitle } from "./common"; |
| 23 | +import { NotebookList } from "./list"; |
| 24 | +import * as types from "./types"; |
| 25 | + |
| 26 | +export interface ProfileProps { |
| 27 | + userInfo: types.UserInfo; |
| 28 | + notebooks: types.NbInfo[]; |
| 29 | + onClick?: (nbId: string) => void; |
| 30 | +} |
| 31 | + |
| 32 | +export class Profile extends Component<ProfileProps, {}> { |
| 33 | + onClick(nbId: string) { |
| 34 | + if (this.props.onClick) this.props.onClick(nbId); |
| 35 | + } |
| 36 | + |
| 37 | + render() { |
| 38 | + if (this.props.notebooks.length === 0) { |
| 39 | + return <h1>User has no notebooks.</h1>; |
| 40 | + } |
| 41 | + const doc = this.props.notebooks[0].doc; |
| 42 | + // TODO Profile is reusing the most-recent css class, because it's a very |
| 43 | + // similar layout. The CSS class should be renamed something appropriate |
| 44 | + // for both of them, maybe nb-listing. |
| 45 | + return ( |
| 46 | + <div class="most-recent"> |
| 47 | + <div class="most-recent-header"> |
| 48 | + <UserTitle userInfo={doc.owner} /> |
| 49 | + {newNotebookButton()} |
| 50 | + </div> |
| 51 | + <ol> |
| 52 | + <NotebookList |
| 53 | + showTitle={ true } |
| 54 | + notebooks={ this.props.notebooks } |
| 55 | + onClick={ this.onClick.bind(this) } |
| 56 | + /> |
| 57 | + </ol> |
| 58 | + </div> |
| 59 | + ); |
| 60 | + } |
| 61 | +} |
0 commit comments