diff --git a/src/components/navbar/NavigationBar.scss b/src/components/navbar/NavigationBar.scss index 83a6250..be87556 100644 --- a/src/components/navbar/NavigationBar.scss +++ b/src/components/navbar/NavigationBar.scss @@ -1,7 +1,7 @@ // Variables for colors and other reusable properties $primary-color: #333; $secondary-color: #555; -$hover-color: #f39c12; +$hover-color: #6e6e6e; $background-color: #f8f9fa; $dark-color: #000; $light-color: #fff; diff --git a/src/components/topics/Topics.jsx b/src/components/topics/Topics.jsx index 2726d12..f8e0232 100644 --- a/src/components/topics/Topics.jsx +++ b/src/components/topics/Topics.jsx @@ -1,17 +1,22 @@ -import {LANGUAGE} from "../../utils/Constants.js"; +import {LANGUAGE, mapLanguageCode} from "../../utils/Constants.js"; import axiosInstance from "../../config/axios-config.js"; import {useQuery} from "react-query"; -import { useState } from "react"; +import { useState, useEffect } from "react"; import {useNavigate, useParams} from "react-router-dom"; import {Button, Card, Col, Container, Form, Row} from "react-bootstrap"; import "./Topics.scss" import {useTranslate} from "@tolgee/react"; const fetchTopics = async (parentId) => { - console.log(parentId) - const language = localStorage.getItem(LANGUAGE) ?? "bo"; + const storedLanguage = localStorage.getItem(LANGUAGE); + const language =(storedLanguage ? mapLanguageCode(storedLanguage) : "bo"); const { data } = await axiosInstance.get("api/v1/topics", { - params: {language, ...(parentId && { parent_id: parentId })} + params: { + language, + ...(parentId && { parent_id: parentId }), + limit: 12, + skip: 0 + } }); return data; } @@ -23,20 +28,52 @@ const Topics = () => { const [parentId, setParentId] = useState(id || ""); const [searchTerm, setSearchTerm] = useState(""); const [selectedLetter, setSelectedLetter] = useState(""); + const [currentLanguage, setCurrentLanguage] = useState(localStorage.getItem(LANGUAGE)); const translatedKey = t("topic.alphabet"); const cleanAlphabetArray = translatedKey .split("") .filter((char) => char.match(/[a-zA-Z.\u0F00-\u0FFF]/)); - const { data: topicsData, isLoading: topicsIsLoading } = useQuery( - ["topics", parentId], + const { data: topicsData, isLoading, isFetching } = useQuery( + ["topics", parentId, currentLanguage], () => fetchTopics(parentId), - { refetchOnWindowFocus: false } + { refetchOnWindowFocus: false,refetchOnMount: true } ); - if(topicsIsLoading){ - return
Loading ...
+ + useEffect(() => { + const handleStorageChange = (e) => { + if (e.key === LANGUAGE) { + setCurrentLanguage(e.newValue); + } + }; + + window.addEventListener('storage', handleStorageChange); + + const intervalId = setInterval(() => { + const storedLanguage = localStorage.getItem(LANGUAGE); + if (storedLanguage !== currentLanguage) { + setCurrentLanguage(storedLanguage); + } + }, 1000); + + return () => { + window.removeEventListener('storage', handleStorageChange); + clearInterval(intervalId); + }; + }, [currentLanguage]); + + if(isLoading || isFetching){ + return ( +Loading topics...
+ +