Skip to content
This repository has been archived by the owner on Apr 19, 2024. It is now read-only.

Commit

Permalink
offline spaces-bar "+" should also link to the cloud
Browse files Browse the repository at this point in the history
  • Loading branch information
jacekkolasa committed Mar 22, 2020
1 parent fe901c1 commit 4b7b534
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { loadCss } from "utils/css-loader"
import { useDateTime } from "utils/date-time"
import { useListenToPostMessage } from "utils/post-message"
import { useSelector } from "store/redux-separate-context"
import { selectCloudBaseUrl } from "domains/global/selectors"
import { selectCloudBaseUrl, selectSignInUrl } from "domains/global/selectors"
import { Portals } from "domains/chart/components/portals"
import { useChartsMetadata } from "domains/dashboard/hooks/use-charts-metadata"
import { PrintModal } from "domains/dashboard/components/print-modal"
Expand Down Expand Up @@ -125,6 +125,7 @@ const App: React.FC = () => {
const [isOffline, setIsOffline] = useState(false)

useListenToFocusMessages()
const signInUrl = useSelector(selectSignInUrl)

// const dispatch = useDispatch()
// const [hasFocus] = useListenToPostMessage("has-focus", (newHasFocus) => {
Expand All @@ -140,6 +141,7 @@ const App: React.FC = () => {
isSignedIn={isSignedIn}
cloudBaseURL={cloudBaseURL}
enoughWaitingForIframe={enoughWaitingForIframe}
signInUrl={signInUrl}
/>
)}
{!isPrintMode && (
Expand Down
9 changes: 8 additions & 1 deletion src/components/spaces-bar/spaces-bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ interface Props {
cloudBaseURL: string
isSignedIn: boolean
enoughWaitingForIframe: boolean
signInUrl: string
}
export const SpacesBar = ({
cloudBaseURL,
isSignedIn,
enoughWaitingForIframe,
signInUrl,
}: Props) => (
<ListContainer>
{isSignedIn ? (
Expand All @@ -30,7 +32,12 @@ export const SpacesBar = ({
<SpacePlaceholder />
</SpacesList>
<SeparatedSection>
<Button icon="plus" onClick={() => {}} />
<Button
icon="plus"
onClick={() => {
window.location.href = signInUrl
}}
/>
</SeparatedSection>
</>
))}
Expand Down
11 changes: 11 additions & 0 deletions src/domains/global/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,17 @@ export const selectRegistry = createSelector(selectGlobal, prop("registry"))

export const selectCloudBaseUrl = createSelector(selectRegistry, prop("cloudBaseURL"))

export const selectSignInUrl = createSelector(
selectRegistry,
selectCloudBaseUrl,
(registry, cloudBaseURL) => {
const name = encodeURIComponent(registry.hostname)
const origin = encodeURIComponent(`${window.location.origin}/`)
// not adding redirect_url - it needs to always be based on newest href
return `${cloudBaseURL}/sign-in?id=${registry.machineGuid}&name=${name}&origin=${origin}`
},
)

export const selectIsFetchingHello = createSelector(selectRegistry, prop("isFetchingHello"))
export const selectIsUsingGlobalRegistry = createSelector(
selectRegistry,
Expand Down

0 comments on commit 4b7b534

Please sign in to comment.