chore: adjust select item mapping method

This commit is contained in:
Mahen 2026-02-13 10:37:00 +07:00
parent 9762069aa4
commit fd94d4a599
3 changed files with 21 additions and 24 deletions

View File

@ -1,7 +1,7 @@
"use client"; "use client";
import { useAnalyseText } from "@/src/hooks/useAnalyzeText"; import { useAnalyseText } from "@/src/hooks/useAnalyzeText";
import { Sparkles, Trophy } from "lucide-react"; import { Sparkles } from "lucide-react";
import { import {
Select, Select,
SelectContent, SelectContent,
@ -11,9 +11,8 @@ import {
} from "../ui/select"; } from "../ui/select";
import { Input } from "../ui/input"; import { Input } from "../ui/input";
import { Button } from "../ui/button"; import { Button } from "../ui/button";
import { motion } from "framer-motion";
import { useState } from "react";
import ResultSection from "./ResultSection"; import ResultSection from "./ResultSection";
import { professions } from "@/src/utils/datas";
export default function AnalysisClient() { export default function AnalysisClient() {
const { const {
@ -24,20 +23,15 @@ export default function AnalysisClient() {
loading, loading,
result, result,
disabled, disabled,
showField,
handleAnalyze, handleAnalyze,
setProfession, setProfession,
setUrl1, setUrl1,
setUrl2, setUrl2,
setDisabled, setDisabled,
setUrl3, setUrl3,
setShowField,
} = useAnalyseText(); } = useAnalyseText();
const [showField, setShowField] = useState(false);
const getSentimentTone = (score: number) => {
if (score >= 80) return "strong";
if (score >= 60) return "light";
return "neutral";
};
return ( return (
<div className="w-full mx-auto"> <div className="w-full mx-auto">
@ -62,18 +56,11 @@ export default function AnalysisClient() {
className="bg-card border-border shadow-lg" className="bg-card border-border shadow-lg"
position="popper" position="popper"
> >
<SelectItem className="cursor-pointer" value="programmer"> {professions.map((item) => (
Programmer <SelectItem key={item.value} value={item.value}>
</SelectItem> {item.label}
<SelectItem className="cursor-pointer" value="designer"> </SelectItem>
Designer ))}
</SelectItem>
<SelectItem className="cursor-pointer" value="student">
Student
</SelectItem>
<SelectItem className="cursor-pointer" value="gamer">
Gamer
</SelectItem>
</SelectContent> </SelectContent>
</Select> </Select>
</div> </div>

View File

@ -9,6 +9,7 @@ export const useAnalyseText = () => {
const [loading, setLoading] = useState(false); const [loading, setLoading] = useState(false);
const [result, setResult] = useState<AnalysisResults | null>(null); const [result, setResult] = useState<AnalysisResults | null>(null);
const [disabled, setDisabled] = useState(false); const [disabled, setDisabled] = useState(false);
const [showField, setShowField] = useState(false);
const handleAnalyze = async () => { const handleAnalyze = async () => {
setLoading(true); setLoading(true);
@ -21,7 +22,7 @@ export const useAnalyseText = () => {
if (urlsToScrape.length < 2) { if (urlsToScrape.length < 2) {
alert("Produk Utama dan minimal 1 Produk Pembanding wajib diisi!"); alert("Produk Utama dan minimal 1 Produk Pembanding wajib diisi!");
setLoading(false); setLoading(false);
return; return;
} }
@ -29,7 +30,7 @@ export const useAnalyseText = () => {
fetch("/api/scrape", { fetch("/api/scrape", {
method: "POST", method: "POST",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
}, },
body: JSON.stringify({ url: u }), body: JSON.stringify({ url: u }),
}).then((res) => { }).then((res) => {
@ -81,11 +82,13 @@ export const useAnalyseText = () => {
loading, loading,
result, result,
disabled, disabled,
showField,
handleAnalyze, handleAnalyze,
setProfession, setProfession,
setUrl1, setUrl1,
setUrl2, setUrl2,
setUrl3, setUrl3,
setDisabled, setDisabled,
setShowField,
}; };
}; };

View File

@ -90,3 +90,10 @@ export function getFallbackData(url: string): ScrapeResult {
], ],
}; };
} }
export const professions = [
{ value: "programmer", label: "Programmer" },
{ value: "designer", label: "Designer" },
{ value: "student", label: "Student" },
{ value: "gamer", label: "Gamer" },
];