Skip to content

Commit

Permalink
feat(topic source editor): add new fields to editor
Browse files Browse the repository at this point in the history
  • Loading branch information
yonadavGit committed Jan 29, 2024
1 parent 4650abc commit e3a9772
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
11 changes: 11 additions & 0 deletions static/js/AdminEditor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ const options_for_form = {
markdown: true
},
"Prompt": {label: "Prompt", field: "prompt", placeholder: "Add a prompt.", type: 'textarea'},
"AI Prompt": {label: "AI Prompt", field: "aiPrompt", placeholder: "AI Generated Prompt", type: 'textarea readonly'},
"Context for Prompt": {label: "Context for Prompt", field: "context", placeholder: "Why was this source added", type: 'textarea'},
"AI Title": {label: "AI Title", field: "aiTitle", placeholder: "AI Generated Title", type: 'readonly'},
"English Short Description": {
label: "English Short Description for Table of Contents", field: "enCategoryDescription",
placeholder: "Add a short description.", type: 'input'
Expand Down Expand Up @@ -177,6 +180,14 @@ const AdminEditor = ({title, data, close, catMenu, pictureUploader, updateData,
obj = <textarea className="default" id={field} onChange={setInputValue} defaultValue={data[field]}
placeholder={Sefaria._(placeholder)}/>;
break;
case 'textarea readonly':
obj = <textarea readOnly className="default" id={field} onChange={setInputValue} defaultValue={data[field]}
placeholder={Sefaria._(placeholder)}/>;
break;
case 'readonly':
const inputTypeReadOnly = field.includes('Year') ? 'number' : 'text';
obj = <input readOnly type={inputTypeReadOnly} id={field} onChange={setInputValue} defaultValue={data[field]}
placeholder={Sefaria._(placeholder)}/>;
default:
const inputType = field.includes('Year') ? 'number' : 'text';
obj = <input type={inputType} id={field} onChange={setInputValue} defaultValue={data[field]}
Expand Down
16 changes: 10 additions & 6 deletions static/js/SourceEditor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@ const SourceEditor = ({topic, close, origData={}}) => {
(origData.heRef || "") : (origData.ref || "") );
const title = Sefaria.interfaceLang === 'english' ? (origData?.descriptions?.en?.title || '') : (origData?.descriptions?.he?.title || '');
const prompt = Sefaria.interfaceLang === 'english' ? (origData?.descriptions?.en?.prompt || '') : (origData?.descriptions?.he?.prompt || '');
const aiPrompt = Sefaria.interfaceLang === 'english' ? (origData?.descriptions?.en?.ai_prompt || '') : (origData?.descriptions?.he?.ai_prompt || '');
const aiTitle = Sefaria.interfaceLang === 'english' ? (origData?.descriptions?.en?.ai_title || '') : (origData?.descriptions?.he?.ai_title || '');
const context = Sefaria.interfaceLang === 'english' ? (origData?.descriptions?.en?.context || '') : (origData?.descriptions?.he?.context || '');

const [data, setData] = useState({enTitle: title, // use enTitle for hebrew or english case
prompt: prompt,
prompt: prompt, aiPrompt: aiPrompt, aiTitle: aiTitle, context: context
});
const [changed, setChanged] = useState(false);
const [savingStatus, setSavingStatus] = useState(false);
Expand Down Expand Up @@ -46,9 +50,9 @@ const SourceEditor = ({topic, close, origData={}}) => {
let refInUrl = isNew ? displayRef : origData.ref;
let url = `/api/ref-topic-links/${Sefaria.normRef(refInUrl)}`;
let postData = {"topic": topic, "is_new": isNew, 'new_ref': displayRef, 'interface_lang': Sefaria.interfaceLang};
if (data.enTitle.length > 0) {
postData['description'] = {"title": data.enTitle, "prompt": data.prompt};
}
// if (data.enTitle.length > 0) {
postData['description'] = {"title": data.enTitle, "prompt": data.prompt, "context": data.context};
// }
requestWithCallBack({url, data: postData, setSavingStatus, redirect: () => window.location.href = "/topics/"+topic});
}

Expand Down Expand Up @@ -89,10 +93,10 @@ const SourceEditor = ({topic, close, origData={}}) => {
const url = `/api/ref-topic-links/${origData.ref}?topic=${topic}&interface_lang=${Sefaria.interfaceLang}`;
requestWithCallBack({url, type: "DELETE", redirect: () => window.location.href = `/topics/${topic}`});
}

console.log(data)
return <div>
<AdminEditor title="Source Editor" close={close} data={data} savingStatus={savingStatus}
validate={validate} items={["Title", "Prompt"]} deleteObj={deleteTopicSource} updateData={updateData} isNew={isNew}
validate={validate} items={["AI Title", "Title","Context for Prompt", "AI Prompt", "Prompt"]} deleteObj={deleteTopicSource} updateData={updateData} isNew={isNew}
extras={
[<div>
<label><InterfaceText>Enter Source Ref (for example: 'Yevamot.62b.9-11' or 'Yevamot 62b:9-11')</InterfaceText></label>
Expand Down

0 comments on commit e3a9772

Please sign in to comment.