             </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()

        # projectPreferences.update "preferences": {}
        # projectPreferences.save()
        if projectPreferences.preferences.minicourses?
          if projectPreferences.preferences.minicourses.opt_out["id_#{@props.minicourse.id}"] # user is restarting via mini-course button
            projectPreferences.update defaultPreferences
            projectPreferences.save()
              .then =>
                slideToStart = projectPreferences.preferences.minicourses.slide_last_seen["id_#{@props.minicourse.id}"]
                @setState {slideToStart: slideToStart, projectPreferences: projectPreferences}
          else if projectPreferences.preferences.minicourses.slide_last_seen["id_#{@props.minicourse.id}"]?
            slideToStart = projectPreferences.preferences.minicourses.slide_last_seen["id_#{@props.minicourse.id}"]
            @setState {slideToStart: slideToStart, projectPreferences: projectPreferences}
        else

    slideToStart: 0
    projectPreferences: null

  componentWillMount: ->
    defaultPreferences = { "preferences.minicourses.opt_out.id_#{@props.minicourse.id}": false, "preferences.minicourses.slide_last_seen.id_#{@props.minicourse.id}": 0 }

    if @props.user?
