Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
thalia
ThaliApp
Commits
32429070
Commit
32429070
authored
Apr 19, 2017
by
AuckeBos
Browse files
Using custom api function eventlist for retrieving calendar
parent
3248ba41
Changes
4
Hide whitespace changes
Inline
Side-by-side
app/actions/calendar.js
View file @
32429070
import
{
AsyncStorage
}
from
'
react-native
'
;
import
*
as
types
from
'
./actionTypes
'
;
const
TOKENKEY
=
'
@MyStore:token
'
;
export
function
calendarRetrieved
(
eventList
)
{
return
{
type
:
types
.
CALENDARRETREIVED
,
...
...
@@ -13,23 +16,36 @@ export function calendarNotRetrieved() {
};
}
export
function
retrieveCalendar
(){
return
(
dispatch
)
=>
{
let
start
=
new
Date
().
toISOString
().
substring
(
0
,
10
);
let
end
=
new
Date
();
end
.
setMonth
(
end
.
getMonth
()
+
6
);
end
=
end
.
toISOString
().
substring
(
0
,
10
);
return
fetch
(
'
http://localhost:8000/api/events?start=
'
+
start
+
'
&end=
'
+
end
)
.
then
(
response
=>
response
.
json
())
export
function
retrieveCalendar
()
{
return
(
dispatch
)
=>
{
AsyncStorage
.
getItem
(
TOKENKEY
)
.
then
(
(
responseJson
)
=>
{
console
.
log
(
responseJson
);
return
dispatch
(
calendarRetrieved
(
responseJson
));
})
.
catch
((
error
)
=>
{
console
.
log
(
error
);
dispatch
(
calendarNotRetrieved
());
})
};
}
\ No newline at end of file
(
token
)
=>
{
let
start
=
new
Date
().
toISOString
().
substring
(
0
,
10
);
let
end
=
new
Date
();
end
.
setMonth
(
end
.
getMonth
()
+
6
);
end
=
end
.
toISOString
().
substring
(
0
,
10
);
const
data
=
{
method
:
'
GET
'
,
headers
:
{
Accept
:
'
application/json
'
,
'
Content-Type
'
:
'
application/json
'
,
'
Authorization
'
:
'
Token
'
+
token
,
},
};
return
fetch
(
'
http://localhost:8000/api/events/eventlist/?start=
'
+
start
+
'
&end=
'
+
end
,
data
)
.
then
(
response
=>
response
.
json
())
.
then
(
(
responseJson
)
=>
{
console
.
log
(
responseJson
);
return
dispatch
(
calendarRetrieved
(
responseJson
));
})
.
catch
((
error
)
=>
{
console
.
log
(
error
);
dispatch
(
calendarNotRetrieved
());
})
}
);
};
}
\ No newline at end of file
app/actions/eventCard.js
View file @
32429070
import
*
as
types
from
"
./actionTypes
"
;
export
function
openEvent
(
eventId
)
{
return
null
;
console
.
log
(
"
opening event
"
);
return
{
};
}
app/components/Calendar.js
View file @
32429070
...
...
@@ -2,7 +2,7 @@ import React from 'react';
import
{
Text
,
View
,
ListView
}
from
'
react-native
'
;
import
{
connect
}
from
'
react-redux
'
;
import
*
as
actions
from
'
../actions/calendar
'
;
import
Event
from
'
./EventCard
'
;
import
Event
Card
from
'
./EventCard
'
;
const
Calendar
=
(
props
)
=>
{
if
(
!
props
.
calendarFetched
)
{
...
...
@@ -16,12 +16,15 @@ const Calendar = (props) => {
)
}
else
{
console
.
log
(
'
calendar is retrieved
'
);
console
.
log
(
props
);
const
ds
=
new
ListView
.
DataSource
({
rowHasChanged
:
(
r1
,
r2
)
=>
r1
!==
r2
});
let
events
=
[];
for
(
let
i
=
0
;
i
<
props
.
eventList
.
length
;
i
++
)
{
events
.
push
(
Event
(
props
.
eventList
[
i
]));
console
.
log
(
props
.
eventList
[
i
]);
events
.
push
(
<
EventCard
event
=
{
props
.
eventList
[
i
]}
/>
)
;
}
console
.
log
(
events
);
const
dataSource
=
ds
.
cloneWithRows
(
events
);
return
(
<
View
>
...
...
app/components/EventCard.js
View file @
32429070
import
React
from
'
react
'
;
import
{
View
,
Text
}
from
'
react-native
'
;
import
{
View
,
Text
,
Button
}
from
'
react-native
'
;
import
{
connect
}
from
'
react-redux
'
;
import
{
openEvent
}
from
'
../actions/eventCard
'
;
import
*
as
actions
from
'
../actions/eventCard
'
;
const
Event
=
(
event
)
=>
const
Event
Card
=
(
props
)
=>
<
View
>
<
Text
>
<
b
>
{
event
.
title
}
<
/b> </
Text
>
<
Text
>
{
new
Date
(
event
.
start
).
toISOString
().
substring
(
0
,
10
)}
<
/Text
>
<
i
>
{
event
.
description
}
<
/i
>
<
Text
>
onPress
=
{()
=>
actions
.
openEvent
(
props
.
event
.
id
)}
<
b
>
{
props
.
event
.
title
}
<
/b> </
Text
>
<
Text
>
{
new
Date
(
props
.
event
.
start
).
toISOString
().
substring
(
0
,
10
)}
<
/Text
>
<
i
>
{
props
.
event
.
description
}
<
/i
>
<
Text
>-----------------------------------------<
/Text
>
onPress
=
{()
=>
openEvent
(
event
.
id
)}
<
/View
>
;
Event
.
propTypes
=
{
Event
Card
.
propTypes
=
{
openEvent
:
React
.
PropTypes
.
func
.
isRequired
,
event
:
React
.
PropTypes
.
object
.
isRequired
,
};
const
mapDispatchToProps
=
dispatch
=>
({
openEvent
:
()
=>
dispatch
(
openEvent
()),
openEvent
:
(
event_id
)
=>
dispatch
(
actions
.
openEvent
(
event_id
)),
});
export
default
connect
(()
=>
({}),
mapDispatchToProps
)(
Event
);
export
default
Event
;
\ No newline at end of file
export
default
connect
(()
=>
({}),
mapDispatchToProps
)(
EventCard
);
\ No newline at end of file
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment