Skip to content

Commit

Permalink
Bug 1783024 - Tweaked load order for Save To Pocket r=thecount
Browse files Browse the repository at this point in the history
  • Loading branch information
gvn committed Aug 16, 2022
1 parent c009401 commit 8f02299
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ function Saved(props) {
setRemovedStatusState,
] = useState({});
const [savedStory, setSavedStoryState] = useState();
const [articleInfoAttempted, setArticleInfoAttempted] = useState();
const [{ similarRecs, similarRecsModel }, setSimilarRecsState] = useState({});
const utmParams = `utm_source=${utmSource}${
utmCampaign && utmContent
Expand Down Expand Up @@ -80,10 +81,16 @@ function Saved(props) {
});
});

panelMessaging.addMessageListener("PKT_renderSavedStory", function(resp) {
panelMessaging.addMessageListener("PKT_articleInfoFetched", function(resp) {
setSavedStoryState(resp?.data?.item_preview);
});

panelMessaging.addMessageListener("PKT_getArticleInfoAttempted", function(
resp
) {
setArticleInfoAttempted(true);
});

panelMessaging.addMessageListener("PKT_renderItemRecs", function(resp) {
const { data } = resp;

Expand Down Expand Up @@ -144,19 +151,21 @@ function Saved(props) {
utmParams={utmParams}
/>
)}
<TagPicker tags={[]} itemUrl={itemUrl} />
{similarRecs?.length && locale?.startsWith("en") && (
<>
<hr />
<h3 className="header_medium">Similar Stories</h3>
<ArticleList
articles={similarRecs}
source="on_save_recs"
model={similarRecsModel}
utmParams={utmParams}
/>
</>
)}
{articleInfoAttempted && <TagPicker tags={[]} itemUrl={itemUrl} />}
{articleInfoAttempted &&
similarRecs?.length &&
locale?.startsWith("en") && (
<>
<hr />
<h3 className="header_medium">Similar Stories</h3>
<ArticleList
articles={similarRecs}
source="on_save_recs"
model={similarRecsModel}
utmParams={utmParams}
/>
</>
)}
</>
)}
{savedStatus === "loading" && (
Expand Down
10 changes: 7 additions & 3 deletions browser/components/pocket/content/panels/js/main.bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -904,6 +904,7 @@ function Saved(props) {
removedErrorMessage
}, setRemovedStatusState] = (0,react.useState)({});
const [savedStory, setSavedStoryState] = (0,react.useState)();
const [articleInfoAttempted, setArticleInfoAttempted] = (0,react.useState)();
const [{
similarRecs,
similarRecsModel
Expand Down Expand Up @@ -966,9 +967,12 @@ function Saved(props) {
savedErrorId: ""
});
});
messages.addMessageListener("PKT_renderSavedStory", function (resp) {
messages.addMessageListener("PKT_articleInfoFetched", function (resp) {
setSavedStoryState(resp?.data?.item_preview);
});
messages.addMessageListener("PKT_getArticleInfoAttempted", function (resp) {
setArticleInfoAttempted(true);
});
messages.addMessageListener("PKT_renderItemRecs", function (resp) {
const {
data
Expand Down Expand Up @@ -1024,10 +1028,10 @@ function Saved(props) {
articles: [savedStory],
openInPocketReader: true,
utmParams: utmParams
}), /*#__PURE__*/react.createElement(TagPicker_TagPicker, {
}), articleInfoAttempted && /*#__PURE__*/react.createElement(TagPicker_TagPicker, {
tags: [],
itemUrl: itemUrl
}), similarRecs?.length && locale?.startsWith("en") && /*#__PURE__*/react.createElement(react.Fragment, null, /*#__PURE__*/react.createElement("hr", null), /*#__PURE__*/react.createElement("h3", {
}), articleInfoAttempted && similarRecs?.length && locale?.startsWith("en") && /*#__PURE__*/react.createElement(react.Fragment, null, /*#__PURE__*/react.createElement("hr", null), /*#__PURE__*/react.createElement("h3", {
className: "header_medium"
}, "Similar Stories"), /*#__PURE__*/react.createElement(ArticleList_ArticleList, {
articles: similarRecs,
Expand Down
6 changes: 6 additions & 0 deletions browser/components/pocket/content/pktApi.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,11 @@ var pktApi = (function() {
request.open("POST", url, true);
request.onreadystatechange = function(e) {
if (request.readyState == 4) {
// "done" is a completed XHR regardless of success/error:
if (options.done) {
options.done();
}

if (request.status === 200) {
// There could still be an error if the response is no valid json
// or does not have status = 1
Expand Down Expand Up @@ -483,6 +488,7 @@ var pktApi = (function() {
}
},
error: options.error,
done: options.done,
});
}

Expand Down
25 changes: 18 additions & 7 deletions browser/components/pocket/content/pktUI.js
Original file line number Diff line number Diff line change
Expand Up @@ -382,16 +382,27 @@ var pktUI = (function() {
SaveToPocket.itemSaved();

if (
item?.resolved_id &&
item?.resolved_id !== "0" &&
NimbusFeatures.saveToPocket.getVariable("layoutRefresh") &&
!NimbusFeatures.saveToPocket.getVariable("hideRecentSaves")
) {
pktApi.getArticleInfo(item.resolved_url, {
success(data) {
pktUIMessaging.sendMessageToPanel("PKT_renderSavedStory", data);
},
});
// Articles saved for the first time (by anyone) won't have a resolved_id
if (item?.resolved_id && item?.resolved_id !== "0") {
pktApi.getArticleInfo(item.resolved_url, {
success(data) {
pktUIMessaging.sendMessageToPanel(
"PKT_articleInfoFetched",
data
);
},
done() {
pktUIMessaging.sendMessageToPanel(
"PKT_getArticleInfoAttempted"
);
},
});
} else {
pktUIMessaging.sendMessageToPanel("PKT_getArticleInfoAttempted");
}
}

getAndShowRecsForItem(item, {
Expand Down

0 comments on commit 8f02299

Please sign in to comment.