Skip to content

Commit

Permalink
hotfix: ChatForm 입력 관련 이슈 해결
Browse files Browse the repository at this point in the history
  • Loading branch information
krokerdile committed Nov 12, 2023
1 parent b574c74 commit 571ae9f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 33 deletions.
30 changes: 15 additions & 15 deletions src/components/ChatForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,33 +43,32 @@ const ChatForm = () => {
temperature: 0.5,
max_tokens: 1000,
});
console.log(result);
const lines = result.data.choices[0].text.split("\n");
console.log("lines: ", lines);

lines.forEach((item) => {
if (item.includes("표현해석")) {
if (item.includes("표현해석: ")) {
let temp = item.replace("표현해석: ", "");
setExpression([...expression, temp]);
setExpressionData(expression);
} else if (item.includes("유의사항")) {
let newExpression = [...expression, temp];
setExpression(newExpression);
setExpressionData(newExpression);
} else if (item.includes("유의사항: ")) {
// data.유의사항.push(item.replace("유의사항: ", ""));
let temp = item.replace("유의사항: ", "");
setCaution([...caution, temp]);
setCautionData(caution);
} else if (item.includes("법률용어")) {
// data.법률용어.push(item.replace("법률용어: ", ""));
let newCaution = [...caution, temp];
setCaution(newCaution);
setCautionData(newCaution);
} else if (item.includes("법률용어: ")) {
let temp = item.replace("법률용어: ", "");
temp = temp.split(",");
let newTerminology = [...terminology];
temp.map((x) => {
setTerminology([...terminology, x]);
let word = x.trim();
newTerminology.push(word);
});
setTerminologyData(terminology);
setTerminology(newTerminology);
setTerminologyData(newTerminology);
}
});
console.log(expression);
console.log(caution);
console.log(terminology);
} catch (e) {
console.error("Error:", e);
} finally {
Expand Down Expand Up @@ -184,6 +183,7 @@ const TypeForm = styled.input`
const ChatResult = styled.div`
width: calc(100% - 2rem);
height: calc(100% - 2rem);
max-height: 60%;
border: 1px solid #d7d7d7;
border-radius: 10px;
margin-bottom: 18px;
Expand Down
9 changes: 3 additions & 6 deletions src/components/GptAnalytics.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,8 @@ const GptAnalytics = () => {
// // 법률 단어 추출
// const legalTerms = gptData.map((data) => data.legalterm.trim());

const { expressionData: expression, cautionData: caution, terminologyData: terminology } = useStoreGptData();
const { expressionData: expression, cautionData: caution } = useStoreGptData();
// 결과 출력
console.log("표현해석:", expression);
console.log("주의사항:", caution);
console.log("법률 단어:", terminology);

return (
<Wrapper>
Expand All @@ -59,9 +56,9 @@ const GptAnalytics = () => {

<AnalyticsContent>
<ContentWrapper>
<ExpreessionTitle>표현해석</ExpreessionTitle>
{expression.length != 0 && <ExpreessionTitle>표현해석</ExpreessionTitle>}
{expression && expression.map((word, index) => <AnalyticsSource key={index}>{word}</AnalyticsSource>)}
<AnalyticsTitle>유의사항</AnalyticsTitle>
{caution.length != 0 && <AnalyticsTitle>유의사항</AnalyticsTitle>}
{caution && caution.map((word, index) => <AnalyticsSource key={index}>{word}</AnalyticsSource>)}
</ContentWrapper>
</AnalyticsContent>
Expand Down
20 changes: 8 additions & 12 deletions src/components/LegalTerminology.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,17 @@ const DUMMY_DATA = [
const LegalTerminology = () => {
const [currentPage, setCurrentPage] = useState(1);
const [currentGroup, setCurrentGroup] = useState(0);
const wordsPerPage = 3;
const wordsPerPage = 4;

const { terminologyData: terminology } = useStoreGptData();

const indexOfLastWord = currentPage * wordsPerPage;
const indexOfFirstWord = indexOfLastWord - wordsPerPage;

const currentData = DUMMY_DATA.slice(indexOfFirstWord, indexOfLastWord);
const currentData = terminology.slice(indexOfFirstWord, indexOfLastWord);
// 페이지 번호를 생성합니다.
const pageNumbers = [];
for (let i = 1; i <= Math.ceil(DUMMY_DATA.length / wordsPerPage); i++) {
for (let i = 1; i <= Math.ceil(terminology.length / wordsPerPage); i++) {
pageNumbers.push(i);
}

Expand All @@ -69,7 +69,6 @@ const LegalTerminology = () => {
try {
const response = await axios.get("http://15.165.159.196:8081/term/all");
setData(response.data);
console.log(response);
} catch (error) {
console.error("데이터를 불러오는데 실패했습니다.", error);
}
Expand All @@ -78,13 +77,10 @@ const LegalTerminology = () => {
fetchData();
}, []);

console.log(data);
const wordsObject = words.reduce((obj, word) => {
const wordsObject = data.reduce((obj, word) => {
obj[word.word] = word.meaning;
return obj;
}, {});
console.log(wordsObject);
console.log(wordsObject["인센티브"]);
return (
<Wrapper>
<MainTitle>Legal Terminology</MainTitle>
Expand All @@ -96,13 +92,13 @@ const LegalTerminology = () => {
<DataContent>{data.content}</DataContent>
</DataItem>
))} */}
{terminology.map((data, index) => {
const content = wordsObject[data.trim()];
console.log(content);
{currentData.map((data, index) => {
const content = wordsObject[data.replace(/\(.*\)|\.$/g, "").trim()];
return (
<DataItem key={index}>
<DataTitle>{data}</DataTitle>
{content && <DataContent>{content}</DataContent>}
{!content && <DataContent>해당 단어는 공공데이터 데이터베이스에서 제공하지 않는 단어 입니다!</DataContent>}
</DataItem>
);
})}
Expand Down Expand Up @@ -164,7 +160,7 @@ const DataItem = styled.div`
const DataTitle = styled.span`
font-size: 0.875rem;
font-weight: 700;
margin: 0;
margin-bottom: 0.2rem;
`;

const DataContent = styled.p`
Expand Down

0 comments on commit 571ae9f

Please sign in to comment.