From cff8f57f2e48edc6dd286841e8ead15cd9cb3474 Mon Sep 17 00:00:00 2001 From: Ochieng Paul Date: Wed, 18 Sep 2024 00:03:55 +0300 Subject: [PATCH 1/3] included link to reporting tool --- website/frontend/locales/en/translation.json | 4 + website/frontend/locales/fr/translation.json | 4 + website/frontend/src/components/nav/TopBar.js | 10 ++ .../src/pages/Publications/Publications.js | 144 +++++++----------- 4 files changed, 76 insertions(+), 86 deletions(-) diff --git a/website/frontend/locales/en/translation.json b/website/frontend/locales/en/translation.json index dbd7afbc09..852563b8d7 100644 --- a/website/frontend/locales/en/translation.json +++ b/website/frontend/locales/en/translation.json @@ -29,6 +29,10 @@ "calibrate": { "name": "AirQalibrate", "desc": "Calibrate your low-cost sensor data" + }, + "reporting": { + "name": "Air Quality Reporting Tool", + "desc": "Generate and download reports" } } }, diff --git a/website/frontend/locales/fr/translation.json b/website/frontend/locales/fr/translation.json index b1551f0073..1ec90af60c 100644 --- a/website/frontend/locales/fr/translation.json +++ b/website/frontend/locales/fr/translation.json @@ -29,6 +29,10 @@ "calibrate": { "name": "AirQalibrate", "desc": "Étalonnez les données de vos capteurs à faible coût" + }, + "reporting": { + "name": "Outil de Rapports sur la Qualité de l'Air", + "desc": "Générer et télécharger des rapports" } } }, diff --git a/website/frontend/src/components/nav/TopBar.js b/website/frontend/src/components/nav/TopBar.js index 180cdc3951..3540b71fc9 100644 --- a/website/frontend/src/components/nav/TopBar.js +++ b/website/frontend/src/components/nav/TopBar.js @@ -98,6 +98,16 @@ const TopBar = () => {

{t('navbar.products.subnav.calibrate.desc')}

+
+ +

{t('navbar.products.subnav.reporting.name')}

+

{t('navbar.products.subnav.reporting.desc')}

+ +
diff --git a/website/frontend/src/pages/Publications/Publications.js b/website/frontend/src/pages/Publications/Publications.js index 5f9427429f..d62e01637a 100644 --- a/website/frontend/src/pages/Publications/Publications.js +++ b/website/frontend/src/pages/Publications/Publications.js @@ -15,59 +15,84 @@ const PublicationsPage = () => { useInitScrollTop(); const { t } = useTranslation(); const dispatch = useDispatch(); - const [selectedTab, setSelectedTab] = useState(''); + + // Redux state const publicationsData = useSelector((state) => state.publicationsData.publications); const loading = useSelector((state) => state.publicationsData.loading); const language = useSelector((state) => state.eventsNavTab.languageTab); + // Pagination settings + const itemsPerPage = 6; + + // Initialize selectedTab state by checking URL params for 'tab' + const getInitialTab = () => { + const url = new URL(window.location); + const tabParam = url.searchParams.get('tab'); + return tabParam || 'Research'; // Default to 'Research' if no tab is specified + }; + + const [selectedTab, setSelectedTab] = useState(getInitialTab); + const [currentPage, setCurrentPage] = useState(1); + + // Fetch publications data if it's empty useEffect(() => { if (isEmpty(publicationsData)) { dispatch(loadPublicationsData()); } }, [dispatch, publicationsData, language]); + // Update URL when tab changes useEffect(() => { const url = new URL(window.location); - const tab = url.searchParams.get('tab'); - if (tab) { - setSelectedTab(tab); - } - }, []); - - useEffect(() => { - if (selectedTab) { - const url = new URL(window.location); - url.searchParams.set('tab', selectedTab); - window.history.replaceState({}, '', url); - } + url.searchParams.set('tab', selectedTab); + window.history.replaceState({}, '', url); }, [selectedTab]); - const filterData = (categories) => { - return publicationsData.filter((publication) => categories.includes(publication.category)); - }; + // Filter publications by category + const filterData = (categories) => + publicationsData.filter((publication) => categories.includes(publication.category)); const ResearchData = filterData(['research']); const ReportsData = filterData(['technical', 'policy']); const GuidesData = filterData(['guide', 'manual']); - const [currentPage, setCurrentPage] = useState(1); - const itemsPerPage = 6; - + // Pagination logic const paginateData = (data) => { const lastItem = currentPage * itemsPerPage; const firstItem = lastItem - itemsPerPage; return data.slice(firstItem, lastItem); }; + // Current paginated data for each tab const currentResearch = paginateData(ResearchData); const currentReports = paginateData(ReportsData); const currentGuides = paginateData(GuidesData); - const totalResearch = ResearchData.length; - const totalReports = ReportsData.length; - const totalGuides = GuidesData.length; + const totalItems = { + Research: ResearchData.length, + Reports: ReportsData.length, + Guides: GuidesData.length + }; - const paginate = (pageNumber) => setCurrentPage(pageNumber); + const handleTabChange = (tab) => { + setSelectedTab(tab); + setCurrentPage(1); // Reset to the first page when switching tabs + }; + + const renderPublications = (publications, Component) => + publications.map((publication) => ( +
+
+ +
+
+ )); return ( @@ -101,93 +126,40 @@ const PublicationsPage = () => { +
- {selectedTab === 'Research' || !selectedTab ? ( - currentResearch.map((publication) => ( -
-
- -
-
- )) - ) : ( -
- )} - {selectedTab === 'Reports' ? ( - currentReports.map((publication) => ( - - )) - ) : ( -
- )} - {selectedTab === 'Guides' ? ( - currentGuides.map((guide) => ( - - )) - ) : ( -
- )} + {selectedTab === 'Research' && renderPublications(currentResearch, CardComponent)} + {selectedTab === 'Reports' && renderPublications(currentReports, ReportComponent)} + {selectedTab === 'Guides' && renderPublications(currentGuides, ReportComponent)}
+
)} From e522b03add8521e10ad285feed6273f9d7c11678 Mon Sep 17 00:00:00 2001 From: Ochieng Paul Date: Wed, 18 Sep 2024 00:16:10 +0300 Subject: [PATCH 2/3] code corrections --- website/frontend/src/components/nav/TopBar.js | 6 +++--- website/frontend/src/pages/Publications/Publications.js | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/website/frontend/src/components/nav/TopBar.js b/website/frontend/src/components/nav/TopBar.js index 3540b71fc9..233fa14633 100644 --- a/website/frontend/src/components/nav/TopBar.js +++ b/website/frontend/src/components/nav/TopBar.js @@ -99,14 +99,14 @@ const TopBar = () => {
-

{t('navbar.products.subnav.reporting.name')}

{t('navbar.products.subnav.reporting.desc')}

- +
diff --git a/website/frontend/src/pages/Publications/Publications.js b/website/frontend/src/pages/Publications/Publications.js index d62e01637a..dce6fee809 100644 --- a/website/frontend/src/pages/Publications/Publications.js +++ b/website/frontend/src/pages/Publications/Publications.js @@ -28,7 +28,8 @@ const PublicationsPage = () => { const getInitialTab = () => { const url = new URL(window.location); const tabParam = url.searchParams.get('tab'); - return tabParam || 'Research'; // Default to 'Research' if no tab is specified + const allowedTabs = ['Research', 'Reports', 'Guides']; + return allowedTabs.includes(tabParam) ? tabParam : 'Research'; }; const [selectedTab, setSelectedTab] = useState(getInitialTab); From 7fad1b9a64fcde1eca70cd99f5fccc91e77cba35 Mon Sep 17 00:00:00 2001 From: Benjamin Ssempala <86492979+BenjaminSsempala@users.noreply.github.com> Date: Wed, 18 Sep 2024 07:54:40 +0300 Subject: [PATCH 3/3] Increment versions for new release --- mobile/android/fastlane/release_notes.txt | 1 + mobile/pubspec.yaml | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/mobile/android/fastlane/release_notes.txt b/mobile/android/fastlane/release_notes.txt index f59d2253ad..0a7d93f04b 100644 --- a/mobile/android/fastlane/release_notes.txt +++ b/mobile/android/fastlane/release_notes.txt @@ -1,2 +1,3 @@ +Pidgin Translations Bug Fixes Performance enhancements \ No newline at end of file diff --git a/mobile/pubspec.yaml b/mobile/pubspec.yaml index e19bab6a25..06b696438d 100644 --- a/mobile/pubspec.yaml +++ b/mobile/pubspec.yaml @@ -14,7 +14,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev # Read more about iOS versioning at # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html # android test -version: 2.1.2+20057 +version: 2.1.3+20058 environment: sdk: '>=3.0.0 <4.0.0'