Skip to content
This repository has been archived by the owner on May 30, 2019. It is now read-only.

profile pages #407

Merged
merged 4 commits into from
Mar 29, 2018
Merged

profile pages #407

merged 4 commits into from
Mar 29, 2018

Conversation

alaq
Copy link
Contributor

@alaq alaq commented Mar 21, 2018

  • Created separate profile page per user.
  • Added last three notebooks by logged in user to the top of /notebook
    • If user has no notebook, message is displayed (maybe not display anything instead? no header?)
  • User's names are clickable and redirecting to user's profile

No error/warning in ./tools/tslint.js
This addresses #297

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) {
Copy link
Contributor

@ry ry Mar 21, 2018

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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);
Copy link
Contributor

@ry ry Mar 21, 2018

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[] {
Copy link
Contributor

@ry ry Mar 21, 2018

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[]> {
Copy link
Contributor

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();
Copy link
Contributor

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()

Copy link
Contributor

@ry ry left a 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 : )

@alaq
Copy link
Contributor Author

alaq commented Mar 21, 2018

I believe the changes have been addressed. Let me know.

.notebook-container {
max-width: 960px;
margin: 0 auto;
padding: 0 8px;
Copy link
Contributor

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;
Copy link
Contributor

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;
Copy link
Contributor

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;
Copy link
Contributor

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");
}

Copy link
Contributor

@ry ry left a 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 [];
    }
  }

@ry ry mentioned this pull request Mar 22, 2018
@alaq alaq force-pushed the profiles branch 3 times, most recently from fbc5829 to 0d8b11b Compare March 26, 2018 19:13
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;
Copy link
Contributor

@ry ry Mar 27, 2018

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);
Copy link
Contributor

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))),
Copy link
Contributor

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?

@alaq alaq force-pushed the profiles branch 3 times, most recently from de9c12b to 3581e8a Compare March 27, 2018 18:56
alaq and others added 4 commits March 27, 2018 20:12
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.
@alaq
Copy link
Contributor Author

alaq commented Mar 28, 2018

Requested changes have been applied, and @ry refactoring as well.
I believe this branch is ready to be merged.

Please review.

@ry
Copy link
Contributor

ry commented Mar 28, 2018

I agree, I think it's ready now.
@piscisaureus Please review

@ry ry requested a review from piscisaureus March 28, 2018 15:57
@piscisaureus
Copy link
Member

The code changes look good to me.
However I think this is not rendering as intended: https://snag.gy/MOyb4N.jpg

@ry
Copy link
Contributor

ry commented Mar 29, 2018

That’s as intended. I’ll let a designer make a second pass.

@ry ry merged commit 6abb9cf into propelml:master Mar 29, 2018
@ry
Copy link
Contributor

ry commented Mar 29, 2018

Thank you @alaq ! This is a massive improvement to the website!

@ry
Copy link
Contributor

ry commented Mar 29, 2018

Profile pages uploaded to the main site. I'm finally able to explore @qti3e's notebooks : )
http://propelml.org/notebook/?profile=nsDPpi960tUR7Y5pmbsMs0zzkN42

Again thanks for trudging thru this @alaq

@alaq
Copy link
Contributor Author

alaq commented Mar 29, 2018

My pleasure @ry
Now that I can see all of mine too, I feel like I should be able to delete the ones that I am ashamed of

@alaq alaq deleted the profiles branch March 29, 2018 16:51
@ry
Copy link
Contributor

ry commented Mar 29, 2018

@alaq I had the same thought #460

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants