Ignore:
Timestamp:
12/12/24 17:06:06 (5 weeks ago)
Author:
stefan toskovski <stefantoska84@…>
Branches:
main
Parents:
d565449
Message:

Pred finalna verzija

File:
1 edited

Legend:

Unmodified
Added
Removed
  • imaps-frontend/src/components/FilterBar/FilterBar.jsx

    rd565449 r0c6b92a  
    1 import React from "react";
     1import React, { useState, useEffect, useCallback } from "react";
    22import styles from "./FilterBar.module.css";
    33
    4 function FilterBar() {
    5   const filterLocation = (category) => {
    6     console.log(`Filter locations by: ${category}`);
    7     // filtering logic
    8   };
     4export default function FilterBar({roomTypes,map}) {
     5  const [selectedCategory, setSelectedCategory] = useState("all");
     6
     7
     8
     9  const filterLocation = useCallback((category) => {
     10    map.setFilter(category)
     11    setSelectedCategory(category);
     12  },[])
    913
    1014  return (
    1115    <div className={styles.wrapper}>
    1216      <div className={styles.scrollableContainer}>
    13         <button className={styles.buttonValue} onClick={() => filterLocation("all")}>
     17        <button
     18          className={`${styles.buttonValue} ${selectedCategory === "all" ? styles.active : ""}`}
     19          onClick={() => filterLocation("all")}
     20        >
    1421          All
    1522        </button>
    16         <button className={styles.buttonValue} onClick={() => filterLocation("Classrooms")}>
    17           Classrooms
    18         </button>
    19         <button className={styles.buttonValue} onClick={() => filterLocation("Administrative")}>
    20           Administrative
    21         </button>
    22         <button className={styles.buttonValue} onClick={() => filterLocation("Labs")}>
    23           Labs
    24         </button>
    25         <button className={styles.buttonValue} onClick={() => filterLocation("Restrooms")}>
    26           Restrooms
    27         </button>
    28         <button className={styles.buttonValue} onClick={() => filterLocation("Cafeteria")}>
    29           Cafeteria
    30         </button>
     23
     24        {roomTypes?.map((roomType, index) => (
     25          <button
     26            key={index}
     27            className={`${styles.buttonValue} ${selectedCategory === roomType.name ? styles.active : ""}`}
     28            onClick={() => filterLocation(roomType.name)}
     29          >
     30            {roomType.name}
     31          </button>
     32        ))}
    3133      </div>
    3234    </div>
     
    3436}
    3537
    36 export default FilterBar;
Note: See TracChangeset for help on using the changeset viewer.