Skip to content

Commit

Permalink
feat(topicPromtGenerator): client sends api request to new endpoint u…
Browse files Browse the repository at this point in the history
…pon clicking the "Publish" button
  • Loading branch information
yonadavGit committed Feb 12, 2024
1 parent 25cc159 commit 7930543
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 5 deletions.
2 changes: 1 addition & 1 deletion reader/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3208,7 +3208,7 @@ def topic_ref_bulk_api(request):
for data_item in data:
tref = data_item.get('ref', data_item.get("tref"))
tref = Ref(tref).normal()
slug = data_item.get("toTopic", data_item.get("topic"))
slug = data_item.get("toTopic", data_item.get("slug"))
linkType = _CAT_REF_LINK_TYPE_FILTER_MAP['authors'][0] if AuthorTopic.init(slug) else 'about'
descriptions = data_item.get("descriptions", data_item.get("description"))
languages = descriptions.keys()
Expand Down
3 changes: 2 additions & 1 deletion static/js/Misc.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -1140,7 +1140,7 @@ const ConfirmationPopup = () => {
};


const CategoryHeader = ({children, type, data = [], buttonsToDisplay = ["subcategory", "edit"]}) => {
const CategoryHeader = ({children, type, data = [], buttonsToDisplay = ["subcategory", "edit"], publishButtonCallback}) => {
/*
Provides an interface for using admin tools.
`type` is 'sources', 'cats', 'books' or 'topics'
Expand Down Expand Up @@ -1180,6 +1180,7 @@ const CategoryHeader = ({children, type, data = [], buttonsToDisplay = ["subcat

if (isConfirmed) {
alert("You clicked OK!");
publishButtonCallback()
} else {
alert("You clicked Cancel or closed the popup.");
}
Expand Down
19 changes: 16 additions & 3 deletions static/js/TopicPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -339,15 +339,28 @@ const TopicHeader = ({ topic, topicData, topicTitle, multiPanel, isCat, setNavTo
const { en, he } = !!topicData && topicData.primaryTitle ? topicData.primaryTitle : {en: "Loading...", he: "טוען..."};
const isTransliteration = !!topicData ? topicData.primaryTitleIsTransliteration : {en: false, he: false};
const category = !!topicData ? Sefaria.topicTocCategory(topicData.slug) : null;
const generateButtonName = existsSourceRefWithContextWithoutPrompt(topicData.refs?.about?.refs) ? "generate" : null
const publishButtonName = existsSourceRefExplicitlyNotPublished(topicData.refs?.about?.refs) ? "publish" : null
const generateButtonName = existsSourceRefWithContextWithoutPrompt(topicData.refs?.about?.refs) ? "generate" : null;
const publishButtonName = existsSourceRefExplicitlyNotPublished(topicData.refs?.about?.refs) ? "publish" : null;
const tpTopImg = !multiPanel && topicImage ? <TopicImage photoLink={topicImage.image_uri} caption={topicImage.image_caption}/> : null;

const requestPublishUnpublishedPrompts = () => {
let refs = topicData.refs?.about?.refs
const lang = Sefaria.interfaceLang === "english" ? 'en' : 'he';
refs = refs.filter((ref) => {
return (ref.descriptions && ref.descriptions[lang]?.hasOwnProperty('published') && !ref.descriptions[lang]?.published)
});
refs.forEach(ref => {
ref['slug'] = topic;
ref.descriptions[lang]["published"] = true;
});
Sefaria.updateBulkTopicRef(refs)
};

return (
<div>

<div className="navTitle tight">
<CategoryHeader type="topics" data={topicData} buttonsToDisplay={[publishButtonName, generateButtonName, "source", "edit", "reorder"]}>
<CategoryHeader publishButtonCallback={requestPublishUnpublishedPrompts} type="topics" data={topicData} buttonsToDisplay={[publishButtonName, generateButtonName, "source", "edit", "reorder"]}>
<h1>
<InterfaceText text={{en:en, he:he}}/>
</h1>
Expand Down
18 changes: 18 additions & 0 deletions static/js/sefaria/sefaria.js
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,24 @@ Sefaria = extend(Sefaria, {
const json = await response.json();
if (json.error) { throw json; }
return json;
},
updateBulkTopicRef: async function(listOfTopicRefLinks) {
const data = JSON.stringify(listOfTopicRefLinks)
const response = await fetch(this.apiHost + `/api/ref-topic-links/bulk`,
{
method: "POST",
mode: 'same-origin',
headers: {
'X-CSRFToken': Cookies.get('csrftoken'),
},
credentials: 'same-origin',
body: data
}
);
if (!response.ok) { throw "error"; }
const json = await response.json();
if (json.error) { throw json; }
return json;
},
subscribeSefariaAndSteinsaltzNewsletter: async function(firstName, lastName, email, educatorCheck) {
const responses = await Promise.all([
Expand Down

0 comments on commit 7930543

Please sign in to comment.