StudentView.tsx 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import React, { useState } from 'react';
  2. import { useClassroomContext } from './ClassroomProvider.tsx';
  3. import { ClassStatus } from './useClassroom.ts';
  4. export const StudentView = () => {
  5. const {
  6. handUp,
  7. sendQuestion,
  8. classStatus,
  9. isJoinedClass
  10. } = useClassroomContext();
  11. const [questionText, setQuestionText] = useState('');
  12. const handleSendQuestion = () => {
  13. if (questionText.trim()) {
  14. sendQuestion(questionText);
  15. setQuestionText('');
  16. }
  17. };
  18. return (
  19. <div className="space-y-4">
  20. {isJoinedClass && (
  21. <div className="mt-4 p-4 bg-white rounded-md shadow">
  22. <h4 className="text-lg font-medium mb-2">互动功能</h4>
  23. <div className="space-y-3">
  24. <button
  25. type="button"
  26. className="w-full px-3 py-2 bg-green-600 text-white rounded-md hover:bg-green-700 disabled:bg-gray-400"
  27. onClick={() => handUp()}
  28. disabled={classStatus !== ClassStatus.IN_PROGRESS}
  29. >
  30. {classStatus === ClassStatus.IN_PROGRESS ? '举手' : '课堂未开始'}
  31. </button>
  32. <div className="flex space-x-2">
  33. <input
  34. type="text"
  35. placeholder="输入问题..."
  36. className="flex-1 px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"
  37. value={questionText}
  38. onChange={(e) => setQuestionText(e.target.value)}
  39. onKeyPress={(e) => e.key === 'Enter' && handleSendQuestion()}
  40. />
  41. <button
  42. type="button"
  43. className="px-3 py-2 bg-blue-600 text-white rounded-md hover:bg-blue-700 disabled:bg-gray-400"
  44. onClick={handleSendQuestion}
  45. disabled={!questionText.trim() || classStatus !== ClassStatus.IN_PROGRESS}
  46. >
  47. 提问
  48. </button>
  49. </div>
  50. </div>
  51. </div>
  52. )}
  53. </div>
  54. );
  55. };