Skip to content

Commit 02d3b40

Browse files
qti3episcisaureus
authored andcommitted
Implement Recent component
and resolve consistency between CSS classes in recent and profile.
1 parent 5f301c1 commit 02d3b40

File tree

4 files changed

+88
-21
lines changed

4 files changed

+88
-21
lines changed

src/components/profile.tsx

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,22 +40,17 @@ export class Profile extends Component<ProfileProps, {}> {
4040
return <h1>User has no notebooks.</h1>;
4141
}
4242
const doc = this.props.notebooks[0].doc;
43-
// TODO Profile is reusing the most-recent css class, because it's a very
44-
// similar layout. The CSS class should be renamed something appropriate
45-
// for both of them, maybe nb-listing.
4643
return (
47-
<div class="most-recent">
48-
<div class="most-recent-header">
44+
<div class="nb-listing">
45+
<div class="nb-listing-header">
4946
<UserTitle userInfo={doc.owner} />
5047
{newNotebookButton()}
5148
</div>
52-
<ol>
53-
<NotebookList
54-
showTitle={ true }
55-
notebooks={ this.props.notebooks }
56-
onClick={ this.onClick.bind(this) }
57-
/>
58-
</ol>
49+
<NotebookList
50+
showTitle={ true }
51+
notebooks={ this.props.notebooks }
52+
onClick={ this.onClick.bind(this) }
53+
/>
5954
</div>
6055
);
6156
}

src/components/recent.tsx

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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+
import { Component, h } from "preact";
17+
import * as types from "../types";
18+
import { NotebookList } from "./list";
19+
import { newNotebookButton } from "./new_notebook_button";
20+
import { profileLink } from "./user_title";
21+
22+
export interface RecentProps {
23+
mostRecent: types.NbInfo[];
24+
userInfo?: types.UserInfo;
25+
// TODO
26+
// onNewNotebookClicked?: () => void;
27+
onClick?: (nbId: string) => void;
28+
}
29+
30+
export interface RecentState {}
31+
32+
export class Recent extends Component<RecentProps, RecentState> {
33+
onClick(nbId: string) {
34+
if (this.props.onClick) this.props.onClick(nbId);
35+
}
36+
37+
render() {
38+
let profileLinkEl = null;
39+
if (this.props.userInfo) {
40+
// TODO This is ugly - we're reusing most-recent-header just to get a line
41+
// break between the link to "Your Notebooks" and "Most Recent".
42+
profileLinkEl = (
43+
<div class="most-recent-header">
44+
<h2>{profileLink(this.props.userInfo, "Your Notebooks")}</h2>
45+
</div>
46+
);
47+
}
48+
49+
return (
50+
<div class="nb-listing">
51+
{profileLinkEl}
52+
<div class="nb-listing-header">
53+
<div class="nb-listing-header-title">
54+
<h2>Recently Updated</h2>
55+
</div>
56+
<div class="nb-listing-header-cta">{newNotebookButton()}</div>
57+
</div>
58+
<NotebookList
59+
showTitle={ true }
60+
notebooks={ this.props.mostRecent }
61+
onClick={ this.onClick.bind(this) }
62+
/>
63+
</div>
64+
);
65+
}
66+
}

src/main.scss

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,7 @@ header {
640640
margin: 0 auto $size3 auto;
641641
}
642642

643-
.most-recent {
643+
.nb-listing {
644644
margin: 0 auto;
645645
padding: 0 8px;
646646
}
@@ -690,14 +690,14 @@ ol.notebooks-list {
690690
}
691691
}
692692

693-
.most-recent-header {
693+
.nb-listing-header {
694694
display: grid;
695695
grid-template-columns: auto auto;
696696
justify-content: space-between;
697697
max-width: 960px;
698698
margin: 0 auto;
699699

700-
.most-recent-header-cta {
700+
.nb-listing-header-cta {
701701
display: grid;
702702
align-content: center;
703703

@@ -707,7 +707,7 @@ ol.notebooks-list {
707707
}
708708
}
709709

710-
.most-recent-header-title {
710+
.nb-listing-header-title {
711711
display: flex;
712712
}
713713

@@ -758,7 +758,7 @@ ol.notebooks-list {
758758

759759
// Mobile first. No desktop related things above this line.
760760
@media (max-width: 1100px) {
761-
.most-recent {
761+
.nb-listing {
762762
max-width: 640px;
763763
}
764764
}

src/nb_test.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,18 +165,24 @@ testBrowser(async function notebook_urlImport() {
165165
const { notebookRef } = await renderAnonNotebook();
166166
const testdataUrl = `${location.origin}/static/testdata`;
167167

168-
const cell1 = await notebookRef.insertCell(1, `
168+
const cell1 = await notebookRef.insertCell(
169+
1,
170+
`
169171
import { assert, assertEqual } from "test_internals";
170172
import * as vegalite from "${testdataUrl}/[email protected]";
171173
import * as tf from "${testdataUrl}/[email protected]";
172174
assertEqual(typeof vegalite.compile, "function");
173175
const t = tf.ones([5, 5]);
174-
assertEqual(t.shape, [5, 5])`);
176+
assertEqual(t.shape, [5, 5])`
177+
);
175178
await notebookRef.onRun(cell1);
176179

177-
const cell2 = await notebookRef.insertCell(2, `
180+
const cell2 = await notebookRef.insertCell(
181+
2,
182+
`
178183
import * as tf2 from "${testdataUrl}/[email protected]";
179-
assertEqual(tf, tf2);`);
184+
assertEqual(tf, tf2);`
185+
);
180186
await notebookRef.onRun(cell2);
181187
});
182188

0 commit comments

Comments
 (0)