diff --git a/src/Components/DatePicker/DatePicker.tsx b/src/Components/DatePicker/DatePicker.tsx index 9aa57aa8..1771d149 100644 --- a/src/Components/DatePicker/DatePicker.tsx +++ b/src/Components/DatePicker/DatePicker.tsx @@ -1,4 +1,4 @@ -import { useState, useEffect} from 'react'; +import { useState, useEffect } from 'react'; import { format, subMonths, @@ -10,7 +10,6 @@ import { getDay, } from 'date-fns'; - type DatepickerType = 'date' | 'month' | 'year'; type DatepickerProps = { @@ -65,7 +64,8 @@ const DatePicker = ({ selectedDate, setSelectedDate }: DatepickerProps) => { new Date( datepickerHeaderDate.getFullYear(), datepickerHeaderDate.getMonth(), - date + date, + new Date().getHours() ) ); setShowDatepicker(false); @@ -290,4 +290,4 @@ const DatePicker = ({ selectedDate, setSelectedDate }: DatepickerProps) => { ); }; -export default DatePicker; \ No newline at end of file +export default DatePicker; diff --git a/src/Pages/SurveyAnswerPage/SurveyAnswerPage.tsx b/src/Pages/SurveyAnswerPage/SurveyAnswerPage.tsx index 011add35..21529d67 100644 --- a/src/Pages/SurveyAnswerPage/SurveyAnswerPage.tsx +++ b/src/Pages/SurveyAnswerPage/SurveyAnswerPage.tsx @@ -11,6 +11,8 @@ import { doc, getDoc, getDocs, + orderBy, + query, Timestamp, } from 'firebase/firestore'; import { BarChartData } from '../../Components/BarChart/BarChart'; @@ -58,10 +60,18 @@ function SurveyAnswerPage() { navigate('/'); return; } - - const answersData = await getDocs( - collection(db, 'surveys', surveyId!, 'answers') + const anserwsCollectionRef = collection( + db, + 'surveys', + surveyId!, + 'answers' + ); + const anserwsQuery = query( + anserwsCollectionRef, + orderBy('answerDate', 'desc') ); + + const answersData = await getDocs(anserwsQuery); setVotes(answersData.docs.length); setStartDate( diff --git a/src/Pages/SurveyListPage/SurveyListPage.tsx b/src/Pages/SurveyListPage/SurveyListPage.tsx index 4ff6eae9..9ca36f82 100644 --- a/src/Pages/SurveyListPage/SurveyListPage.tsx +++ b/src/Pages/SurveyListPage/SurveyListPage.tsx @@ -1,6 +1,12 @@ import { useCollection } from 'react-firebase-hooks/firestore'; import { db, auth } from '../../firebase'; -import { collection, query, Timestamp, where } from 'firebase/firestore'; +import { + collection, + query, + Timestamp, + where, + orderBy, +} from 'firebase/firestore'; import { useDocumentTitle } from '../../Hooks/useDocumentTitle'; import Header from '../../Components/Header'; import SurveyRow from '../../Components/SurveyRow'; @@ -13,7 +19,11 @@ function SurveyListPage() { const [user] = useAuthState(auth); const surveysCollectionRef = collection(db, 'surveys'); - const q = query(surveysCollectionRef, where('creatorId', '==', user?.uid)); + const q = query( + surveysCollectionRef, + where('creatorId', '==', user?.uid), + orderBy('startDate', 'desc') + ); const [surveysCollection, loading, error] = useCollection(q); return (