Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/sort surveys #31

Merged
merged 2 commits into from
May 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/Components/DatePicker/DatePicker.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useState, useEffect} from 'react';
import { useState, useEffect } from 'react';
import {
format,
subMonths,
Expand All @@ -10,7 +10,6 @@ import {
getDay,
} from 'date-fns';


type DatepickerType = 'date' | 'month' | 'year';

type DatepickerProps = {
Expand Down Expand Up @@ -65,7 +64,8 @@ const DatePicker = ({ selectedDate, setSelectedDate }: DatepickerProps) => {
new Date(
datepickerHeaderDate.getFullYear(),
datepickerHeaderDate.getMonth(),
date
date,
new Date().getHours()
)
);
setShowDatepicker(false);
Expand Down Expand Up @@ -290,4 +290,4 @@ const DatePicker = ({ selectedDate, setSelectedDate }: DatepickerProps) => {
);
};

export default DatePicker;
export default DatePicker;
16 changes: 13 additions & 3 deletions src/Pages/SurveyAnswerPage/SurveyAnswerPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import {
doc,
getDoc,
getDocs,
orderBy,
query,
Timestamp,
} from 'firebase/firestore';
import { BarChartData } from '../../Components/BarChart/BarChart';
Expand Down Expand Up @@ -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(
Expand Down
14 changes: 12 additions & 2 deletions src/Pages/SurveyListPage/SurveyListPage.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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 (
Expand Down