11import * as React from "react" ;
22import { connect } from 'react-redux' ;
33import { dispatchShowLoginModal } from "../actions/dispatch" ;
4-
54import { SkillMapState } from "../store/reducer" ;
5+ import { lookupActivityProgress } from "../lib/skillMapUtils" ;
6+ import { head } from "request" ;
67
78interface OwnProps {
89 signedIn : boolean ;
10+ cloudStatus : pxt . cloud . CloudStatus ;
911}
1012
1113interface DispatchProps {
@@ -16,14 +18,14 @@ type CloudActionsProps = OwnProps & DispatchProps;
1618
1719export class CloudActionsImpl extends React . Component < CloudActionsProps > {
1820 render ( ) {
21+ const cloudStatus = pxt . cloud . cloudStatus [ this . props . cloudStatus ] ;
1922 return < div className = "cloud-action" >
2023 {
2124 this . props . signedIn
2225 ? < div className = "cloud-indicator" >
23- < div className = { " ui tiny cloudicon xicon cloud-saved-b" } title = { lf ( "Project saved to cloud" ) } tabIndex = { - 1 } > </ div >
24- { lf ( "Saved To Cloud!" ) }
26+ < div className = { ` ui tiny cloudicon xicon ${ cloudStatus . icon } ` } title = { cloudStatus . tooltip } tabIndex = { - 1 } > </ div >
27+ { cloudStatus . longStatus }
2528 </ div >
26-
2729 : < div className = "sign-in-button" onClick = { this . props . dispatchShowLoginModal } >
2830 { lf ( "Sign in to Save" ) }
2931 </ div >
@@ -33,13 +35,33 @@ export class CloudActionsImpl extends React.Component<CloudActionsProps> {
3335}
3436
3537function mapStateToProps ( state : SkillMapState , ownProps : any ) {
38+ const { user, pageSourceUrl, selectedItem } = state ;
39+
40+ let cloudStatus : pxt . cloud . CloudStatus = "none" ;
41+
42+ if ( selectedItem ?. activityId ) {
43+ const headerId = lookupActivityProgress (
44+ user ,
45+ pageSourceUrl ,
46+ selectedItem . mapId ,
47+ selectedItem . activityId ,
48+ ) ?. headerId ;
49+ if ( headerId ) {
50+ cloudStatus = state . cloudState && state . cloudState [ headerId ] || cloudStatus ;
51+ }
52+ } else {
53+ // For skillmap view, show "Saved to cloud"
54+ cloudStatus = "synced" ;
55+ }
56+
3657 return {
37- signedIn : state . auth . signedIn
58+ signedIn : state . auth . signedIn ,
59+ cloudStatus
3860 }
3961}
4062
4163const mapDispatchToProps = {
4264 dispatchShowLoginModal
4365}
4466
45- export const CloudActions = connect ( mapStateToProps , mapDispatchToProps ) ( CloudActionsImpl ) ;
67+ export const CloudActions = connect ( mapStateToProps , mapDispatchToProps ) ( CloudActionsImpl ) ;
0 commit comments