Skip to content

Commit

Permalink
Add undo add skill
Browse files Browse the repository at this point in the history
  • Loading branch information
linxiaoxin committed Jul 28, 2024
1 parent f0f75d0 commit 2e03085
Showing 1 changed file with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions app/(main)/questions/topics/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const ManageTopics = () => {
const [topicNodes, setTopicNodes] = useState<any[]>([]);
const [topics, setTopics] = useState<Questions.Topic[]>([]);
const [edited, setEdited] = useState(false);
const [expandedKeys, setExpandedKeys] = useState();
const [expandedKeys, setExpandedKeys] = useState<Record<string, boolean>>();

const reload = () => {
QuestionsService.getTopics().then((t) => {
Expand All @@ -31,7 +31,7 @@ const ManageTopics = () => {
if(item.skills){
childnode = item.skills.map( skill => {
return { "key": item.id+"-"+skill.id,
"data": { "id": skill.id,"name": skill.name , "active": skill.active, "type": "skill", "edited": skill.edited}
"data": { "id": skill.id,"name": skill.name , "active": skill.active, "type": "skill", "edited": skill.edited, "topicId": item.id}
};
});
}
Expand All @@ -50,9 +50,15 @@ const ManageTopics = () => {
);
};
const activeTemplate = (node: any) => {
return(
return(<>
{!node.data.id ||
<ToggleButton onLabel="Active" offLabel="Inactive"
checked={node.data.active} onChange={(e) => onActiveStatusChange(node, e.target.value)}/>
}
{node.data.id != undefined ||
<Button label='Undo' icon="pi pi-undo" onClick={(e)=> undoAddSkill(node)}/>
}
</>
);
}
//edit active status
Expand Down Expand Up @@ -111,7 +117,6 @@ const ManageTopics = () => {
//add skill
const addSkill = (node: any)=> {
var found = false;
console.log("Add skills for ", node.key)
let updatedTopics = topics.map( (t)=> {
if(t.id === node.key){
found = true;
Expand Down Expand Up @@ -140,6 +145,24 @@ const ManageTopics = () => {

}
}
//undo add skill
const undoAddSkill = (node: any)=> {
var found = false;
console.log("for topic:", node.data.topicId)
let updatedTopics = topics.map( (t)=> {
if(t.id === node.data.topicId){
found = true;
//add skill
if(t.skills && t.skills[0].id == undefined){
t.skills.shift();
}
}
return t;
});
if(found){
setTopics(updatedTopics);
}
}
//footer
const footer = (
<div className='grid'>
Expand Down

0 comments on commit 2e03085

Please sign in to comment.