Skip to content
This repository has been archived by the owner on Feb 29, 2020. It is now read-only.

feat (systemaddon): #2944 add tippy top icons #3049

Merged
merged 1 commit into from
Aug 1, 2017

Conversation

rlr
Copy link
Contributor

@rlr rlr commented Aug 1, 2017

Fixes #2944

image

@coveralls
Copy link

Coverage Status

Coverage remained the same at 86.407% when pulling 202375f on rlr:gh2944/tippy-tops into c51a689 on mozilla:master.

@rlr
Copy link
Contributor Author

rlr commented Aug 1, 2017

We still need to cut a limited tippy top release but that can be done as a quick followup.

r? @Mardak and/or @jaredkerim and/or ?

@rlr rlr requested a review from Mardak August 1, 2017 02:44
Copy link
Member

@Mardak Mardak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like things are working fine. Just a bunch of various nits

}
{!showScreenshot &&
<div className="tippy-top-icon" style={style} />
}
Copy link
Member

@Mardak Mardak Aug 1, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like it could just be maybe <div className={imageClassName} style={imageStyle} /> and unconditionally render that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or… we could be even fancier :p ?
<div {...imageAttributes} />

@@ -43,12 +43,24 @@ class TopSite extends React.Component {
const title = link.pinTitle || shortURL(link);
const screenshotClassName = `screenshot${link.screenshot ? " active" : ""}`;
const topSiteOuterClassName = `top-site-outer${isContextMenuOpen ? " active" : ""}`;
const style = {backgroundImage: (link.screenshot ? `url(${link.screenshot})` : "none")};
const tippyTopIcon = link.tippyTopIcon;
const showScreenshot = !tippyTopIcon;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: just make this const {tippyTopIcon} = link;

const style = {backgroundImage: (link.screenshot ? `url(${link.screenshot})` : "none")};
const tippyTopIcon = link.tippyTopIcon;
const showScreenshot = !tippyTopIcon;
let style;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're going to have a imageClassName then let's make this imageStyle.

if (showScreenshot) {
style = {backgroundImage: (link.screenshot ? `url(${link.screenshot})` : "none")};
} else {
style = {backgroundImage: `url(${tippyTopIcon})`, backgroundColor: link.backgroundColor || "none"};
Copy link
Member

@Mardak Mardak Aug 1, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: let's split this latter object (with 2 keys) onto multiple lines. And just make the condition

if (tippyTopIcon) {
  imageClassName = "tippy-top-icon";
  imageStyle = {
    backgroundColor: ,
    backgroundImage: 
  };
} else {
  imageClassName = `screenshot${link.screenshot ? " active" : ""}`; // can get rid of the const screenshotClassName
  imageStyle = {backgroundImage: }
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that turned out nice like that 👍

// Load the Tippy Top sites from the json manifest.
fetch(TIPPYTOP_JSON_PATH)
.then(response => response.json())
.then(sites => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These should be awaits given that we're inside an async function

try {
  for (const site of await (await fetch(PATH)).json()) {
 
} catch(error) 

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do I need to stub it out differently in tests to do this? I can't get them to work now for some reason.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops nvm. there waz a typo

for (let link of links) {
if (!link) { continue; }

// Check for tippy top icon.
link = this._tippyTopProvider.processSite(link);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, this seems like it could fail or give wrong results if TippyTopProvider hasn't finished adding to _sitesByDomain. I would guess the correct fix is to make processSite async. But we can skip this for 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.

Yeah, figured it should just should just move on if it isn't fully init'd instead of waiting. I guess we would want to dispatch an action when init is done to refresh again. Maybe there should be a tippy top feed like you suggested 🤔

Copy link
Member

@Mardak Mardak Aug 1, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, Provider doesn't have the usual dispatch, but it async init returns a promise that TopSitesFeed could use to have refresh wait until Provider is inited . E.g.,

TopSitesFeed {
constructor() {
  const provider = new TippyTopProvider();
  this._initedProvider = provider.init(); // init needs to resolve the provider
}
async refresh() {
  
  (await this._initedProvider).processSite(link);

This can be separately handled as a followup as I expect the tests would need to change a bit.

Also, it wouldn't allow for the "just move on" if that's desired.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool, I'll look into that after doing the tippy top release for default sites

@@ -22,8 +23,11 @@ const DEFAULT_TOP_SITES = [];
this.TopSitesFeed = class TopSitesFeed {
constructor() {
this.lastUpdated = 0;
this._tippyTopProvider = new TippyTopProvider();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@k88hudson any thoughts on having this TippyTopProvider vs a TippyTopFeed? If we do want a feed, we should just refactor it later. I could see the feed dispatching a mapping of domains to urls, but then again, would we want all that data going to stores and the content process?

yamscripts.yml Outdated

copyTippyTopManifest: cpx "node_modules/tippy-top-sites/top_sites.json" system-addon/data/content/tippytop

copyTippyTopImages: cpx "node_modules/tippy-top-sites/images/**/*" system-addon/data/content/tippytop/images
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this seems better organized as

tippymc:
  pre: rimraf …
  manifest: cpx …
  images: cpx …

yamscripts.yml Outdated
# buildmc: Export the bootstraped add-on to mozilla central
buildmc:
pre: rimraf ../mozilla-central/browser/extensions/activity-stream
pre: =>cleanmc && =>cleanTippyTop && =>copyTippyTopManifest && =>copyTippyTopImages
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

then this would just be => cleanmc && => tippymc

}
if ("urls" in site) {
for (let url of site.urls) {
this._sitesByDomain[getDomain(url)] = site;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: This seems a bit awkward with the repetition. Maybe

for (const url of site.url ? [site.url] : site.urls || []) {
  this._sitesByDomain.set(getDomain(url), site);

Or maybe that's just too clever :p It would want a comment ;) Also not quite exactly the same logic as it doesn't allow for both url and urls to exist..

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kind of likey 😉

}
init() {
this._tippyTopProvider.init();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the conflict with removing TopSitesFeed.init Maybe just call this just after constructing it from TopSitesFeed.constructor ?

@coveralls
Copy link

Coverage Status

Coverage remained the same at 86.407% when pulling 5aae927 on rlr:gh2944/tippy-tops into 729f4c6 on mozilla:master.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 86.407% when pulling 172a055 on rlr:gh2944/tippy-tops into 729f4c6 on mozilla:master.

@as-pine-proxy
Copy link
Collaborator

@rlr rlr deleted the gh2944/tippy-tops branch August 1, 2017 20:57
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants