Skip to content

Commit 4c6e247

Browse files
authored
Initialize Entities In API calls, Personal View In Views Page (#413)
#413 * Init Entities in API calls, Inline Todos changes * Remove logs
1 parent c89e5cd commit 4c6e247

File tree

20 files changed

+116
-53
lines changed

20 files changed

+116
-53
lines changed

.changeset/sour-berries-compete.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'mexit-webapp': patch
3+
---
4+
5+
'Init Entities in API calls, inline tasks'

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@ const ViewList = () => {
7272
data: {}
7373
},
7474
{
75-
label: 'Reminders',
75+
label: 'Personal',
7676
id: ReminderViewData.id,
77-
icon: getMIcon('ICON', 'ri:timer-flash-line'),
77+
icon: getMIcon('ICON', 'ri:user-line'),
7878
data: {}
7979
}
8080
]}

apps/webapp/src/Components/TaskHeader.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ const ViewHeader = ({ cardSelected = false }: ViewHeaderProps) => {
107107

108108
const openTaskViewModal = useTaskViewModalStore((store) => store.openModal)
109109

110-
const isDefault = ['tasks', 'reminders'].includes(view?.id)
110+
const isDefault = ['tasks', 'personal'].includes(view?.id)
111111

112112
const { goTo } = useRouting()
113113

apps/webapp/src/Components/Views/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export const ViewContainer: React.FC<ViewProps> = ({ viewId, withFilters = true
6363

6464
return (
6565
<View>
66-
<ViewRenderer key={activeView?.id} view={activeView} />
66+
<ViewRenderer view={activeView} />
6767
</View>
6868
)
6969
}

apps/webapp/src/Editor/Components/SlashCommands/useSlashCommandOnChange.ts

+13-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,14 @@ import {
99
TElement
1010
} from '@udecode/plate'
1111

12-
import { camelCase, FloatingElementType, isElder, useComboboxStore, useFloatingStore } from '@mexit/core'
12+
import {
13+
camelCase,
14+
ELEMENT_TODO_LI,
15+
FloatingElementType,
16+
isElder,
17+
useComboboxStore,
18+
useFloatingStore
19+
} from '@mexit/core'
1320

1421
import { useSnippets } from '../../../Hooks/useSnippets'
1522
import { IComboboxItem, SlashCommandConfig } from '../../Types/Combobox'
@@ -23,10 +30,13 @@ export const useSlashCommandOnChange = (keys: { [type: string]: SlashCommandConf
2330
const targetRange = useComboboxStore.getState().targetRange
2431
const commandKey = Object.keys(keys).filter((k) => keys[k].command === item.key)[0]
2532
const commandConfig = keys[commandKey]
26-
2733
if (targetRange) {
2834
try {
29-
if (isElder(commandKey, 'snip')) {
35+
if (commandConfig.slateElementType === ELEMENT_TODO_LI) {
36+
const data = commandConfig.getData ? commandConfig.getData(item) : { type: commandConfig.slateElementType }
37+
select(editor, targetRange)
38+
insertNodes(editor, data)
39+
} else if (isElder(commandKey, 'snip')) {
3040
const content = getSnippetContent(commandConfig.command)
3141
if (content) {
3242
select(editor, targetRange)

apps/webapp/src/Editor/Hooks/useEditorConfig.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
mog,
1717
PromptRenderType,
1818
SEPARATOR,
19+
TodoStatus,
1920
useAuthStore,
2021
useDataStore,
2122
useEditorStore,
@@ -259,7 +260,12 @@ export const useEditorPluginConfig = (editorId: string, options?: PluginOptionTy
259260
},
260261
task: {
261262
slateElementType: ELEMENT_TODO_LI,
262-
command: 'task'
263+
command: 'task',
264+
getData: () => ({
265+
type: ELEMENT_TODO_LI,
266+
children: [{ text: '' }],
267+
status: TodoStatus.todo
268+
})
263269
},
264270
table: {
265271
slateElementType: ELEMENT_TABLE,

apps/webapp/src/Editor/Plugins/options.tsx

+6-15
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import {
4040
MARK_ITALIC,
4141
MARK_STRIKETHROUGH,
4242
PlateEditor,
43+
setElements,
4344
toggleList,
4445
unwrapList,
4546
Value
@@ -62,18 +63,12 @@ const preFormat = (editor: PlateEditor<Value>) => unwrapList(editor)
6263
* Returns true if the autoformat can be applied:
6364
* Is outside of code
6465
*/
65-
const formatQuery = (editor: PlateEditor<Value>, options: AutoformatQueryOptions) => {
66+
export const formatQuery = (editor: PlateEditor<Value>, options: AutoformatQueryOptions) => {
6667
const parentEntry = getParentNode(editor, editor.selection.focus)
6768
if (!parentEntry) return
6869
const [node] = parentEntry
6970

70-
// mog('formatQuery', { editor, options, node })
71-
7271
if (isElement(node) && node.type !== ELEMENT_CODE_LINE && node.type !== ELEMENT_CODE_BLOCK) {
73-
// mog('formatNodeConversion', {
74-
// node,
75-
// parentEntry
76-
// })
7772
return true
7873
}
7974
return false
@@ -177,14 +172,10 @@ export const optionsAutoFormatRule: Array<AutoformatRule> = [
177172
match: '[]',
178173
triggerAtBlockStart: true,
179174
format: (editor: PlateEditor<Value>) => {
180-
insertNodes(editor, [
181-
{
182-
type: ELEMENT_TODO_LI,
183-
children: [{ text: '' }],
184-
id: generateTempId(),
185-
status: TodoStatus.todo
186-
}
187-
])
175+
setElements(editor, {
176+
type: ELEMENT_TODO_LI,
177+
status: TodoStatus.todo
178+
})
188179
},
189180
query: formatQuery
190181
},

apps/webapp/src/Hooks/useHighlights.tsx

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { useCallback } from 'react'
22

33
import { mog, useHighlightStore } from '@mexit/core'
44

5+
import { getEntitiyInitializer } from '../Workers/controller'
6+
57
import { useHighlightAPI } from './API/useHighlightAPI'
68

79
export const useHighlights = () => {
@@ -38,6 +40,7 @@ export const useHighlightSync = () => {
3840
.then((highlights) => {
3941
if (highlights) {
4042
setHighlights(highlights)
43+
getEntitiyInitializer('initializeHighlights', highlights)
4144
}
4245
})
4346
.catch((e) => {

apps/webapp/src/Hooks/useInitLoader.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export const useInitLoader = () => {
4141

4242
const getWorkspaceId = useAuthStore((store) => store.getWorkspaceId)
4343
const snippetHydrated = useSnippetStore((store) => store._hasHydrated)
44+
const highlightStoreHydrated = useHighlightStore((store) => store._hasHydrated)
4445
const dataStoreHydrated = useDataStore((store) => store._hasHydrated)
4546
const contentStoreHydrated = useContentStore((store) => store._hasHydrated)
4647
const initHighlightBlockMap = useHighlightStore((store) => store.initHighlightBlockMap)
@@ -124,7 +125,8 @@ export const useInitLoader = () => {
124125
userPrefHydrated &&
125126
snippetHydrated &&
126127
dataStoreHydrated &&
127-
contentStoreHydrated
128+
contentStoreHydrated &&
129+
highlightStoreHydrated
128130
) {
129131
startWorkers()
130132
.then(async () => {

apps/webapp/src/Hooks/useURLs.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,11 @@ import {
1515
URL_DOMAIN_REG,
1616
useAuthStore,
1717
useDataStore,
18-
useHighlightStore
19-
, useLinkStore } from '@mexit/core'
18+
useHighlightStore,
19+
useLinkStore
20+
} from '@mexit/core'
21+
22+
import { getEntitiyInitializer } from '../Workers/controller'
2023

2124
import { useLinkFilterFunctions } from './useFilterFunctions'
2225
import { applyFilters, FilterStore } from './useFilters'
@@ -352,6 +355,7 @@ export const useURLsAPI = () => {
352355
})
353356
.then((links: Link[]) => {
354357
setLinks(links)
358+
getEntitiyInitializer('initializeLinks', links)
355359
})
356360
.catch(console.error)
357361

apps/webapp/src/Hooks/useViewResults.ts

+7-5
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,13 @@ const useViewResults = (path: string) => {
4646
const filterSetQuery = currentFilters?.length > 0 ? [...parentFilters, currentFilters] : parentFilters
4747
const query = generateFilterSetQuery(filterSetQuery, entities)
4848

49-
queryIndex(Indexes.MAIN, query).then((queryResult) => {
50-
if (queryResult) {
51-
setResults(queryResult)
52-
}
53-
})
49+
if (query.length) {
50+
queryIndex(Indexes.MAIN, query).then((queryResult) => {
51+
if (queryResult) {
52+
setResults(queryResult)
53+
}
54+
})
55+
} else setResults([])
5456
}, [currentFilters, entities, docUpdated])
5557

5658
return groupedResults

apps/webapp/src/Hooks/useViews.tsx

+28-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Entities } from '@workduck-io/mex-search'
22

3-
import { Filter, getAllEntities, useDataStore, View, ViewType } from '@mexit/core'
3+
import { Filter, getAllEntities, RESERVED_NAMESPACES, useDataStore, View, ViewType } from '@mexit/core'
44

55
import { useViewStore } from '../Stores/useViewStore'
66

@@ -32,6 +32,25 @@ export const useViews = () => {
3232
}
3333
}
3434

35+
const getPersonalSpace = (): Filter => {
36+
const space = useDataStore.getState().spaces.find((space) => space.name === RESERVED_NAMESPACES.default)
37+
38+
if (space)
39+
return {
40+
multiple: false,
41+
id: 'FILTER_SPACE',
42+
join: 'all',
43+
type: 'space',
44+
values: [
45+
{
46+
value: space.id,
47+
id: space.id,
48+
label: space.name
49+
}
50+
]
51+
}
52+
}
53+
3554
const getParentViewFilters = (path: string) => {
3655
const entities = getAllEntities(path)
3756

@@ -64,14 +83,16 @@ export const useViews = () => {
6483
globalJoin: 'all',
6584
sortOrder: 'ascending'
6685
}
67-
case 'reminders':
86+
case 'personal':
87+
// eslint-disable-next-line no-case-declarations
88+
const personalFilters = getPersonalSpace()
6889
return {
69-
id: 'reminders',
70-
filters: [],
71-
title: 'Reminders',
72-
description: 'The Reminders View is helpful tool for keeping track of tasks, events, and deadlines.',
90+
id: 'personal',
91+
filters: personalFilters ? [personalFilters] : [],
92+
title: 'Personal',
93+
description: 'The Personal View is helpful tool for keeping track of tasks, events, and deadlines.',
7394
viewType: ViewType.List,
74-
entities: [Entities.REMINDER],
95+
entities: [],
7596
globalJoin: 'all',
7697
sortOrder: 'ascending'
7798
}

apps/webapp/src/Stores/useAuth.ts

+2
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export const useAuthentication = () => {
4646
const [sensitiveData, setSensitiveData] = useState<RegisterFormData | undefined>()
4747

4848
const initContents = useContentStore((store) => store.initContents)
49+
const resetHighlights = useHighlightStore((store) => store.reset)
4950
const clearUsersCache = useUserCacheStore((s) => s.clearCache)
5051
const clearUserPreferences = useUserPreferenceStore((store) => store.clear)
5152
const clearSnippets = useSnippetStore((s) => s.clear)
@@ -119,6 +120,7 @@ export const useAuthentication = () => {
119120
clearReactions()
120121
clearComments()
121122
resetDataStore()
123+
resetHighlights()
122124
clearMentions()
123125
clearRoutesInformation()
124126
resetPublicNodes()

apps/webapp/src/Switch.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { animated } from 'react-spring'
55

66
import styled from 'styled-components'
77

8-
import { AppInitStatus, useAuthStore, useBlockStore, useEditorStore , useLayoutStore } from '@mexit/core'
8+
import { AppInitStatus, useAuthStore, useBlockStore, useEditorStore, useLayoutStore } from '@mexit/core'
99
import { OverlaySidebarWindowWidth } from '@mexit/shared'
1010

1111
import RouteNotFound from './Components/404'

apps/webapp/src/Utils/nav.ts

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export const showNav = (pathname: string): boolean => {
1212
'/tag',
1313
'/integrations',
1414
'/reminders',
15+
'/personal',
1516
ROUTE_PATHS.links
1617
]
1718

apps/webapp/src/Views/SearchView.tsx

-1
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,6 @@ const SearchView = <Item,>({
276276
useEffect(() => {
277277
executeSearch(searchTerm)
278278
return () => {
279-
mog('clearing search', { searchTerm })
280279
clearSearch()
281280
}
282281
}, []) // eslint-disable-line react-hooks/exhaustive-deps

libs/core/src/Data/defaultCommands.ts

+10-8
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@ export const defaultCommands: SlashCommand[] = [
1111
{ command: 'task', text: 'Create a Task', icon: getMIcon('ICON', 'ri:task-line'), type: CategoryType.action },
1212
{ command: 'table', text: 'Insert Table', icon: getMIcon('ICON', 'ri:table-line'), type: CategoryType.action },
1313
// { command: 'canvas', text: 'Insert Drawing canvas', icon: getMIcon('ICON', 'ri:markup-line'), type: CategoryType.action },
14-
{ command: 'webem', text: 'Insert Web embed', icon: getMIcon('ICON', 'ri:global-line'), type: CategoryType.action },
15-
{
16-
command: 'remind',
17-
text: 'Create a Reminder',
18-
icon: getMIcon('ICON', 'ri:timer-line'),
19-
type: CategoryType.action,
20-
extended: true
21-
}
14+
{ command: 'webem', text: 'Insert Web embed', icon: getMIcon('ICON', 'ri:global-line'), type: CategoryType.action }
15+
16+
// TODO: Add this back in when they are ready
17+
// {
18+
// command: 'remind',
19+
// text: 'Create a Reminder',
20+
// icon: getMIcon('ICON', 'ri:timer-line'),
21+
// type: CategoryType.action,
22+
// extended: true
23+
// }
2224
] as SlashCommand[]

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

+10-2
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ interface LayoutState {
4444

4545
const SIDEBAR_WIDTH = 276
4646

47-
export const layoutStoreConfig = (set, get) => ({
47+
const initializeLayoutStore = () => ({
4848
// Focus mode
4949
toggleTop: 44,
5050
showLoader: false,
@@ -65,7 +65,11 @@ export const layoutStoreConfig = (set, get) => ({
6565
rhSidebar: {
6666
expanded: false,
6767
show: true
68-
},
68+
}
69+
})
70+
71+
export const layoutStoreConfig = (set, get) => ({
72+
...initializeLayoutStore(),
6973
setToggleTop: (height: number) => set({ toggleTop: height }),
7074
toggleFocusMode: () => set((state) => ({ focusMode: { ...state.focusMode, on: !state.focusMode.on } })),
7175
setFocusMode: (focusMode) => set({ focusMode }),
@@ -115,6 +119,10 @@ export const layoutStoreConfig = (set, get) => ({
115119
const infobar = get().infobar
116120
if (infobar.mode === mode) return
117121
set({ infobar: { ...infobar, mode } })
122+
},
123+
reset: () => {
124+
const initLayoutState = initializeLayoutStore()
125+
set(initLayoutState)
118126
}
119127
})
120128

libs/core/src/Utils/reminders.ts

+9-2
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,16 @@ export const upcoming = (reminder: Reminder) => {
8080
return today.getTime() <= reminder.time
8181
}
8282

83+
// export const ReminderViewData: any = {
84+
// id: 'reminders',
85+
// title: 'Reminders',
86+
// filters: [],
87+
// globalJoin: 'all'
88+
// }
89+
8390
export const ReminderViewData: any = {
84-
id: 'reminders',
85-
title: 'Reminders',
91+
id: 'personal',
92+
title: 'Personal',
8693
filters: [],
8794
globalJoin: 'all'
8895
}

libs/shared/src/Components/AIPreview/styled.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ export const FloaterContainer = styled.div`
107107
backdrop-filter: blur(2rem);
108108
border: 1px solid ${({ theme }) => theme.tokens.surfaces.app};
109109
transform-origin: top;
110-
z-index: 9999;
110+
z-index: 10;
111111
border: 1px solid ${({ theme }) => theme.tokens.surfaces.s[3]};
112112
animation: ${float} 150ms ease-out;
113113
`

0 commit comments

Comments
 (0)