             </p>}
         </MediaCard>}
     </StepThrough>
+
+  handleProjectPreferencesOnUnmount: ->
+    if @state.projectPreferences.preferences.minicourses.slide_last_seen["id_#{@props.minicourse.id}"] < @props.minicourse.steps.length
+      nextSlideIndex = @state.projectPreferences.preferences.minicourses.slide_last_seen["id_#{@props.minicourse.id}"] + 1
+      @state.projectPreferences.update "preferences.minicourses.slide_last_seen.id_#{@props.minicourse.id}": nextSlideIndex
+      @state.projectPreferences.save()
+
+    if @state.slideToStart is @props.minicourse.steps.length - 1
+      now = new Date().toISOString()
+      completedThisSession[@props.minicourse.id] = now
+
+      @state.projectPreferences.update "preferences.minicourses.completed_at.id_#{@props.minicourse.id}": now
+      @state.projectPreferences.save()

apiClient = require 'panoptes-client/lib/api-client'

completedThisSession = {}
window?.tutorialsCompletedThisSession = completedThisSession

module.exports = React.createClass
  displayName: 'MiniCourse'

  #     content: React.PropTypes.string

  getDefaultProps: ->
    media: {}
    minicourse: {}
    project: {}
