Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug login flow worker errors #274

Merged
merged 6 commits into from
Nov 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/wise-waves-drop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'mexit-webapp': patch
---

Fix analysis worker crashes, theme init, user fetch
13 changes: 5 additions & 8 deletions apps/webapp/src/Components/Buttons/Buttons.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
import React from 'react'

import { Icon } from '@iconify/react'
import { useTheme } from 'styled-components'

import { IS_DEV, MEXIT_FRONTEND_AUTH_BASE } from '@mexit/core'
import { AsyncButton, AsyncButtonProps, GoogleAuthButton, Loading } from '@mexit/shared'
import { MEXIT_FRONTEND_AUTH_BASE } from '@mexit/core'
import { GoogleAuthButton } from '@mexit/shared'

import { useAuthentication, useAuthStore } from '../../Stores/useAuth'
import config from '../../config'

export interface GoogleLoginButtonProps {
text: string
}

export const GoogleLoginButton = ({ text }: GoogleLoginButtonProps) => {
const { loginViaGoogle } = useAuthentication()
// const { loginViaGoogle } = useAuthentication()
const baseAuthURL = 'https://workduck.auth.us-east-1.amazoncognito.com/oauth2/authorize'
const searchParams = new URLSearchParams({
identity_provider: 'Google',
Expand All @@ -29,10 +25,11 @@ export const GoogleLoginButton = ({ text }: GoogleLoginButtonProps) => {

const authURL = URLObject.toString()

const openUrl = (url) => {
const openUrl = (url: string) => {
window.open(url, '_self')
// if (newWindow) newWindow.opener = null
}

return (
<GoogleAuthButton
large={true}
Expand Down
2 changes: 1 addition & 1 deletion apps/webapp/src/Components/Editor/Rename/NodeRename.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const NodeRenameOnlyTitle = () => {

const to = useRenameStore((store) => store.to)
const ilinks = useDataStore((store) => store.ilinks)
const nodeTitle = useAnalysisStore((state) => state.analysis.title)
const nodeTitle = useAnalysisStore((state) => state.analysis?.title)

const { push } = useNavigation()
const setMockRefactored = useRenameStore((store) => store.setMockRefactored)
Expand Down
4 changes: 2 additions & 2 deletions apps/webapp/src/Components/Editor/TagsRelated.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ export const TagsRelatedTiny = ({ nodeid }: TagsRelated) => {
*/
export const TagsRelatedSuggestions = ({ nodeid, fromAnalysis }: TagsRelated) => {
const { getRelatedNodes } = useTags()
const tagsCache = useDataStore((state) => state.tagsCache)
const analysisTags = useAnalysisStore((state) => state.analysis.tags)
const tagsCache = useDataStore((state) => state?.tagsCache)
const analysisTags = useAnalysisStore((state) => state?.analysis?.tags)
const [relNodes, setRelNodes] = useState<string[]>([])
const { getPathFromNodeid } = useLinks()

Expand Down
2 changes: 1 addition & 1 deletion apps/webapp/src/Components/Infobar/Outline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ interface OutlineProps {
}

const Outline = ({ staticOutline, editorId }: OutlineProps) => {
const storeOutline = useAnalysisStore((state) => state.analysis.outline)
const storeOutline = useAnalysisStore((state) => state.analysis?.outline)

const outline = staticOutline ? staticOutline : storeOutline

Expand Down
47 changes: 12 additions & 35 deletions apps/webapp/src/Components/Sidebar/Tree.tsx
Original file line number Diff line number Diff line change
@@ -1,38 +1,32 @@
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react'

import {
default as AtlaskitTree,
ItemId,
mutateTree,
RenderItemParams,
TreeData,
TreeDestinationPosition,
TreeItem,
TreeSourcePosition
default as AtlaskitTree,
ItemId,
mutateTree,
RenderItemParams,
TreeData,
TreeDestinationPosition,
TreeItem,
TreeSourcePosition
} from '@atlaskit/tree'
import fileList2Line from '@iconify/icons-ri/file-list-2-line'
import { Icon } from '@iconify/react'
import Tippy, { useSingleton } from '@tippyjs/react'
import { useLocation, useMatch } from 'react-router-dom'

import { tinykeys } from '@workduck-io/tinykeys'

import { mog, SEPARATOR, getNameFromPath } from '@mexit/core'
import { getNameFromPath, mog, SEPARATOR } from '@mexit/core'
import {
StyledTreeItemSwitcher,
TooltipContentWrapper,
TooltipCount,
ItemTitle,
StyledTreeSwitcher,
isOnEditableElement
isOnEditableElement, StyledTreeItemSwitcher, StyledTreeSwitcher, TooltipContentWrapper,
TooltipCount
} from '@mexit/shared'

import { getNextWrappingIndex } from '../../Editor/Utils/getNextWrappingIndex'
import { useNavigation } from '../../Hooks/useNavigation'
import { useRefactor } from '../../Hooks/useRefactor'
import { useRouting, ROUTE_PATHS, NavigationType } from '../../Hooks/useRouting'
import { NavigationType, ROUTE_PATHS, useRouting } from '../../Hooks/useRouting'
import { getTreeFromLinks } from '../../Hooks/useTreeFromLinks'
import { useAnalysisStore } from '../../Stores/useAnalysis'
import { useDataStore } from '../../Stores/useDataStore'
import { useEditorStore } from '../../Stores/useEditorStore'
import { useTreeStore } from '../../Stores/useTreeStore'
Expand Down Expand Up @@ -82,23 +76,6 @@ export const TooltipContent = ({ item }: { item: TreeItem }) => {
)
}

const ItemTitleWithAnalysis = ({ item }: { item: TreeItem }) => {
const anal = useAnalysisStore((state) => state.analysis)
const title =
anal.nodeid && anal.nodeid === item.data.nodeid && anal.title !== undefined && anal.title !== ''
? anal.title
: item.data
? item.data.title
: 'NoTitle'

return (
<ItemTitle>
<Icon icon={item.data.mex_icon ?? fileList2Line} />
<span>{title}</span>
</ItemTitle>
)
}

interface TreeProps {
initTree: TreeData
selectedItemId?: string
Expand Down
4 changes: 2 additions & 2 deletions apps/webapp/src/Components/Sidebar/TreeItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ export const TooltipContent = ({ item }: { item: TreeItem }) => {
const ItemTitleWithAnalysis = ({ item }: { item: TreeItem }) => {
const anal = useAnalysisStore((state) => state.analysis)
const title =
anal.nodeid && anal.nodeid === item.data.nodeid && anal.title !== undefined && anal.title !== ''
? anal.title
anal?.nodeid && anal?.nodeid === item.data.nodeid && anal?.title !== undefined && anal?.title !== ''
? anal?.title
: item.data
? item.data.title
: 'NoTitle'
Expand Down
17 changes: 15 additions & 2 deletions apps/webapp/src/Data/links.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react'
import React, { useMemo } from 'react'

import fileDocument from '@iconify/icons-gg/file-document'
import appsLine from '@iconify/icons-ri/apps-line'
Expand All @@ -13,6 +13,8 @@ import { useViewStore } from '../Hooks/useTaskViews'
import { useEditorStore } from '../Stores/useEditorStore'
import { useHelpStore } from '../Stores/useHelpStore'
import { NavLinkData } from '../Types/Nav'
import { useDataStore } from '../Stores/useDataStore'
import { InitialNode, mog } from '@mexit/core'

/*
Sidebar links are defined here
Expand All @@ -25,8 +27,19 @@ export const GetIcon = (icon: any): React.ReactNode => <Icon icon={icon} />
const useNavlinks = () => {
const shortcuts = useHelpStore((store) => store.shortcuts)

const baseNodeId = useDataStore((store) => store.baseNodeId)
const match = useMatch(`${ROUTE_PATHS.node}/:nodeid`)
const nodeid = match?.params?.nodeid || useEditorStore.getState().node.nodeid
const nodeid = useMemo(() => {
const editorNode = useEditorStore.getState().node
// mog('match', { match, baseNodeId, editorNode })
if (match?.params?.nodeid) {
return match.params.nodeid
} else if (editorNode && editorNode.nodeid !== InitialNode.nodeid) {
return editorNode.nodeid
} else if (baseNodeId) {
return baseNodeId
}
}, [match, baseNodeId])

// const count = useMemo(() => getLinkCount(), [reminders, ilinks, archive, tasks])

Expand Down
6 changes: 6 additions & 0 deletions apps/webapp/src/Hooks/API/useUserAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { useAuthStore } from '../../Stores/useAuth'
import { useUserCacheStore } from '../../Stores/useUserCacheStore'
import { useUserPreferenceStore } from '../../Stores/userPreferenceStore'
import { useAPIHeaders } from './useAPIHeaders'
import { USER_ID_REGEX } from '../../Utils/constants'

export interface TempUser {
email: string
Expand Down Expand Up @@ -70,9 +71,14 @@ export const useUserService = () => {
}

const getUserDetailsUserId = async (userID: string): Promise<TempUserUserID> => {
// Get from cache
const user = getUser({ userID })
if (user) return user

// Check if the userid is of valid format
const match = userID.match(USER_ID_REGEX)
if (!match) return { userID }

try {
return await client.get(apiURLs.user.getFromUserId(userID)).then((resp: any) => {
mog('Response', { data: resp.data })
Expand Down
4 changes: 2 additions & 2 deletions apps/webapp/src/Hooks/useLoad.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ const useLoad = () => {
// const { saveQ } = useSaveQ()

const saveNodeName = (nodeId: string, title?: string) => {
if (nodeId !== useAnalysisStore.getState().analysis.nodeid) return
const draftNodeTitle = title ?? useAnalysisStore.getState().analysis.title
if (nodeId !== useAnalysisStore.getState().analysis?.nodeid) return
const draftNodeTitle = title ?? useAnalysisStore.getState().analysis?.title
mog('SAVE NODE NAME', { draftNodeTitle })
if (!draftNodeTitle) return

Expand Down
4 changes: 2 additions & 2 deletions apps/webapp/src/Hooks/useSaveNodeName.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ export const useSaveNodeName = () => {
const { execRefactorAsync } = useRefactor()

const saveNodeName = (nodeId: string, title?: string) => {
if (nodeId !== useAnalysisStore.getState().analysis.nodeid) return
const draftNodeTitle = title ?? useAnalysisStore.getState().analysis.title
if (nodeId !== useAnalysisStore.getState().analysis?.nodeid) return
const draftNodeTitle = title ?? useAnalysisStore.getState().analysis?.title
if (!draftNodeTitle) return

const node = getLinkFromNodeIdHookless(nodeId)
Expand Down
2 changes: 1 addition & 1 deletion apps/webapp/src/Hooks/useTags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const useTags = () => {
if (!fromAnalysis) {
return _getTags(nodeid, tagsCache)
}
const analTags = useAnalysisStore.getState().analysis.tags
const analTags = useAnalysisStore.getState().analysis?.tags || []
return analTags
}

Expand Down
7 changes: 5 additions & 2 deletions apps/webapp/src/Stores/useAnalysis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useEffect } from 'react'

import create from 'zustand'

import { TodoType, checkIfUntitledDraftNode, getParentNodePath } from '@mexit/core'
import { TodoType, checkIfUntitledDraftNode, getParentNodePath, mog } from '@mexit/core'

import { useBufferStore, useEditorBuffer } from '../Hooks/useEditorBuffer'
import { useLinks } from '../Hooks/useLinks'
Expand Down Expand Up @@ -51,7 +51,10 @@ export const useAnalysisTodoAutoUpdate = () => {
const node = useEditorStore((state) => state.node)

useEffect(() => {
const { editorTodos, nodeid } = useAnalysisStore.getState().analysis
const analysis = useAnalysisStore.getState().analysis
const nodeid = analysis?.nodeid
const editorTodos = analysis?.editorTodos ?? []
// mog('useAnalysisTodoAutoUpdate', { editorTodos, nodeid })
updateNodeTodos(nodeid, editorTodos)
}, [analysis, node])
}
Expand Down
3 changes: 3 additions & 0 deletions apps/webapp/src/Utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ export const EMAIL_REG =

export const PASSWORD = /^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[\^$*.\[\]{}\(\)?\-“!@#%&\/,><\’:;|_~`])\S{8,99}$/

// User id 833cae89-dd14-445e-8f40-8f8fde047665
export const USER_ID_REGEX = /^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/

export const MultiEmailValidate = (emailsRaw: string): boolean => {
const isValid = getWrongEmails(emailsRaw).length === 0
return isValid
Expand Down
7 changes: 4 additions & 3 deletions libs/core/src/Utils/treeUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@ export const sampleFlatTree = [
'com',
'com.workduck'
]

export const getInitialNode = (): NodeProperties => ({
export const InitialNode = {
title: '__loading__',
id: '__loading__',
path: '__loading__',
nodeid: '__null__',
namespace: '__null__'
})
}

export const getInitialNode = (): NodeProperties => InitialNode

export const getNodeIcon = (path: string) => {
if (isElder(path, BASE_DRAFT_PATH)) {
Expand Down
2 changes: 1 addition & 1 deletion libs/shared/src/Stores/preferenceStoreConstructor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export const mergeUserPreferences = (local: UserPreferences, remote: UserPrefere
// The local notes which do not exist in the remote notes will be left alone
lastOpenedNotes: { ...local.lastOpenedNotes, ...mergedLastOpenedNotes },
lastUsedSnippets: { ...local.lastUsedSnippets, ...mergedLastUsedSnippets },
theme: local.theme,
theme: remote.theme ?? local.theme,
smartCaptureExcludedFields: local.smartCaptureExcludedFields
}
}