forked from docmost/docmost
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e0e5f7c
commit a0ec2f3
Showing
22 changed files
with
522 additions
and
174 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { useQuery, UseQueryResult } from '@tanstack/react-query'; | ||
import { searchPage } from '@/features/search/services/search-service'; | ||
import { IPageSearch } from '@/features/search/types/search.types'; | ||
|
||
export function usePageSearchQuery(query: string): UseQueryResult<IPageSearch[], Error> { | ||
return useQuery({ | ||
queryKey: ['page-history', query], | ||
queryFn: () => searchPage(query), | ||
enabled: !!query, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,59 @@ | ||
import { rem } from '@mantine/core'; | ||
import { Spotlight, SpotlightActionData } from '@mantine/spotlight'; | ||
import { IconHome, IconDashboard, IconSettings, IconSearch } from '@tabler/icons-react'; | ||
|
||
const actions: SpotlightActionData[] = [ | ||
{ | ||
id: 'home', | ||
label: 'Home', | ||
description: 'Get to home page', | ||
onClick: () => console.log('Home'), | ||
leftSection: <IconHome style={{ width: rem(24), height: rem(24) }} stroke={1.5} />, | ||
}, | ||
{ | ||
id: 'dashboard', | ||
label: 'Dashboard', | ||
description: 'Get full information about current system status', | ||
onClick: () => console.log('Dashboard'), | ||
leftSection: <IconDashboard style={{ width: rem(24), height: rem(24) }} stroke={1.5} />, | ||
}, | ||
{ | ||
id: 'settings', | ||
label: 'Settings', | ||
description: 'Account settings and workspace management', | ||
onClick: () => console.log('Settings'), | ||
leftSection: <IconSettings style={{ width: rem(24), height: rem(24) }} stroke={1.5} />, | ||
}, | ||
]; | ||
import { Group, Center, Text } from '@mantine/core'; | ||
import { Spotlight } from '@mantine/spotlight'; | ||
import { IconFileDescription, IconHome, IconSearch, IconSettings } from '@tabler/icons-react'; | ||
import React, { useState } from 'react'; | ||
import { useNavigate } from 'react-router-dom'; | ||
import { useDebouncedValue } from '@mantine/hooks'; | ||
import { usePageSearchQuery } from '@/features/search/queries/search-query'; | ||
|
||
|
||
export function SearchSpotlight() { | ||
const navigate = useNavigate(); | ||
const [query, setQuery] = useState(''); | ||
const [debouncedSearchQuery] = useDebouncedValue(query, 300); | ||
const { data: searchResults, isLoading, error } = usePageSearchQuery(debouncedSearchQuery) | ||
|
||
const items = (searchResults && searchResults.length > 0 ? searchResults : []) | ||
.map((item) => ( | ||
<Spotlight.Action key={item.title} onClick={() => navigate(`/p/${item.id}`)}> | ||
<Group wrap="nowrap" w="100%"> | ||
<Center> | ||
{item?.icon ? ( | ||
<span style={{ fontSize: "20px" }}>{ item.icon }</span> | ||
) : ( | ||
<IconFileDescription size={20} /> | ||
)} | ||
</Center> | ||
|
||
<div style={{ flex: 1 }}> | ||
<Text>{item.title}</Text> | ||
|
||
{item?.highlight && ( | ||
<Text opacity={0.6} size="xs" dangerouslySetInnerHTML={{ __html: item.highlight }}/> | ||
)} | ||
</div> | ||
|
||
</Group> | ||
</Spotlight.Action> | ||
)); | ||
|
||
return ( | ||
<> | ||
<Spotlight | ||
actions={actions} | ||
nothingFound="Nothing found..." | ||
highlightQuery | ||
searchProps={{ | ||
leftSection: <IconSearch style={{ width: rem(20), height: rem(20) }} stroke={1.5} />, | ||
placeholder: 'Search...', | ||
}} | ||
/> | ||
<Spotlight.Root query={query} | ||
onQueryChange={setQuery} | ||
scrollable | ||
overlayProps={{ | ||
backgroundOpacity: 0.55, | ||
}}> | ||
<Spotlight.Search placeholder="Search..." | ||
leftSection={ | ||
<IconSearch size={20} stroke={1.5} /> | ||
} /> | ||
<Spotlight.ActionsList> | ||
{items.length > 0 ? items : <Spotlight.Empty>No results found...</Spotlight.Empty>} | ||
</Spotlight.ActionsList> | ||
</Spotlight.Root> | ||
|
||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import api from '@/lib/api-client'; | ||
import { IPageSearch } from '@/features/search/types/search.types'; | ||
|
||
export async function searchPage(query: string): Promise<IPageSearch[]> { | ||
const req = await api.post<IPageSearch[]>('/search', { query }); | ||
return req.data as any; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
|
||
export interface IPageSearch { | ||
id: string; | ||
title: string; | ||
icon: string; | ||
parentPageId: string; | ||
creatorId: string; | ||
createdAt: Date; | ||
updatedAt: Date; | ||
rank: string; | ||
highlight: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { StarterKit } from '@tiptap/starter-kit'; | ||
import { TextAlign } from '@tiptap/extension-text-align'; | ||
import { TaskList } from '@tiptap/extension-task-list'; | ||
import { TaskItem } from '@tiptap/extension-task-item'; | ||
import { Underline } from '@tiptap/extension-underline'; | ||
import { Link } from '@tiptap/extension-link'; | ||
import { Superscript } from '@tiptap/extension-superscript'; | ||
import SubScript from '@tiptap/extension-subscript'; | ||
import { Highlight } from '@tiptap/extension-highlight'; | ||
import { Typography } from '@tiptap/extension-typography'; | ||
import { TextStyle } from '@tiptap/extension-text-style'; | ||
import { Color } from '@tiptap/extension-color'; | ||
import { TrailingNode, Comment } from '@docmost/editor-ext'; | ||
import { generateHTML, generateJSON } from '@tiptap/html'; | ||
import { generateText, JSONContent } from '@tiptap/core'; | ||
|
||
export const tiptapExtensions = [ | ||
StarterKit, | ||
Comment, | ||
TextAlign, | ||
TaskList, | ||
TaskItem, | ||
Underline, | ||
Link, | ||
Superscript, | ||
SubScript, | ||
Highlight, | ||
Typography, | ||
TrailingNode, | ||
TextStyle, | ||
Color, | ||
]; | ||
|
||
export function jsonToHtml(tiptapJson: JSONContent) { | ||
return generateHTML(tiptapJson, tiptapExtensions); | ||
} | ||
|
||
export function htmlToJson(html: string) { | ||
return generateJSON(html, tiptapExtensions); | ||
} | ||
|
||
export function jsonToText(tiptapJson: JSONContent) { | ||
return generateText(tiptapJson, tiptapExtensions); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export class SearchResponseDto { | ||
id: string; | ||
title: string; | ||
icon: string; | ||
parentPageId: string; | ||
creatorId: string; | ||
rank: string; | ||
highlight: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { IsNumber, IsOptional, IsString } from 'class-validator'; | ||
|
||
export class SearchDTO { | ||
@IsString() | ||
query: string; | ||
|
||
@IsOptional() | ||
@IsString() | ||
creatorId?: string; | ||
|
||
@IsOptional() | ||
@IsNumber() | ||
limit?: number; | ||
|
||
@IsOptional() | ||
@IsNumber() | ||
offset?: number; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { SearchController } from './search.controller'; | ||
|
||
describe('SearchController', () => { | ||
let controller: SearchController; | ||
|
||
beforeEach(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
controllers: [SearchController], | ||
}).compile(); | ||
|
||
controller = module.get<SearchController>(SearchController); | ||
}); | ||
|
||
it('should be defined', () => { | ||
expect(controller).toBeDefined(); | ||
}); | ||
}); |
Oops, something went wrong.