Skip to content

Commit

Permalink
Update works.jsx
Browse files Browse the repository at this point in the history
  • Loading branch information
dennislee928 committed May 21, 2024
1 parent 0ee613e commit f98fb5c
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions frontstage/app/components/works/works.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ const PublicArtComponent = () => {
const fetchData = async () => {
try {
const response = await axios.get("http://localhost:3001/api/publicart");
setData(response.data);
console.log(response.data);
setData(Array.isArray(response.data) ? response.data : []);
} catch (error) {
setError(error);
} finally {
Expand All @@ -36,12 +37,13 @@ const PublicArtComponent = () => {
[e.target.name]: e.target.value,
});
};

//
const [filteredData, setFilteredData] = useState([]);
//
const handleSearch = () => {
setLoading(true);
try {
// Filter data based on input
const filteredData = data.filter(
const results = data.filter(
(item) =>
(!filters.district || item.district.includes(filters.district)) &&
(!filters.name || item.name.includes(filters.name)) &&
Expand All @@ -51,7 +53,7 @@ const PublicArtComponent = () => {
(!filters.type || item.type.includes(filters.type)) &&
(!filters.manager || item.manager.includes(filters.manager))
);
setData(filteredData);
setFilteredData(results);
} catch (error) {
setError(error);
} finally {
Expand All @@ -78,7 +80,7 @@ const PublicArtComponent = () => {
<button onClick={handleSearch}>Search</button>
</div>
<div>
{data.map((item, index) => (
{filteredData.map((item, index) => (
<div
key={index}
style={{
Expand Down

0 comments on commit f98fb5c

Please sign in to comment.