-
Notifications
You must be signed in to change notification settings - Fork 104
Conversation
website/nb.ts
Outdated
async componentWillMount() { | ||
// Only query firebase when in the browser. | ||
// This is to avoiding calling into firebase during static HTML generation. | ||
if (IS_WEB) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove the if (IS_WEB)
and the comment above. The if (IS_WEB) isn't necessary (despite it being erroneously used in elsewhere in this file) this code is only executed on web now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I went ahead and removed it from the other location in the file, if that's okay.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, thanks!
website/nb.ts
Outdated
@@ -464,7 +480,8 @@ export class MostRecent extends Component<any, MostRecentState> { | |||
// This is to avoiding calling into firebase during static HTML generation. | |||
if (IS_WEB) { | |||
const latest = await db.active.queryLatest(); | |||
this.setState({latest}); | |||
const own = await db.active.queryProfile(this.props.uid); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When loading "/notebook" I get a crash here because this.props.uid
is undefined.
Also, if MostRecent is going to take props, please add a MostRecentProps interface
website/nb.ts
Outdated
@@ -687,6 +751,19 @@ export class Notebook extends Component<NotebookProps, NotebookState> { | |||
} | |||
} | |||
|
|||
function notebookList(notebooks: db.NbInfo[]): JSX.Element[] { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice
website/db.ts
Outdated
@@ -167,6 +168,19 @@ class DatabaseFB implements Database { | |||
return out.reverse(); | |||
} | |||
|
|||
async queryProfile(uid): Promise<NbInfo[]> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
uid: string
website/db.ts
Outdated
const doc = snap.data(); | ||
out.unshift({ nbId, doc }); | ||
}); | ||
return out.reverse(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you used push()
instead of unshift()
, you wouldn't have to call reverse()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fantastic!! It needs some clean up - it crashes when I load /notebook
for example - but this is the first time I've been able to see my list of notebooks, so it's really adding some much needed functionality : )
I believe the changes have been addressed. Let me know. |
website/main.scss
Outdated
.notebook-container { | ||
max-width: 960px; | ||
margin: 0 auto; | ||
padding: 0 8px; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like an unrelated change. In fact, if we left out all the css changes completely - would it look terrible? I'd rather land the functionality first and then clean up the style later.
website/nb.ts
Outdated
|
||
export interface ProfileState { | ||
latest: db.NbInfo[]; | ||
profile: string; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ProfileState.profile is unused.
website/nb.ts
Outdated
|
||
export interface ProfileProps { | ||
uid: string; | ||
userInfo?: db.UserInfo; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ProfileProps.userInfo is unused.
website/nb.ts
Outdated
if (!this.state.latest) { | ||
return h(Loading, null); | ||
} | ||
const doc = this.state.latest[0].doc; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It crashes here if this.state.latest
is empty. You can do something simple for now like this:
if (this.state.latest.length === 0) {
return h("h1", null, "User has no notebooks");
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks better - not crashing and working properly. I have a few comments...
Please add a test
testBrowser(async function notebook_profileSmoke() {
let mdb = enableMock();
resetPage();
let el = h(nb.Profile, { uid: "non-existant" });
render(el, document.body);
await Promise.resolve(); // Wait for promise queue to flush.
let profileBlurbs = document.querySelectorAll(".profile-blurb");
assert(profileBlurbs.length === 0);
assert(objectsEqual(mdb.counts, { queryProfile: 1 }));
// Try again with a real uid.
mdb = enableMock();
resetPage();
el = h(nb.Profile, { uid: db.defaultOwner.uid });
render(el, document.body);
await Promise.resolve(); // Wait for promise queue to flush.
profileBlurbs = document.querySelectorAll(".profile-blurb");
assert(profileBlurbs.length === 1);
assert(objectsEqual(mdb.counts, { queryProfile: 1 }));
});
(Feel free to expand on this / clean it up)
In the db.ts you can modify the queryProfile to do something like this:
async queryProfile(uid: string): Promise<NbInfo[]> {
this.inc("queryProfile");
if (uid === defaultOwner.uid) {
return [{ nbId: "default", doc: defaultDoc }];
} else {
return [];
}
}
fbc5829
to
0d8b11b
Compare
website/nb.ts
Outdated
@@ -431,10 +431,12 @@ export class FixedCell extends Component<FixedProps, CellState> { | |||
export interface NotebookRootProps { | |||
userInfo?: db.UserInfo; | |||
nbId?: string; | |||
uid?: string; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is getting a bit confusing with all these ids. So "uid" is supposed to be the user id of the profile we want to display, while "userInfo" is info about the logged in user. I'd suggest changing "uid" to "profileUid". You can leave "userInfo" as is, but I will change it in the future to be "currentUserInfo".
Also, what's the purpose of having uid both in the Props and State? It seems it doesn't need to be in the props?
website/nb.ts
Outdated
this.setState({latest}); | ||
} | ||
const latest = await db.active.queryLatest(); | ||
const own = await db.active.queryProfile(this.props.uid); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a bit unfortunate that we're doing two queries... Maybe make a comment
// TODO potentially these two queries can be combined into one.
website/nb.ts
Outdated
), | ||
h("div", {"class": "most-recent-header-cta"}, | ||
h("button", { "class": "create-notebook", | ||
"onClick": () => this.onCreate(), | ||
}, "+ New Notebook"), | ||
), | ||
), | ||
h("ol", null, ...notebookList), | ||
empty, | ||
h("ol", null, ...notebookList(this.state.own.slice(0, 3))), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you're only using 3 of the results, maybe limit the query to only return three?
de9c12b
to
3581e8a
Compare
Fix overflow on notebook links. Plus other visual clean ups
Now NotebookRoot makes all the queries and passes state downwards. This makes it easier to check for readiness in the tests and display errors more consistently.
Requested changes have been applied, and @ry refactoring as well. Please review. |
I agree, I think it's ready now. |
The code changes look good to me. |
That’s as intended. I’ll let a designer make a second pass. |
Thank you @alaq ! This is a massive improvement to the website! |
Profile pages uploaded to the main site. I'm finally able to explore @qti3e's notebooks : ) Again thanks for trudging thru this @alaq |
My pleasure @ry |
/notebook
No error/warning in
./tools/tslint.js
This addresses #297