Skip to content

Commit

Permalink
Manual Refresh Option On Splash Screen (#401)
Browse files Browse the repository at this point in the history
  • Loading branch information
dineshsingh1 authored Mar 21, 2023
1 parent 860dca9 commit d9d5b31
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 14 deletions.
5 changes: 5 additions & 0 deletions .changeset/orange-rings-film.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'mexit-webapp': patch
---

Manual Refresh on Splash Screen
56 changes: 51 additions & 5 deletions apps/webapp/src/Components/SplashScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import Lottie from 'lottie-react'
import styled from 'styled-components'

import { hintsData } from '@mexit/core'
import { fadeIn, Hints } from '@mexit/shared'
import { hintsData, useAppStore } from '@mexit/core'
import { BodyFont, fadeIn, Group, Hints } from '@mexit/shared'

import { loader } from '../Data/loader'

Expand All @@ -26,6 +26,36 @@ const OverlayLoader = styled.div`
}
`

const RefreshLink = styled.span`
font-weight: bolder;
border-radius: ${({ theme }) => theme.spacing.tiny};
:hover {
transition: background 0.2s ease;
cursor: pointer;
color: ${({ theme }) => theme.tokens.colors.primary.hover};
background: ${({ theme }) => theme.tokens.surfaces.s[3]};
}
padding: ${({ theme }) => theme.spacing.tiny};
color: ${({ theme }) => theme.tokens.colors.primary.default};
`

const RefreshGroup = styled(Group)`
display: flex;
${BodyFont}
animation: ${fadeIn} 0.5s;
color: ${({ theme }) => theme.tokens.text.fade};
padding: ${({ theme }) => theme.spacing.small};
`

const CenteredGroup = styled.section`
display: flex;
align-items: center;
flex-direction: column;
gap: ${({ theme }) => theme.spacing.medium};
`

const VerticallyCenter = styled.div`
display: flex;
position: relative;
Expand All @@ -50,15 +80,31 @@ type SplashScreenProps = {
}

const SplashScreen: React.FC<SplashScreenProps> = ({ showHints = false }) => {
const manualReload = useAppStore((s) => s.manualReload)
const setManualReload = useAppStore((s) => s.setManualReload)

const onManualReload = () => {
setManualReload(false)
window.location.reload()
}

return (
<OverlayLoader>
<VerticallyCenter>
<Lottie autoplay loop animationData={loader} />
</VerticallyCenter>
{showHints && (
<HintsContainer>
<Hints hints={hintsData} show />
</HintsContainer>
<CenteredGroup>
{manualReload && (
<RefreshGroup>
Taking too long...
<RefreshLink onClick={onManualReload}>Refresh</RefreshLink>
</RefreshGroup>
)}
<HintsContainer>
<Hints hints={hintsData} show />
</HintsContainer>
</CenteredGroup>
)}
</OverlayLoader>
)
Expand Down
9 changes: 7 additions & 2 deletions apps/webapp/src/Hooks/useInitLoader.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useEffect } from 'react'
import toast from 'react-hot-toast'

import { API, AppInitStatus, mog, runBatch, useLinkStore } from '@mexit/core'
import { API, AppInitStatus, mog, runBatch, useAppStore, useLinkStore, withTimeout } from '@mexit/core'

import { useAuthentication, useAuthStore } from '../Stores/useAuth'
import { useContentStore } from '../Stores/useContentStore'
Expand All @@ -25,6 +25,7 @@ import { useUserPreferences } from './useSyncUserPreferences'
import { useURLsAPI } from './useURLs'

export const useInitLoader = () => {
const setManualReload = useAppStore((store) => store.setManualReload)
const initalizeApp = useAuthStore((store) => store.appInitStatus)

const setIsUserAuthenticated = useAuthStore((store) => store.setIsUserAuthenticated)
Expand Down Expand Up @@ -122,7 +123,11 @@ export const useInitLoader = () => {

if (initalizeApp === AppInitStatus.RUNNING) {
backgroundFetch()
await fetchAll()
try {
await withTimeout(fetchAll(), 60 * 1000, 'Oops, something went wrong while fetching workspace')
} catch (err) {
setManualReload(true)
}
}
})
.catch((error) => {
Expand Down
4 changes: 1 addition & 3 deletions apps/webapp/src/Hooks/useSearch.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { ELEMENT_MENTION } from '@udecode/plate'

import { Indexes, ISearchQuery, IUpdateDoc, SearchX } from '@workduck-io/mex-search'
import { Indexes, ISearchQuery, IUpdateDoc } from '@workduck-io/mex-search'

import {
ELEMENT_ILINK,
Expand All @@ -27,8 +27,6 @@ import {

import { useLinks } from './useLinks'

export const searchX = new SearchX()

export const useSearchExtra = () => {
const ilinks = useDataStore((s) => s.ilinks)
const mentionable = useMentionStore((s) => s.mentionable)
Expand Down
7 changes: 4 additions & 3 deletions apps/webapp/src/Stores/useAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import { toast } from 'react-hot-toast'
import create from 'zustand'
import { persist } from 'zustand/middleware'

import { useAuth, useAuthStore as useDwindleAuthStore } from '@workduck-io/dwindle'
import { useAuth } from '@workduck-io/dwindle'
import { UserCred } from '@workduck-io/dwindle/lib/esm/AuthStore/useAuthStore'

import { API, authStoreConstructor, AuthStoreState, mog, RegisterFormData } from '@mexit/core'
import { API, authStoreConstructor, AuthStoreState, mog, RegisterFormData, useAppStore } from '@mexit/core'

import { getEmailStart } from '../Utils/constants'
import { terminateAllWorkers } from '../Workers/controller'
Expand Down Expand Up @@ -38,7 +38,6 @@ type LoginResult = { loginData: UserCred; loginStatus: string }
export const useAuthentication = () => {
const setUnAuthenticated = useAuthStore((store) => store.setUnAuthenticated)
const { signIn, signOut, signUp, verifySignUp, googleSignIn } = useAuth()
const clearRequestsCacheFromDwindle = useDwindleAuthStore((s) => s.clearStore)

const setRegistered = useAuthStore((store) => store.setRegistered)
const [sensitiveData, setSensitiveData] = useState<RegisterFormData | undefined>()
Expand All @@ -52,6 +51,7 @@ export const useAuthentication = () => {
const clearRecents = useRecentsStore((s) => s.clear)
const clearMentions = useMentionStore((m) => m.reset)
const clearComments = useCommentStore((s) => s.clear)
const clearAppStore = useAppStore((s) => s.clear)
const clearReactions = useReactionStore((s) => s.clear)
const clearViews = useViewStore((s) => s.clear)
const clearRoutesInformation = useRouteStore((s) => s.clear)
Expand Down Expand Up @@ -121,6 +121,7 @@ export const useAuthentication = () => {
clearReminders()
clearSnippets()
resetShortcuts()
clearAppStore()
clearTodos()
clearViews()
clearUsersCache()
Expand Down
11 changes: 10 additions & 1 deletion libs/core/src/Stores/useAppStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ interface AppStoreType {
setFeatureFlags: (featureFlags: FeatureFlagsType) => void
version?: string
setVersion: (version: string) => void
manualReload: boolean
setManualReload: (manualReload: boolean) => void
clear: () => void
}

const defaultFeatureFlags: FeatureFlagsType = {
Expand All @@ -29,7 +32,13 @@ export const useAppStore = create<AppStoreType>(
version: undefined,
setVersion: (version: string) => {
set({ version: version })
}
},
clear: () =>
set({
manualReload: false
}),
manualReload: false,
setManualReload: (manualReload: boolean) => set({ manualReload })
}),
{
name: 'mexit-version-webapp',
Expand Down

0 comments on commit d9d5b31

Please sign in to comment.