들어온 피드백을 표시
| Parameter | Type | Require | |
|---|---|---|---|
| id | number | O | |
| writeSecond | number | O | |
| content | string | O |
import React, { useState } from 'react';
export interface FeedbackBoxPropType {
feedback: feedbackType;
onPinFeedback: any;
onDelete: any;
}
export interface feedbackType {
id: number;
writeSecond: number;
content: string;
}
const FeedbackBox = ({
feedback: { id, writeSecond, content },
onPinFeedback,
onDelete,
}: FeedbackBoxPropType) => {
const [isPin, setIsPin] = useState(false);
const [readOnly, setReadOnly] = useState(true);
const minute = Math.floor(writeSecond / 60);
const second = writeSecond % 60;
const setPin = () => {
setIsPin((current) => !current);
onPinFeedback(id);
};
return (
<div>
<span>{isPin ? '(고정)' : ''}</span>
<span>
{minute}:{second}
</span>
<textarea readOnly={readOnly}>{content}</textarea>
<button type="button" onClick={setPin}>
{isPin ? '해제' : '고정'}
</button>
<button type="button" onClick={() => setReadOnly((current) => !current)}>
{readOnly ? '편집' : '완료'}
</button>
<button type="button" onClick={() => onDelete(id)}>
삭제
</button>
</div>
);
};
export default FeedbackBox;