-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add questionList component, update message UI
- Loading branch information
Showing
3 changed files
with
63 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import React, { useState, useEffect } from 'react'; | ||
import { Card, Button } from 'react-bootstrap'; | ||
|
||
// 假设的API方法,用于从数据库删除特定ID的题目 | ||
const deleteQuestionFromDB = async (id) => { | ||
// 在这里你可以调用API来从数据库删除题目 | ||
console.log(`Deleted question with ID: ${id}`); | ||
}; | ||
|
||
function QuestionList({ questions, setQuestions }) { // 通过结构赋值来接受questions prop | ||
|
||
const handleDelete = async (id) => { | ||
// 删除数据库中的数据 | ||
await deleteQuestionFromDB(id); | ||
|
||
//更新状态,移除已删除的问题 | ||
const updatedQuestions = questions.filter(q => q.question_id !== id); | ||
setQuestions(updatedQuestions); | ||
}; | ||
|
||
|
||
return ( | ||
<div> | ||
{questions.map((question) => ( | ||
<Card key={question.question_id} style={{ marginBottom: '20px' }}> | ||
<Card.Body> | ||
<Card.Title>{question.question_title}</Card.Title> | ||
<Card.Text>{question.question_detail}</Card.Text> | ||
<Button variant="danger" onClick={() => handleDelete(question.question_id)}>delete</Button> | ||
</Card.Body> | ||
</Card> | ||
))} | ||
</div> | ||
); | ||
} | ||
|
||
|
||
export default QuestionList; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters