Skip to content

Commit

Permalink
feat(topic source editor): add button 'published', displayed only whe…
Browse files Browse the repository at this point in the history
…n there exists a prompt explicitly unpublished
  • Loading branch information
yonadavGit committed Feb 1, 2024
1 parent 6e77612 commit c38298e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
17 changes: 17 additions & 0 deletions static/js/Misc.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -1157,6 +1157,7 @@ const CategoryHeader = ({children, type, data = [], buttonsToDisplay = ["subcat
const [addSection, toggleAddSection] = useEditToggle();
const [hiddenButtons, setHiddenButtons] = useHiddenButtons(true);
const [isGenerateConfirmationShown, setGenerateConfirmationShown] = useState(false);
const [isPublishConfirmationShown, setPublishConfirmationShown] = useState(false);
buttonsToDisplay = buttonsToDisplay.filter(item => item !== null && item !== undefined)

const showGenerationConfirmation = () => {
Expand All @@ -1173,11 +1174,27 @@ const CategoryHeader = ({children, type, data = [], buttonsToDisplay = ["subcat
setGenerateConfirmationShown(true);
}
};
const showPublishConfirmation = () => {
if (!isPublishConfirmationShown) {
const isConfirmed = window.confirm("Are you sure you want to publish prompts?");

if (isConfirmed) {
alert("You clicked OK!");
} else {
alert("You clicked Cancel or closed the popup.");
}

// Update state to prevent showing the popup again
setPublishConfirmationShown(true);
}
};

const buttonOptions = {"subcategory": ["Add sub-category", toggleAddCategory],
"source": ["Add a source", toggleAddSource],
"section": ["Add section", toggleAddSection],
"reorder": ["Reorder sources", toggleReorderCategory],
"generate": ["Generate", showGenerationConfirmation],
"publish": ["Publish", showPublishConfirmation],
"edit": ["Edit", toggleEditCategory]};

let wrapper = "";
Expand Down
2 changes: 0 additions & 2 deletions static/js/Story.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,10 @@ const PromptWrapper = ({text}) => {
return promptComponent
}
const ReviewStateWrapper = ({topic, text}) => {
console.log(text)
let reviewIndicatorComponent = null;
const [reviewStateEn, setReviewStateEn] = useState(text.descriptions?.en?.review_state);
const [reviewStateHe, setReviewStateHe] = useState(text.descriptions?.he?.review_state);
const markReviewed = function(){
console.log("markReviewed")
let lang = Sefaria.interfaceLang == "english" ? 'en' : 'he';
let setFun = Sefaria.interfaceLang == "english" ? setReviewStateEn : setReviewStateHe;
let postData = {"topic": topic, "is_new": false, 'new_ref': text.ref, 'interface_lang': Sefaria.interfaceLang};
Expand Down
15 changes: 14 additions & 1 deletion static/js/TopicPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -324,17 +324,30 @@ const existsSourceRefWithContextWithoutPrompt = (refs) => {
!ref.descriptions[lang]?.prompt;
});
};
const existsSourceRefExplicitlyNotPublished = (refs) => {
if (!refs) {
return false;
}

const lang = Sefaria.interfaceLang === "english" ? 'en' : 'he';

return refs.some((ref) => {
return (ref.descriptions && ref.descriptions[lang]?.hasOwnProperty('published') && !ref.descriptions[lang]?.published)
});
};
const TopicHeader = ({ topic, topicData, topicTitle, multiPanel, isCat, setNavTopic, openDisplaySettings, openSearch, topicImage }) => {
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 tpTopImg = !multiPanel && topicImage ? <TopicImage photoLink={topicImage.image_uri} caption={topicImage.image_caption}/> : null;

return (
<div>

<div className="navTitle tight">
<CategoryHeader type="topics" data={topicData} buttonsToDisplay={[generateButtonName, "source", "edit", "reorder"]}>
<CategoryHeader type="topics" data={topicData} buttonsToDisplay={[publishButtonName, generateButtonName, "source", "edit", "reorder"]}>
<h1>
<InterfaceText text={{en:en, he:he}}/>
</h1>
Expand Down

0 comments on commit c38298e

Please sign in to comment.