Skip to content

Commit

Permalink
Update option no when save question from genai
Browse files Browse the repository at this point in the history
  • Loading branch information
linxiaoxin committed Sep 18, 2024
1 parent 43b346f commit dc717b4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 18 deletions.
27 changes: 12 additions & 15 deletions app/(main)/questions/create/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import { Dialog } from 'primereact/dialog';
import { TreeSelect, TreeSelectSelectionKeysType } from 'primereact/treeselect';
import { TreeNode } from 'primereact/treenode';
import { useRouter } from 'next/navigation';
import { Toast } from 'primereact/toast';
import { ProgressSpinner } from 'primereact/progressspinner';
import AppMessages, {AppMessage} from '../../../../components/AppMessages'

const EditQuestion = () => {
const router = useRouter();
Expand All @@ -31,16 +31,7 @@ const EditQuestion = () => {
const [activeTab, setActiveTab] = useState<number>(0);
const [showSpinner, setShowSpinner] = useState<boolean>(false);

const toast = useRef<Toast>(null);

const showWarning = (summary: string, message: string) => {
toast.current?.show({
severity: 'warn',
summary: summary,
detail: message,
life: 3000 //3 secs
});
};
const appMsg = useRef<AppMessage>(null);

useEffect(() => {
QuestionsService.getTopics().then((data) => {
Expand Down Expand Up @@ -207,6 +198,13 @@ const EditQuestion = () => {
//TODO: call generate question API
console.log('Invoking handleOnGenerateQuestion');
var updateQuestion = (data: Genai.MCQ) => {
var index =1
if(data.options && data.options.map ){
data.options.map((item: Genai.Option) => {
item.no = index;
index++;
})
}
setStem(data.stem);
setAddedOptions(data.options);
setShowSpinner(false);
Expand All @@ -219,13 +217,12 @@ const EditQuestion = () => {

//console.debug("selectedTopicNodes", selectedTopicNodes);
if (!selectedTopicNodes) {
console.log('selectedTopicNodes undefined');
showWarning('Invalid Input', 'Generate Question works only for 1 topic with 1 or more skills selected');
appMsg.current?.showWarning('Generate Question works only for 1 topic with 1 or more skills selected');
return;
}
const { selectedTopics, selectedSkills } = retrieveSelectedTopicSkillsIds();
if (selectedTopics.length != 1) {
showWarning('Invalid Input', 'Generate Question works only for 1 topic with 1 or more skills selected');
appMsg.current?.showWarning('Generate Question works only for 1 topic with 1 or more skills selected');
return;
}
//search in listOfTopics
Expand All @@ -250,7 +247,7 @@ const EditQuestion = () => {
};
return (
<>
<Toast ref={toast} position="top-center" />
<AppMessages ref={appMsg} />
{!showSpinner || <ProgressSpinner style={{ width: '50px', height: '50px', position: 'fixed', left: '50%', top: '50%', opacity: '1', zIndex: '1000', background: 'transparent' }} strokeWidth="8" fill="var(--surface-ground)" />}
<h5>Add Question</h5>
<br />
Expand Down
4 changes: 2 additions & 2 deletions components/AppMessages.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ const AppMessages = forwardRef<AppMessage, Props>((props, ref) =>{
showError(messageContent: string){
msgs.current?.show([{ severity: 'error', summary: '', icon: 'pi pi-error', detail: messageContent, closable: true, sticky: true }]);
},
showWarning(messageContent: string){
msgs.current?.show([{ severity: 'warn', summary: '', icon: 'pi pi-warning', detail: messageContent, closable: true, sticky: true }]);
showWarning(messageContent: string, life: number = 10000){
msgs.current?.show([{ severity: 'warn', summary: '', icon: 'pi pi-warning', detail: messageContent, closable: true, sticky: true, life: life }]);
},
showCustomWarning(messageContent: ReactNode){
msgs.current?.show([{ severity: 'warn', summary: '', icon: 'pi pi-warning', content: messageContent, closable: true, sticky: true }]);
Expand Down
2 changes: 1 addition & 1 deletion service/UserService.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import api from "./ConnectionService"
export const UserService = {
async addClass(data: Class) {
const res = await api<UserServiceResponseDto>({ url: classUrl, body: JSON.stringify(data), method: "POST" });
console.log('res', res);
//console.log('res', res);
// const res = await fetch(classUrl, {
// method: 'POST',
// headers: {
Expand Down

0 comments on commit dc717b4

Please sign in to comment.