Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 33 additions & 17 deletions src/components/Card/FlowCard.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import { DeleteIcon } from '@chakra-ui/icons';
import { CheckIcon, CloseIcon, DeleteIcon } from '@chakra-ui/icons';
import {
Avatar,
Badge,
Box,
Button,
Card,
CardBody,
CardFooter,
Flex,
Heading,
HStack,
IconButton,
Image,
LinkBox,
LinkOverlay,
Expand Down Expand Up @@ -46,22 +49,24 @@ const FlowCard = ({ flow, px, py, canDelete, setSelected }: FlowCardProps) => {
<Stack w="full">
<CardBody>
{canDelete && (
<Button
zIndex={11}
position="absolute"
top={4}
right={5}
variant="unstyled"
>
<Tooltip label="Delete" placement="right">
<DeleteIcon
onClick={() => setSelected?.(flow._id!)}
w={5}
h={5}
color="red"
/>
</Tooltip>
</Button>
<>
<Button
zIndex={11}
position="absolute"
top={4}
right={5}
variant="unstyled"
>
<Tooltip label="Delete" placement="right">
<DeleteIcon
onClick={() => setSelected?.(flow._id!)}
w={5}
h={5}
color="red"
/>
</Tooltip>
</Button>
</>
)}
<Heading size="md">{flow.title}</Heading>
{flow.tags &&
Expand Down Expand Up @@ -89,6 +94,17 @@ const FlowCard = ({ flow, px, py, canDelete, setSelected }: FlowCardProps) => {
</HStack>
</>
)}
<Flex right={'35px'} bottom={5} position={'absolute'}>
{flow.publish ? 'Published' : 'Not published'}:
<IconButton
size={'xs'}
backgroundColor={flow.publish ? 'green.500' : 'red.500'}
aria-label={''}
left={'5px'}
>
{flow.publish ? <CheckIcon /> : <CloseIcon />}
</IconButton>
</Flex>
</CardFooter>
</Stack>
</Card>
Expand Down
81 changes: 70 additions & 11 deletions src/components/Modals/CreateAILPModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ const CreateAILPModal = ({ isOpen, onClose, action }: ModaTemplateProps) => {
</FormLabel>
<Textarea
maxHeight={'200px'}
placeholder="Insert your material here, you can put your plain text or the link (attention some websites are crypted, sometimes the tool cannot access the actual text)..."
placeholder="Here, you can define the context of the learning path's application."
value={context}
overflowY={'auto'}
onChange={(e) => {
Expand Down Expand Up @@ -765,10 +765,9 @@ const CreateAILPModal = ({ isOpen, onClose, action }: ModaTemplateProps) => {
: 1;
const generatedNodes: PolyglotNode[] = [];
let counter = 0;
let check = 0;
do {
check++;
for (let i = 0; i < selectedNodes.length; i++) {
if (counter == 0 && nReadMaterial != 0) {
i--;
counter = nTopicReadMaterial;
setNReadMaterial(nReadMaterial - 1);
const readTopics: LessonNodeAI[] = selectedNodes
Expand Down Expand Up @@ -842,7 +841,7 @@ const CreateAILPModal = ({ isOpen, onClose, action }: ModaTemplateProps) => {
}
} else {
counter--;
const activity = selectedNodes.shift();
const activity = selectedNodes[i];
if (!activity) break;
try {
await API.generateNewExercise({
Expand Down Expand Up @@ -903,11 +902,8 @@ const CreateAILPModal = ({ isOpen, onClose, action }: ModaTemplateProps) => {
console.log(error);
}
}
} while (
selectedNodes.length + nReadMaterial !=
generatedNodes.length ||
check < selectedNodes.length + nReadMaterial
);
}

const generatedEdges: PolyglotEdge[] = [];

//edges generation
Expand Down Expand Up @@ -944,6 +940,45 @@ const CreateAILPModal = ({ isOpen, onClose, action }: ModaTemplateProps) => {
title: 'next',
});
} else {
const idRecovery = UUIDv4();
const x = node.reactFlow.position.x;
const y = node.reactFlow.position.y + 50;
generatedNodes.push({
_id: idRecovery,
type: 'abstractNode',
title: 'Recovery Activity',
description: 'Recovery activity',
platform: 'Library',
difficulty: 1,
data: {
useFlowData: true,
sourceMaterial: sourceMaterial,
learning_outcome: learningOutcome,
education_level: eduLevel,
topicsAI: selectedTopic,
language: analysedMaterial.language,
macro_subject: analysedMaterial.macro_subject,
title: analysedMaterial.title,
context: context,
},
reactFlow: {
id: idRecovery,
type: 'abstractNode',
position: {
x: x,
y: y,
},
width: 88,
height: 46,
selected: false,
dragging: false,
positionAbsolute: {
x: x,
y: y,
},
data: {},
},
});
const id1 = UUIDv4();
generatedEdges.push({
_id: id1,
Expand Down Expand Up @@ -980,7 +1015,7 @@ const CreateAILPModal = ({ isOpen, onClose, action }: ModaTemplateProps) => {
reactFlow: {
id: id2,
source: node._id,
target: node._id,
target: idRecovery,
type: 'passFailEdge',
markerEnd: {
color: 'red',
Expand All @@ -992,6 +1027,30 @@ const CreateAILPModal = ({ isOpen, onClose, action }: ModaTemplateProps) => {
},
title: 'fail',
});
const id3 = UUIDv4();
generatedEdges.push({
_id: id3,
type: 'passFailEdge',
code: `\nasync Task<(bool, string)> validate(PolyglotValidationContext context) {\n var getMultipleChoiceAnswer = () => {\n var submitted = context.JourneyContext.EventsProduced.OfType<ReturnValueProduced>().FirstOrDefault()?.Value as HashSet<string>;\n var answersCorrect = ((List<object>)context.Exercise.Data.isChoiceCorrect).Select((c, i) => (c, i))\n .Where(c => bool.Parse(c.c.ToString()))\n .Select(c => (c.i + 1).ToString())\n .ToHashSet();\n return submitted.SetEquals(answersCorrect);\n };\n\n var isSubmissionCorrect = context.Exercise.NodeType switch\n {\n \"multipleChoiceQuestionNode\" => getMultipleChoiceAnswer(),\n _ => context.Exercise.Data.correctAnswers.Contains(context.JourneyContext.SubmittedCode),\n };\n\n var conditionKind = context.Condition.Data.conditionKind switch\n {\n \"pass\" => true,\n \"fail\" => false,\n _ => throw new Exception(\"Unknown condition kind\")\n };\n return (conditionKind == isSubmissionCorrect, \"Pass/Fail edge\");\n} \n
`,
data: {
conditionKind: 'pass',
},
reactFlow: {
id: id3,
source: idRecovery,
target: nextNode._id,
type: 'passFailEdge',
markerEnd: {
color: 'green',
type: MarkerType.Arrow,
width: 25,
height: 25,
},
selected: true,
},
title: 'pass',
});
}
}

Expand Down
20 changes: 17 additions & 3 deletions src/components/Modals/EditFlowModal.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AddIcon, CloseIcon } from '@chakra-ui/icons';
import { AddIcon, CheckIcon, CloseIcon } from '@chakra-ui/icons';
import {
Box,
Button,
Expand Down Expand Up @@ -54,7 +54,7 @@ const EditFlowModal = ({
const [topicName, setTopicName] = useState('');
const [topics, setTopics] = useState([...flow.topics]);
const [tagName, setTagName] = useState('');
const [publish] = useState(false);
const [publish, setPublish] = useState(false);
const [colorTag, setColorTag] = useState(colors[0]);
const [tags, setTags] = useState([...flow.tags]);
const { isOpen: ioPop, onClose: ocPop, onOpen: opPop } = useDisclosure();
Expand All @@ -67,6 +67,7 @@ const EditFlowModal = ({
setTopics([...flow.topics]);
setColorTag(colors[0]);
setTags([...flow.tags]);
setPublish(flow.publish);
}, [flow]);

return (
Expand Down Expand Up @@ -270,6 +271,19 @@ const EditFlowModal = ({
</Button>
))}
</ModalBody>
<Box position={'absolute'} bottom={'15px'} left={'27px'}>
{publish ? 'Published' : 'Not published'}:{' '}
<IconButton
backgroundColor={publish ? 'green.500' : 'red.500'}
onClick={() => {
console.log(publish);
setPublish(!publish);
}}
aria-label={''}
>
{publish ? <CheckIcon /> : <CloseIcon />}
</IconButton>
</Box>

<ModalFooter>
<Button
Expand All @@ -287,7 +301,7 @@ const EditFlowModal = ({
learningContext: learningContext,
duration: duration,
topics: topics,
topicsAI: [],
topicsAI: flow.topicsAI,
});
onClose();
}}
Expand Down
1 change: 1 addition & 0 deletions src/data/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export type aiAPIResponse = {

const axios = axiosCreate.create({
baseURL: process.env.BACK_URL,
timeout: 60000,
headers: {
'Content-Type': 'application/json',
},
Expand Down
1 change: 0 additions & 1 deletion src/pages/flows/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
import { GetServerSideProps } from 'next';
import { useCallback, useEffect, useMemo, useState } from 'react';
import FlowCard from '../../components/Card/FlowCard';
import CreateAILPModal from '../../components/Modals/CreateAILPModal';
import CreateFlowModal from '../../components/Modals/CreateFlowModal';
import DeleteFlowModal from '../../components/Modals/DeleteFlowModal';
import Navbar from '../../components/NavBars/NavBar';
Expand Down
Loading