Skip to content

Commit 7ed2662

Browse files
committed
Implement Profile component
1 parent e67d375 commit 7ed2662

File tree

2 files changed

+84
-0
lines changed

2 files changed

+84
-0
lines changed

src/common.tsx

+23
Original file line numberDiff line numberDiff line change
@@ -138,3 +138,26 @@ export function profileLink(
138138
export function fmtDate(d: Date): string {
139139
return d.toISOString();
140140
}
141+
142+
export function nbUrl(nbId: string): string {
143+
// Careful, S3 is finicky about what URLs it serves. So
144+
// /notebook?nbId=blah will get redirect to /notebook/
145+
// because it is a directory with an index.html in it.
146+
const u = window.location.origin + "/notebook/?nbId=" + nbId;
147+
return u;
148+
}
149+
150+
export function newNotebookButton() {
151+
return (
152+
<button
153+
class="create-notebook"
154+
onClick={async () => {
155+
// Redirect to new notebook.
156+
const nbId = await db.active.create();
157+
window.location.href = nbUrl(nbId);
158+
}}
159+
>
160+
+ New Notebook
161+
</button>
162+
);
163+
}

src/profile.tsx

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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

Comments
 (0)