63 lines
2.0 KiB
JavaScript
63 lines
2.0 KiB
JavaScript
import React, { useEffect, useState } from 'react';
|
|
import { useTool } from '../context/ToolContext';
|
|
|
|
export default function ToolsPage({ onNavigate }) {
|
|
const { tools, favorites, toggleFavorite, setSelectedTool } = useTool();
|
|
const [filter, setFilter] = useState('all');
|
|
|
|
const filtered = tools.filter((tool) => {
|
|
if (filter === 'all') return true;
|
|
if (filter === 'favorite') return favorites.includes(tool.id);
|
|
return tool.category?.includes(filter);
|
|
});
|
|
|
|
const handleSelect = (tool) => {
|
|
setSelectedTool(tool);
|
|
onNavigate && onNavigate('chat');
|
|
};
|
|
|
|
return (
|
|
<section className="page page-tools" style={{ flex: 1, display:'flex', flexDirection:'column' }}>
|
|
<div className="tools-header">
|
|
<span className="tools-title">도구 목록</span>
|
|
<div className="tools-filters">
|
|
{['all', 'favorite', '오픈AI', '내부AI'].map((f) => (
|
|
<button
|
|
key={f}
|
|
className={`filter-btn ${filter === f ? 'active' : ''}`}
|
|
onClick={() => setFilter(f)}
|
|
data-filter={f}
|
|
>
|
|
{f === 'all' ? '전체' : f === 'favorite' ? '즐겨찾기' : f}
|
|
</button>
|
|
))}
|
|
</div>
|
|
</div>
|
|
<div className="tools-list">
|
|
{filtered.map((tool) => {
|
|
const fav = favorites.includes(tool.id);
|
|
return (
|
|
<div
|
|
className="tool-card"
|
|
key={tool.id}
|
|
data-tool-id={tool.id}
|
|
onClick={() => handleSelect(tool)}
|
|
>
|
|
<div className="tool-title">{tool.name}</div>
|
|
<div className="tool-desc">{tool.description}</div>
|
|
<div
|
|
className={`tool-fav ${fav ? 'active' : ''}`}
|
|
onClick={(e) => {
|
|
e.stopPropagation();
|
|
toggleFavorite(tool.id);
|
|
}}
|
|
>
|
|
★
|
|
</div>
|
|
</div>
|
|
);
|
|
})}
|
|
</div>
|
|
</section>
|
|
);
|
|
}
|