1
1
import React , { useEffect , useState } from 'react'
2
2
import { useDispatch , useSelector } from 'react-redux'
3
3
import { View } from 'react-native'
4
- import { Button , HStack } from 'native-base'
4
+ import { Button , HStack , ScrollView } from 'native-base'
5
5
import { useTheme } from '@/Theme'
6
6
import FetchAlbumByDate from '@/Store/Album/FetchByDate'
7
7
import FetchPhotosWithoutDate from '@/Store/Album/FetchPhotosWithoutDate'
8
- import TimelineList from '../../Components/TimelineList'
9
- import { TopBar } from '../../Components'
10
- import ImageGrid from '../../Components/ImageGrid'
8
+ import FetchRecentlyAdded from '@/Store/Album/FetchRecentlyAdded'
9
+ import FetchFavourites from '@/Store/Album/FetchFavourites'
10
+ import FetchHidden from '@/Store/Album/FetchHidden'
11
+ import FetchPublic from '@/Store/Album/FetchPublic'
12
+ import TimelineList from '@/Components/TimelineList'
13
+ import { TopBar } from '@/Components'
14
+ import ImageGrid from '@/Components/ImageGrid'
15
+
16
+ const CategoryType = {
17
+ PhotosByDate : 'With Timestamp' ,
18
+ PhotosWithoutDate : 'Without Timestamp' ,
19
+ Recent : 'Recently Added' ,
20
+ Favourite : 'Favourites' ,
21
+ Public : 'Public Photos' ,
22
+ Hidden : 'Hidden' ,
23
+ }
11
24
12
25
const GalleryContainer = ( ) => {
13
26
const { Common, Layout } = useTheme ( )
@@ -16,108 +29,136 @@ const GalleryContainer = () => {
16
29
const albums = useSelector ( state => state . album )
17
30
const albumByDate = useSelector ( state => state . album . albumByDate )
18
31
const albumWithoutDate = useSelector ( state => state . album . albumWithoutDate )
19
- const photosByDate = albumByDate ?. results
32
+ const albumRecentlyAdded = useSelector (
33
+ state => state . album . albumRecentlyAdded ,
34
+ )
35
+ const albumFavourites = useSelector ( state => state . album . albumFavourites )
36
+ const albumPublic = useSelector ( state => state . album . albumPublic )
37
+ const albumHidden = useSelector ( state => state . album . albumHidden )
38
+ const photosByDate = albumByDate
20
39
const photosWithoutDate = albumWithoutDate ?. results
21
40
22
- useEffect ( ( ) => {
23
- handleAlbumWithoutDateRefresh ( )
24
- handleAlbumWithDateRefresh ( )
25
- // eslint-disable-next-line react-hooks/exhaustive-deps
26
- } , [ ] )
27
-
28
- const handleAlbumWithoutDateRefresh = ( ) => {
29
- dispatch ( FetchPhotosWithoutDate . action ( ) )
30
- }
31
-
32
- const handleAlbumWithDateRefresh = ( ) => {
33
- dispatch ( FetchAlbumByDate . action ( ) )
34
- }
35
-
36
- const imageGridMapper = sectionData => {
37
- if ( typeof sectionData === 'undefined' || sectionData . length < 1 ) {
38
- return [ ]
39
- }
40
-
41
- let finalmap = sectionData . map ( item => {
42
- return {
43
- url : item . url ,
44
- }
45
- } )
46
-
47
- return finalmap
48
- }
41
+ const [ category , setCategory ] = useState ( CategoryType . PhotosByDate )
49
42
50
- const photoMapper = photosResult => {
51
- if ( typeof photosResult === 'undefined' || photosResult . length < 1 ) {
52
- return [ ]
43
+ useEffect ( ( ) => {
44
+ console . log ( 'Fetching Category: ' + category )
45
+ switch ( category ) {
46
+ case CategoryType . PhotosByDate :
47
+ dispatch ( FetchPhotosWithoutDate . action ( ) )
48
+ break
49
+ case CategoryType . PhotosWithoutDate :
50
+ dispatch ( FetchAlbumByDate . action ( ) )
51
+ break
52
+ case CategoryType . Recent :
53
+ dispatch ( FetchRecentlyAdded . action ( ) )
54
+ break
55
+ case CategoryType . Favourite :
56
+ dispatch ( FetchFavourites . action ( ) )
57
+ break
58
+ case CategoryType . Public :
59
+ dispatch ( FetchPublic . action ( ) )
60
+ break
61
+ case CategoryType . Hidden :
62
+ dispatch ( FetchHidden . action ( ) )
63
+ break
53
64
}
65
+ } , [ dispatch , category ] )
54
66
55
- let finalmap = photosResult . map ( item => {
56
- return {
57
- id : item . date ,
58
- title : item . date ,
59
- data : imageGridMapper ( item . items ) ,
60
- }
61
- } )
67
+ useEffect ( ( ) => {
68
+ dispatch ( FetchAlbumByDate . action ( ) )
69
+ // eslint-disable-next-line react-hooks/exhaustive-deps
70
+ } , [ ] )
62
71
63
- return finalmap
72
+ const renderButton = ( index , buttonCategory ) => {
73
+ return (
74
+ < Button
75
+ key = { index }
76
+ size = "xs"
77
+ variant = { category === buttonCategory ? 'solid' : 'outline' }
78
+ colorScheme = "dark"
79
+ onPress = { ( ) => setCategory ( buttonCategory ) }
80
+ >
81
+ { buttonCategory }
82
+ </ Button >
83
+ )
64
84
}
65
85
66
- const [ showPhotosByDate , setPhotosByDate ] = useState ( true )
67
-
68
- return (
69
- < >
70
- < TopBar />
71
- < View style = { [ Common . backgroundDefault , Layout . colCenter ] } >
72
- < HStack
73
- space = { {
74
- base : 3 ,
75
- md : 4 ,
76
- } }
77
- mx = { {
78
- base : 5 ,
79
- md : 0 ,
80
- } }
81
- my = { {
82
- base : 2 ,
83
- md : 0 ,
84
- } }
85
- style = { [ Common . backgroundDefault ] }
86
- >
87
- < Button
88
- size = "xs"
89
- variant = { showPhotosByDate ? 'solid' : 'outline' }
90
- colorScheme = "dark"
91
- onPress = { ( ) => setPhotosByDate ( true ) }
92
- >
93
- With Timestamp
94
- </ Button >
95
- < Button
96
- size = "xs"
97
- variant = { ! showPhotosByDate ? 'solid' : 'outline' }
98
- colorScheme = "dark"
99
- onPress = { ( ) => setPhotosByDate ( false ) }
100
- >
101
- Without Timestamp
102
- </ Button >
103
- </ HStack >
104
- </ View >
105
- < View style = { [ Layout . fill , Layout . colCenter , Common . backgroundDefault ] } >
106
- { showPhotosByDate ? (
86
+ const renderContent = ( ) => {
87
+ switch ( category ) {
88
+ case CategoryType . PhotosByDate :
89
+ return (
107
90
< TimelineList
108
- data = { photoMapper ( photosByDate ) }
109
- onRefresh = { handleAlbumWithDateRefresh }
91
+ data = { photosByDate }
92
+ onRefresh = { ( ) => dispatch ( FetchAlbumByDate . action ( ) ) }
110
93
refreshing = { albums . loading }
111
94
/>
112
- ) : (
95
+ )
96
+ case CategoryType . PhotosWithoutDate :
97
+ return (
113
98
< ImageGrid
114
99
data = { photosWithoutDate }
115
100
numColumns = { 3 }
116
101
displayError = { true }
117
- onRefresh = { handleAlbumWithoutDateRefresh }
102
+ onRefresh = { ( ) => dispatch ( FetchPhotosWithoutDate . action ( ) ) }
103
+ refreshing = { albums . loading }
104
+ />
105
+ )
106
+ case CategoryType . Recent :
107
+ return (
108
+ < ImageGrid
109
+ data = { albumRecentlyAdded ?. results }
110
+ numColumns = { 3 }
111
+ displayError = { true }
112
+ onRefresh = { ( ) => dispatch ( FetchAlbumByDate . action ( ) ) }
113
+ refreshing = { albums . loading }
114
+ />
115
+ )
116
+ case CategoryType . Favourite :
117
+ return (
118
+ < TimelineList
119
+ data = { albumFavourites }
120
+ onRefresh = { ( ) => dispatch ( FetchFavourites . action ( ) ) }
121
+ refreshing = { albums . loading }
122
+ />
123
+ )
124
+ case CategoryType . Public :
125
+ return (
126
+ < TimelineList
127
+ data = { albumPublic }
128
+ onRefresh = { ( ) => dispatch ( FetchPublic . action ( ) ) }
129
+ refreshing = { albums . loading }
130
+ />
131
+ )
132
+ case CategoryType . Hidden :
133
+ return (
134
+ < TimelineList
135
+ data = { albumHidden }
136
+ onRefresh = { ( ) => dispatch ( FetchHidden . action ( ) ) }
118
137
refreshing = { albums . loading }
119
138
/>
120
- ) }
139
+ )
140
+ }
141
+ }
142
+
143
+ return (
144
+ < >
145
+ < TopBar />
146
+ < View style = { [ Common . backgroundDefault , Layout . colCenter ] } >
147
+ < ScrollView horizontal = { true } showsHorizontalScrollIndicator = { false } >
148
+ < HStack
149
+ space = { { base : 3 , md : 4 } }
150
+ mx = { { base : 5 , md : 0 } }
151
+ my = { { base : 2 , md : 0 } }
152
+ style = { [ Common . backgroundDefault ] }
153
+ >
154
+ { Object . values ( CategoryType ) . map ( ( buttonCategory , index ) =>
155
+ renderButton ( index , buttonCategory ) ,
156
+ ) }
157
+ </ HStack >
158
+ </ ScrollView >
159
+ </ View >
160
+ < View style = { [ Layout . fill , Common . backgroundDefault ] } >
161
+ { renderContent ( ) }
121
162
</ View >
122
163
</ >
123
164
)
0 commit comments