context = window
SessionsActions = @SessionsActions
LatencyActions = @LatencyActions
@FindSessionOpen = React.createClass({
mixins: [Reflux.listenTo(@AppStore, "onAppInit")
Reflux.listenTo(@SessionsStore, "onSessionsChanged")]
searched_ever: false
registeredInfiniteScroll: false
getInitialState: () ->
{active: false, sessions: [], searching: false, count: 0, currentPage: 0, end: false, participant_ids: []}
sessionResults: () ->
results = []
for session in @state.sessions
results.push(``)
results
help: () ->
if this.props.mode == 'open'
`
How This Page Works
This page will show only public jam sessions.
Most recent sessions are shown at the top.
This list of public sessions does not auto-update. You will have to push the REFRESH button to see new sessions.
`
else if this.props.mode == 'my'
`
How This Page Works
This page will show sessions tailored for you:
- sessions created by a friend (invite others to JamKazam)
- sessions for which you have an invitation
- sessions for which you have a RSVP
Sit Back and Relax
This page will automatically update when a friend creates a session, or you are invited to one.
So if your friend is creating a session soon, just sit tight and watch for sessions to show up!
`
else
`
How This Page Works
This page will show these scheduled sessions:
- public jam sessions
- sessions created by a friend (invite others to JamKazam)
- sessions for which you have an invitation
- sessions for which you have a RSVP
Reserve a spot
If you find a session you are interested in attending later, then click the RSVP icon to reserve your spot.
An email will be sent to the creator of the session, and they can then approve your request.
Schedule your Own
Don't see a session you like? You can schedule your own session for others to RSVP to at the create session screen. You will receive emails when others RSVP.
`
refresh: () ->
if @state.searching
return
SessionsActions.clearSessions.trigger(@props.mode, @query())
render: () ->
results = @sessionResults()
className = "content-body-scroller sessions-for-open"
if(@props.active)
className = className + " active"
firstTime = null
if results.length == 0
if @state.searching
results = `| ... Searching ... |
`
else
# help = @help()
results = `| None Found |
`
if @state.end && results.length > 5
results.push(`| End of Search Results |
`)
help = @help()
refreshButtonClasses = "button-grey btn-refresh"
if @state.searching
refreshButtonClasses = refreshButtonClasses += " disabled"
`
| SESSION |
MUSICIANS |
ACTIONS |
{results}
{help}
`
query: () ->
$root = $(this.getDOMNode())
keyword = $root.find('input.session-keyword-srch').val()
if keyword == ''
keyword = undefined
query =
keyword: keyword
query
componentDidMount: () ->
@EVENTS = context.JK.EVENTS
@rest = context.JK.Rest()
@logger = context.JK.logger
componentDidUpdate: (prevProps, prevState) ->
if !@props.screenActive && prevProps.screenActive
@searched_ever = false
if @props.screenActive && @props.active && !@searched_ever
SessionsActions.updateSessions.trigger(@props.mode)
@searched_ever = true
#if @props.active && !prevProps.active && !@searched_ever
$root = $(this.getDOMNode())
$scroller = $root
if !@registeredInfiniteScroll
@registerInfiniteScroll($scroller)
registerInfiniteScroll: ($scroller) ->
@registeredInfiniteScroll = true
$scroller.off('scroll')
$scroller.on('scroll', () =>
# be sure to not fire off many refreshes when user hits the bottom
return if @state.searching
return if @state.end
if $scroller.scrollTop() + $scroller.innerHeight() + 400 >= $scroller[0].scrollHeight
SessionsActions.updateSessions.trigger(@props.mode, @query())
)
inviteFriends:() ->
JK.InvitationDialogInstance.showEmailDialog();
onAppInit: (@app) ->
return
onSessionsChanged: (sessionsChanged) ->
if sessionsChanged.type == @props.mode
for session in sessionsChanged.sessions
if session.active_music_session?
for participant in session.active_music_session.participants
@state.participant_ids.push(participant.user.id) unless _.contains(@state.participant_ids, participant.user.id)
for rsvp in session.approved_rsvps
@state.participant_ids.push(rsvp.id) unless _.contains(@state.participant_ids, rsvp.id)
LatencyActions.resolve(_.unique(@state.participant_ids))
@setState(sessionsChanged)
})