Skip to content

Commit 44b7825

Browse files
Mukul Mehtadineshsingh1
Mukul Mehta
andauthored
Flexsearch and Request Handler Fixes; Update Search in Extension (#404)
#404 * Remove .data from response in extension requestHandler * Update mex-search to 0.0.8 for flexsearch fix * IDBStorage to Localstorage webapp auth getter * Update search * UI changes * Add changeset * Remove logs --------- Co-authored-by: Dinesh Singh <[email protected]>
1 parent 24b58b5 commit 44b7825

File tree

21 files changed

+1764
-1749
lines changed

21 files changed

+1764
-1749
lines changed

.changeset/light-pans-clap.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'mexit': patch
3+
'mexit-webapp': patch
4+
---
5+
6+
Request Handler fixes; Revert flexsearh to 0.7.22; UI and Search Fixes

apps/extension/src/Components/Action/styled.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export const StyledAction = styled.div<{ $active?: boolean }>`
1717
${({ $active }) =>
1818
$active &&
1919
css`
20-
background: ${({ theme }) => theme.tokens.surfaces.s[1]};
20+
background: ${({ theme }) => theme.tokens.surfaces.s[3]};
2121
`}
2222
`
2323

apps/extension/src/Components/Sidebar/SnippetsInfoBar.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -119,14 +119,14 @@ export const SnippetsInfoBar = () => {
119119
setSearchedSnippets(snippets)
120120
} else {
121121
const searched = res
122-
.map((r) => {
122+
?.map((r) => {
123123
const snippet = snippets.find((snippet) => snippet.id === r.parent)
124124

125125
return snippet
126126
})
127-
.filter((s) => s !== undefined) as Snippet[]
127+
?.filter((s) => s !== undefined) as Snippet[]
128128

129-
setSearchedSnippets(searched)
129+
setSearchedSnippets(searched ?? [])
130130
}
131131
}
132132

apps/extension/src/Components/Sidebar/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const ExtInfoBarItems = () => {
2626
return (
2727
<Tabs
2828
visible={true}
29-
openedTab={infobar.mode}
29+
openedTab={infobar.mode ?? 'context'}
3030
root={getElementById('ext-side-nav')}
3131
onChange={(tab) => {
3232
setInfobarMode(tab as ExtInfobarMode)

apps/extension/src/Hooks/useSearch.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ import {
2323
useContentStore,
2424
useDataStore,
2525
useLinkStore,
26-
useMentionStore
26+
useMentionStore,
27+
useSnippetStore
2728
} from '@mexit/core'
2829
import { useQuery } from '@mexit/shared'
2930

@@ -33,7 +34,6 @@ import { getListItemFromNode, getListItemFromSnippet } from '../Utils/helper'
3334

3435
import { useLinks } from './useLinks'
3536
import { useQuickLinks } from './useQuickLinks'
36-
import { useSnippets } from './useSnippets'
3737

3838
export const useSearchExtra = () => {
3939
const ilinks = useDataStore((s) => s.ilinks)
@@ -70,7 +70,6 @@ export const useSearchExtra = () => {
7070

7171
export const useSearch = () => {
7272
const { getQuickLinks } = useQuickLinks()
73-
const { getSnippet } = useSnippets()
7473
const { generateSearchQuery } = useQuery()
7574
const setDocUpdated = useContentStore((store) => store.setDocUpdated)
7675

@@ -111,8 +110,9 @@ export const useSearch = () => {
111110
})
112111

113112
if (!selection) {
113+
const snippets = useSnippetStore.getState().snippets
114114
snippetItems?.forEach((snippet) => {
115-
const snip = getSnippet(snippet.parent)
115+
const snip = snippets?.[snippet?.parent]
116116
if (snip) {
117117
const item = getListItemFromSnippet(snip, actionType)
118118
localNodes.push(item)

apps/extension/src/Hooks/useSnippets.tsx

+4-6
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,15 @@ import {
1010
Snippet,
1111
SnippetID,
1212
useAuthStore,
13-
useContentStore,
1413
useDataStore,
1514
useDescriptionStore,
1615
useMetadataStore,
1716
useSnippetStore
1817
} from '@mexit/core'
1918
import { useSlashCommands } from '@mexit/shared'
2019

21-
import { wUpdateDoc } from '../Sync/invokeOnWorker'
22-
2320
import { useEditorStore } from './useEditorStore'
21+
import { useSearch } from './useSearch'
2422
import { useSputlitContext, VisualState } from './useSputlitContext'
2523

2624
export const useSnippets = () => {
@@ -34,6 +32,7 @@ export const useSnippets = () => {
3432
const addMetadata = useMetadataStore((s) => s.addMetadata)
3533
const setSlashCommands = useDataStore((store) => store.setSlashCommands)
3634

35+
const { updateDocument } = useSearch()
3736
const { generateSlashCommands } = useSlashCommands()
3837

3938
const getSnippets = () => {
@@ -70,13 +69,12 @@ export const useSnippets = () => {
7069
const metadata = extractMetadata(message.metadata, { icon: DefaultMIcons.SNIPPET })
7170

7271
addMetadata('snippets', { [message.id]: metadata })
73-
wUpdateDoc({
72+
73+
updateDocument({
7474
indexKey: Indexes.SNIPPET,
7575
id: message.id,
7676
contents: request.data.content,
7777
title: message.title
78-
}).then(() => {
79-
useContentStore.getState().setDocUpdated()
8078
})
8179

8280
if (notify) {

apps/extension/src/Utils/requestHandler.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export const handleCaptureRequest = ({ subType, data }) => {
3232
})
3333
.json()
3434
.then((response: any) => {
35-
return { message: { ...response.data, content: deserializeContent(reqData.data) }, error: null }
35+
return { message: { ...response, content: deserializeContent(reqData.data) }, error: null }
3636
})
3737
.catch((err) => {
3838
return { message: null, error: err }
@@ -62,7 +62,7 @@ export const handleCaptureRequest = ({ subType, data }) => {
6262
})
6363
.json()
6464
.then((response: any) => {
65-
return { message: { ...response.data, content: deserializeContent(reqData.data) }, error: null }
65+
return { message: { ...response, content: deserializeContent(reqData.data) }, error: null }
6666
})
6767
.catch((error) => {
6868
return { message: null, error: error }
@@ -90,7 +90,7 @@ export const handleSnippetRequest = ({ data }) => {
9090
})
9191
.json()
9292
.then((response: any) => {
93-
return { message: response.data, error: null }
93+
return { message: response, error: null }
9494
})
9595
.catch((err) => {
9696
return { message: null, error: err }
@@ -113,7 +113,7 @@ export const handleNodeContentRequest = ({ subType, body, headers }) => {
113113
})
114114
.json()
115115
.then((response: any) => {
116-
return { message: response.data, error: null }
116+
return { message: response, error: null }
117117
})
118118
.catch((err) => {
119119
return { message: null, error: err }

apps/webapp/src/Components/Sidebar/SidebarList.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { debounce } from 'lodash'
77

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

10-
import { fuzzySearch, LastOpenedState, mog , useLayoutStore } from '@mexit/core'
10+
import { fuzzySearch, LastOpenedState, mog, useLayoutStore } from '@mexit/core'
1111
import {
1212
DesignItem,
1313
EmptyMessage,

apps/webapp/src/Components/Sidebar/TaskViewList.tsx

+1-7
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,7 @@ import React from 'react'
22

33
import stackLine from '@iconify/icons-ri/stack-line'
44

5-
import {
6-
ContextMenuType,
7-
getMIcon,
8-
ReminderViewData,
9-
useLayoutStore,
10-
ViewType
11-
} from '@mexit/core'
5+
import { ContextMenuType, getMIcon, ReminderViewData, useLayoutStore, ViewType } from '@mexit/core'
126
import { DefaultMIcons, IconDisplay } from '@mexit/shared'
137

148
import { NavigationType, ROUTE_PATHS, useRouting } from '../../Hooks/useRouting'

apps/webapp/src/Components/TaskHeader.tsx

+4-11
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,7 @@ import stackLine from '@iconify/icons-ri/stack-line'
1010
import { Icon } from '@iconify/react'
1111
import { useSingleton } from '@tippyjs/react'
1212

13-
import {
14-
Button,
15-
DisplayShortcut,
16-
IconButton,
17-
Infobox,
18-
LoadingButton,
19-
ToolbarTooltip
20-
} from '@workduck-io/mex-components'
13+
import { Button, DisplayShortcut, IconButton, LoadingButton, ToolbarTooltip } from '@workduck-io/mex-components'
2114
import { tinykeys } from '@workduck-io/tinykeys'
2215

2316
import {
@@ -26,7 +19,6 @@ import {
2619
ShortcutTokens,
2720
TaskHeader as StyledTaskHeader,
2821
TaskHeaderTitleSection,
29-
TasksHelp,
3022
TaskViewControls,
3123
TaskViewHeaderWrapper,
3224
TaskViewTitle
@@ -138,6 +130,7 @@ const ViewHeader = ({ cardSelected = false }: ViewHeaderProps) => {
138130
openTaskViewModal({
139131
cloneViewId: view?.id,
140132
filters: currentFilters,
133+
type: 'save-as',
141134
properties: {
142135
viewType,
143136
globalJoin,
@@ -216,7 +209,7 @@ const ViewHeader = ({ cardSelected = false }: ViewHeaderProps) => {
216209
</TaskHeaderTitleSection>
217210
<ShortcutTokens>
218211
<ShortcutToken>
219-
Select:
212+
Select Card:
220213
<Icon icon={dragMove2Fill} />
221214
</ShortcutToken>
222215
{cardSelected && (
@@ -243,7 +236,7 @@ const ViewHeader = ({ cardSelected = false }: ViewHeaderProps) => {
243236
</ShortcutToken>
244237
)}
245238
</ShortcutTokens>
246-
<Infobox text={TasksHelp} />
239+
{/* <Infobox text={TasksHelp} /> */}
247240
</StyledTaskHeader>
248241
)
249242
}

apps/webapp/src/Components/TaskViewModal.tsx

+15-2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ interface ViewProperties {
3737
groupBy?: string
3838
}
3939

40+
export type ViewCreateType = 'new' | 'update' | 'clone' | 'save-as'
41+
4042
interface TaskViewModalState {
4143
open: boolean
4244
// If present, changes in title, description will be applied to the view with viewid
@@ -45,9 +47,11 @@ interface TaskViewModalState {
4547
cloneViewId?: string
4648
filters: Filter[]
4749
properties?: ViewProperties
50+
type?: ViewCreateType
4851

4952
openModal: (args: {
5053
filters: Filter[]
54+
type?: ViewCreateType
5155
updateViewId?: string
5256
cloneViewId?: string
5357
properties: ViewProperties
@@ -59,6 +63,7 @@ interface TaskViewModalState {
5963
const getInitialState = () => ({
6064
open: false,
6165
filters: [],
66+
type: 'new' as ViewCreateType,
6267
updateViewId: undefined,
6368
cloneViewId: undefined,
6469
properties: {
@@ -88,6 +93,7 @@ const TaskViewModal = () => {
8893
const updateViewId = useTaskViewModalStore((store) => store.updateViewId)
8994
const cloneViewId = useTaskViewModalStore((store) => store.cloneViewId)
9095
const filters = useTaskViewModalStore((store) => store.filters)
96+
const type = useTaskViewModalStore((store) => store.type)
9197

9298
const closeModal = useTaskViewModalStore((store) => store.closeModal)
9399

@@ -173,10 +179,17 @@ const TaskViewModal = () => {
173179
closeModal()
174180
}
175181

176-
// mog('TaskViewModal', { open, curView })
182+
// * TODO: Use Type Based Switch here
183+
const getTitle = () => {
184+
if (updateViewId) return 'Update View'
185+
if (type === 'save-as') return 'Save As'
186+
if (cloneViewId) return 'Clone View'
187+
return 'New View'
188+
}
189+
177190
return (
178191
<Modal className="ModalContent" overlayClassName="ModalOverlay" onRequestClose={closeModal} isOpen={open}>
179-
<ModalHeader>{updateViewId ? 'Update' : cloneViewId ? 'Clone' : 'New'} Task View</ModalHeader>
192+
<ModalHeader>{getTitle()}</ModalHeader>
180193

181194
<form onSubmit={handleSubmit(onSubmit)}>
182195
<Input

apps/webapp/src/Components/Todo/BoardTask.tsx

-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ export const RenderBoardTask = React.memo<RenderTaskProps>(
4242

4343
const todo = useMemo(() => getTodoOfNode(nodeid, todoid), [nodeid, todoid])
4444
const pC = useMemo(() => getPureContent(todo), [id, todo, documentUpdated])
45-
console.log('TODO IS', { todo, pC, nodeid })
4645
const { accessWhenShared } = usePermissions()
4746
const readOnly = useMemo(() => isReadonly(accessWhenShared(todo?.nodeid)), [todo])
4847
const toggleModal = useModalStore((store) => store.toggleOpen)

apps/webapp/src/IFrame/initializeExtension.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import { get } from 'idb-keyval'
2-
31
import { BroadcastSyncedChannel, getStoreName, StoreIdentifier } from '@mexit/core'
42

53
const updateDwindleAuth = (extension) => {
@@ -14,7 +12,7 @@ const updateDwindleAuth = (extension) => {
1412

1513
const updateUserInfo = async (extension) => {
1614
const storeName = getStoreName(StoreIdentifier.AUTH, false)
17-
const data = await get(storeName)
15+
const data = localStorage.getItem(storeName)
1816
extension.sendToExtension({
1917
msgId: BroadcastSyncedChannel.AUTH,
2018
state: JSON.parse(data).state,

apps/webapp/src/Workers/search.ts

+13-3
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,24 @@ const searchWorker = {
4747
addDoc: (doc: IUpdateDoc) => {
4848
if (doc.indexKey === Indexes.ARCHIVE) console.log('Adding Archive Doc', { id: doc.id, contents: doc.contents })
4949

50-
searchX.addOrUpdateDocument(doc)
50+
searchX.addOrUpdateDocument({
51+
...doc,
52+
contents: doc.contents?.map((item) => ({ ...item, metadata: item.metadata ?? {} }))
53+
})
5154
},
5255
updateBlock: (doc: IUpdateDoc) => {
53-
searchX.appendToDoc(doc)
56+
searchX.appendToDoc({
57+
...doc,
58+
contents: doc.contents?.map((item) => ({ ...item, metadata: item.metadata ?? {} }))
59+
})
5460
},
5561
updateDoc: (doc: IUpdateDoc) => {
5662
if (doc.indexKey === Indexes.ARCHIVE) console.log('Updating Archive Doc', { id: doc.id, contents: doc.contents })
57-
searchX.addOrUpdateDocument(doc)
63+
64+
searchX.addOrUpdateDocument({
65+
...doc,
66+
contents: doc.contents?.map((item) => ({ ...item, metadata: item.metadata ?? {} }))
67+
})
5868
},
5969
updateILink: (ilink: ILink) => {
6070
searchX.updateIlink(ilink)

libs/core/src/Stores/auth.store.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export const authStoreConfig = (set, get) => ({
3636
}
3737
})
3838

39-
export const useAuthStore = createStore(authStoreConfig, StoreIdentifier.AUTHSTORE, true, {
39+
export const useAuthStore = createStore(authStoreConfig, StoreIdentifier.AUTH, true, {
4040
storage: {
4141
web: typeof window !== 'undefined' ? localStorage : undefined
4242
}

libs/core/src/Types/Store.ts

-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ export enum StoreIdentifier {
6262
TREE = 'tree',
6363
USERCACHE = 'user-cache',
6464
APP = 'app',
65-
AUTHSTORE = 'authstore',
6665
EDITORS = 'editors',
6766
EDITOR = 'editor',
6867
BUFFER = 'buffer',

libs/shared/src/Style/Todo.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ export const ShortcutTokens = styled.div`
190190

191191
export const ShortcutToken = styled.div`
192192
display: flex;
193+
pointer-events: none;
193194
align-items: center;
194195
${({ theme }) => generateStyle(theme.generic.shortcut)};
195196
gap: ${({ theme }) => theme.spacing.small};

libs/shared/src/Utils/helpers.ts

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import React from 'react'
22
import toast from 'react-hot-toast'
33

44
export async function copyTextToClipboard(text: any, toastMessage?: string) {
5-
console.log('COPY TO CLIP', { text, s: String(text) })
65
await navigator.clipboard
76
.writeText(String(text))
87
.then(() => {

libs/shared/src/Utils/tabInfo.ts

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
export const getCurrentTab = async () => {
22
const cTabsArr = await chrome.tabs?.query({ currentWindow: true, active: true })
3-
console.log('Tabs: ', cTabsArr)
43
const currTab = cTabsArr[0]
54

65
return currTab

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"*.{ts,tsx}": "eslint --cache --fix"
2121
},
2222
"dependencies": {
23-
"@workduck-io/mex-search": "0.0.6",
23+
"@workduck-io/mex-search": "0.0.8",
2424
"buffer": "^6.0.3",
2525
"react-dnd": "^16.0.1",
2626
"react-dnd-html5-backend": "^16.0.1",

0 commit comments

Comments
 (0)