Skip to content

Commit

Permalink
feat(topic source editor): generate button is displayed iff there exi…
Browse files Browse the repository at this point in the history
…sts a source-link with context and without prompt
  • Loading branch information
yonadavGit committed Feb 1, 2024
1 parent 2d45786 commit cc1591d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
1 change: 1 addition & 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);
buttonsToDisplay = buttonsToDisplay.filter(item => item !== null && item !== undefined)

const showGenerationConfirmation = () => {
if (!isGenerateConfirmationShown) {
Expand Down
16 changes: 14 additions & 2 deletions static/js/TopicPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -312,17 +312,29 @@ const TopicSponsorship = ({topic_slug}) => {
);
}

const existsSourceRefWithContextWithoutPrompt = (refs) => {
if (!refs) {
return false;
}

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

return refs.some((ref) => {
return ref.descriptions && ref.descriptions[lang]?.context && ref.descriptions[lang]?.context != '' &&
!ref.descriptions[lang]?.prompt;
});
};
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 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={["generate", "source", "edit", "reorder"]}>
<CategoryHeader type="topics" data={topicData} buttonsToDisplay={[generateButtonName, "source", "edit", "reorder"]}>
<h1>
<InterfaceText text={{en:en, he:he}}/>
</h1>
Expand Down

0 comments on commit cc1591d

Please sign in to comment.