-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
181 additions
and
231 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,31 @@ | ||
import { collection, getDocs, orderBy, query } from 'firebase/firestore'; | ||
import { Initialized, Success } from '@abraham/remotedata'; | ||
import { orderBy } from 'firebase/firestore'; | ||
import { Dispatch } from 'redux'; | ||
import { db } from '../../firebase'; | ||
import { Post } from '../../models/post'; | ||
import { mergeDataAndId } from '../../utils/firestore'; | ||
import { subscribeToCollection, Subscription } from '../../utils/firestore'; | ||
import { | ||
BlogActions, | ||
FETCH_BLOG_LIST, | ||
FETCH_BLOG_LIST_FAILURE, | ||
FETCH_BLOG_LIST_SUCCESS, | ||
} from './types'; | ||
|
||
const getPosts = async (): Promise<Post[]> => { | ||
const { docs } = await getDocs(query(collection(db, 'blog'), orderBy('published', 'desc'))); | ||
let subscription: Subscription = new Initialized(); | ||
|
||
return docs.map<Post>(mergeDataAndId); | ||
export const unsubscribe = () => { | ||
if (subscription instanceof Success) { | ||
subscription.data(); | ||
} | ||
}; | ||
|
||
export const fetchBlogPosts = async (dispatch: Dispatch<BlogActions>) => { | ||
dispatch({ | ||
type: FETCH_BLOG_LIST, | ||
}); | ||
|
||
try { | ||
dispatch({ | ||
type: FETCH_BLOG_LIST_SUCCESS, | ||
payload: await getPosts(), | ||
}); | ||
} catch (error) { | ||
dispatch({ | ||
type: FETCH_BLOG_LIST_FAILURE, | ||
payload: error, | ||
}); | ||
if (subscription instanceof Initialized) { | ||
subscription = subscribeToCollection( | ||
'blog', | ||
() => dispatch({ type: FETCH_BLOG_LIST }), | ||
(payload: Post[]) => dispatch({ type: FETCH_BLOG_LIST_SUCCESS, payload }), | ||
(payload: Error) => dispatch({ type: FETCH_BLOG_LIST_FAILURE, payload }), | ||
orderBy('published', 'desc') | ||
); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,31 @@ | ||
import { collection, getDocs, query } from 'firebase/firestore'; | ||
import { Initialized, Success } from '@abraham/remotedata'; | ||
import { orderBy } from 'firebase/firestore'; | ||
import { Dispatch } from 'redux'; | ||
import { db } from '../../firebase'; | ||
import { Photo } from '../../models/photo'; | ||
import { mergeDataAndId } from '../../utils/firestore'; | ||
import { subscribeToCollection, Subscription } from '../../utils/firestore'; | ||
import { | ||
FETCH_GALLERY, | ||
FETCH_GALLERY_FAILURE, | ||
FETCH_GALLERY_SUCCESS, | ||
GalleryActions, | ||
} from './types'; | ||
|
||
const getGalleries = async (): Promise<Photo[]> => { | ||
const { docs } = await getDocs(query(collection(db, 'gallery'))); | ||
let subscription: Subscription = new Initialized(); | ||
|
||
return docs.map<Photo>(mergeDataAndId); | ||
export const unsubscribe = () => { | ||
if (subscription instanceof Success) { | ||
subscription.data(); | ||
} | ||
}; | ||
|
||
export const fetchGallery = async (dispatch: Dispatch<GalleryActions>) => { | ||
dispatch({ | ||
type: FETCH_GALLERY, | ||
}); | ||
|
||
try { | ||
dispatch({ | ||
type: FETCH_GALLERY_SUCCESS, | ||
payload: await getGalleries(), | ||
}); | ||
} catch (error) { | ||
dispatch({ | ||
type: FETCH_GALLERY_FAILURE, | ||
payload: error, | ||
}); | ||
if (subscription instanceof Initialized) { | ||
subscription = subscribeToCollection( | ||
'gallery', | ||
() => dispatch({ type: FETCH_GALLERY }), | ||
(payload: Photo[]) => dispatch({ type: FETCH_GALLERY_SUCCESS, payload }), | ||
(payload: Error) => dispatch({ type: FETCH_GALLERY_FAILURE, payload }), | ||
orderBy('order') | ||
); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,29 @@ | ||
import { collection, getDocs, orderBy, query } from 'firebase/firestore'; | ||
import { Initialized, Success } from '@abraham/remotedata'; | ||
import { Dispatch } from 'redux'; | ||
import { db } from '../../firebase'; | ||
import { PreviousSpeaker } from '../../models/previous-speaker'; | ||
import { mergeDataAndId } from '../../utils/firestore'; | ||
import { subscribeToCollection, Subscription } from '../../utils/firestore'; | ||
import { | ||
FETCH_PREVIOUS_SPEAKERS, | ||
FETCH_PREVIOUS_SPEAKERS_FAILURE, | ||
FETCH_PREVIOUS_SPEAKERS_SUCCESS, | ||
PreviousSpeakersActions, | ||
} from './types'; | ||
|
||
const getPreviousSpeakers = async (): Promise<PreviousSpeaker[]> => { | ||
const { docs } = await getDocs( | ||
query(collection(db, 'previousSpeakers'), orderBy('order', 'asc')) | ||
); | ||
let subscription: Subscription = new Initialized(); | ||
|
||
return docs.map<PreviousSpeaker>(mergeDataAndId).sort((speakerA, speakerB) => { | ||
return speakerA.name.localeCompare(speakerB.name); | ||
}); | ||
export const unsubscribe = () => { | ||
if (subscription instanceof Success) { | ||
subscription.data(); | ||
} | ||
}; | ||
|
||
export const fetchPreviousSpeakers = async (dispatch: Dispatch<PreviousSpeakersActions>) => { | ||
dispatch({ | ||
type: FETCH_PREVIOUS_SPEAKERS, | ||
}); | ||
|
||
try { | ||
dispatch({ | ||
type: FETCH_PREVIOUS_SPEAKERS_SUCCESS, | ||
payload: await getPreviousSpeakers(), | ||
}); | ||
} catch (error) { | ||
dispatch({ | ||
type: FETCH_PREVIOUS_SPEAKERS_FAILURE, | ||
payload: error, | ||
}); | ||
if (subscription instanceof Initialized) { | ||
subscription = subscribeToCollection( | ||
'previousSpeakers', | ||
() => dispatch({ type: FETCH_PREVIOUS_SPEAKERS }), | ||
(payload: PreviousSpeaker[]) => dispatch({ type: FETCH_PREVIOUS_SPEAKERS_SUCCESS, payload }), | ||
(payload: Error) => dispatch({ type: FETCH_PREVIOUS_SPEAKERS_FAILURE, payload }) | ||
); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,31 @@ | ||
import { collection, getDocs, query } from 'firebase/firestore'; | ||
import { Initialized, Success } from '@abraham/remotedata'; | ||
import { orderBy } from 'firebase/firestore'; | ||
import { Dispatch } from 'redux'; | ||
import { db } from '../../firebase'; | ||
import { Day } from '../../models/day'; | ||
import { subscribeToCollection, Subscription } from '../../utils/firestore'; | ||
import { | ||
FETCH_SCHEDULE, | ||
FETCH_SCHEDULE_FAILURE, | ||
FETCH_SCHEDULE_SUCCESS, | ||
ScheduleActions, | ||
} from './types'; | ||
|
||
const getSchedule = async (): Promise<Day[]> => { | ||
const { docs } = await getDocs(query(collection(db, 'generatedSchedule'))); | ||
let subscription: Subscription = new Initialized(); | ||
|
||
return docs.map<Day>((doc) => doc.data() as Day).sort((a, b) => a.date.localeCompare(b.date)); | ||
export const unsubscribe = () => { | ||
if (subscription instanceof Success) { | ||
subscription.data(); | ||
} | ||
}; | ||
|
||
export const fetchSchedule = async (dispatch: Dispatch<ScheduleActions>) => { | ||
dispatch({ | ||
type: FETCH_SCHEDULE, | ||
}); | ||
|
||
try { | ||
dispatch({ | ||
type: FETCH_SCHEDULE_SUCCESS, | ||
payload: await getSchedule(), | ||
}); | ||
} catch (error) { | ||
dispatch({ | ||
type: FETCH_SCHEDULE_FAILURE, | ||
payload: error, | ||
}); | ||
if (subscription instanceof Initialized) { | ||
subscription = subscribeToCollection( | ||
'generatedSchedule', | ||
() => dispatch({ type: FETCH_SCHEDULE }), | ||
(payload: Day[]) => dispatch({ type: FETCH_SCHEDULE_SUCCESS, payload }), | ||
(payload: Error) => dispatch({ type: FETCH_SCHEDULE_FAILURE, payload }), | ||
orderBy('date') | ||
); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,31 @@ | ||
import { collection, getDocs, query } from 'firebase/firestore'; | ||
import { Initialized, Success } from '@abraham/remotedata'; | ||
import { orderBy } from 'firebase/firestore'; | ||
import { Dispatch } from 'redux'; | ||
import { db } from '../../firebase'; | ||
import { Session } from '../../models/session'; | ||
import { mergeDataAndId } from '../../utils/firestore'; | ||
import { subscribeToCollection, Subscription } from '../../utils/firestore'; | ||
import { | ||
FETCH_SESSIONS, | ||
FETCH_SESSIONS_FAILURE, | ||
FETCH_SESSIONS_SUCCESS, | ||
SessionsActions, | ||
} from './types'; | ||
|
||
const getSessions = async () => { | ||
const { docs } = await getDocs(query(collection(db, 'generatedSessions'))); | ||
return docs.map<Session>(mergeDataAndId); | ||
let subscription: Subscription = new Initialized(); | ||
|
||
export const unsubscribe = () => { | ||
if (subscription instanceof Success) { | ||
subscription.data(); | ||
} | ||
}; | ||
|
||
export const fetchSessions = async (dispatch: Dispatch<SessionsActions>) => { | ||
dispatch({ | ||
type: FETCH_SESSIONS, | ||
}); | ||
|
||
try { | ||
dispatch({ | ||
type: FETCH_SESSIONS_SUCCESS, | ||
payload: await getSessions(), | ||
}); | ||
} catch (error) { | ||
dispatch({ | ||
type: FETCH_SESSIONS_FAILURE, | ||
payload: error, | ||
}); | ||
if (subscription instanceof Initialized) { | ||
subscription = subscribeToCollection( | ||
'generatedSessions', | ||
() => dispatch({ type: FETCH_SESSIONS }), | ||
(payload: Session[]) => dispatch({ type: FETCH_SESSIONS_SUCCESS, payload }), | ||
(payload: Error) => dispatch({ type: FETCH_SESSIONS_FAILURE, payload }), | ||
orderBy('day') | ||
); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.