chore: search for guest

This commit is contained in:
Aslam H
2024-10-22 20:58:49 +07:00
parent 200245b39f
commit f6bacc8f29
2 changed files with 49 additions and 42 deletions
+28 -29
View File
@@ -18,11 +18,11 @@ import { Route as LayoutPagesImport } from './routes/_layout/_pages'
import { Route as LayoutlandingIndexImport } from './routes/_layout/(landing)/index' import { Route as LayoutlandingIndexImport } from './routes/_layout/(landing)/index'
import { Route as LayoutPagesProtectedImport } from './routes/_layout/_pages/_protected' import { Route as LayoutPagesProtectedImport } from './routes/_layout/_pages/_protected'
import { Route as LayoutauthAuthImport } from './routes/_layout/(auth)/_auth' import { Route as LayoutauthAuthImport } from './routes/_layout/(auth)/_auth'
import { Route as LayoutPagesSearchIndexImport } from './routes/_layout/_pages/search/index'
import { Route as LayoutPagestopicSplatImport } from './routes/_layout/_pages/(topic)/$' import { Route as LayoutPagestopicSplatImport } from './routes/_layout/_pages/(topic)/$'
import { Route as LayoutPagesProtectedTopicsIndexImport } from './routes/_layout/_pages/_protected/topics/index' import { Route as LayoutPagesProtectedTopicsIndexImport } from './routes/_layout/_pages/_protected/topics/index'
import { Route as LayoutPagesProtectedTasksIndexImport } from './routes/_layout/_pages/_protected/tasks/index' import { Route as LayoutPagesProtectedTasksIndexImport } from './routes/_layout/_pages/_protected/tasks/index'
import { Route as LayoutPagesProtectedSettingsIndexImport } from './routes/_layout/_pages/_protected/settings/index' import { Route as LayoutPagesProtectedSettingsIndexImport } from './routes/_layout/_pages/_protected/settings/index'
import { Route as LayoutPagesProtectedSearchIndexImport } from './routes/_layout/_pages/_protected/search/index'
import { Route as LayoutPagesProtectedProfileIndexImport } from './routes/_layout/_pages/_protected/profile/index' import { Route as LayoutPagesProtectedProfileIndexImport } from './routes/_layout/_pages/_protected/profile/index'
import { Route as LayoutPagesProtectedPagesIndexImport } from './routes/_layout/_pages/_protected/pages/index' import { Route as LayoutPagesProtectedPagesIndexImport } from './routes/_layout/_pages/_protected/pages/index'
import { Route as LayoutPagesProtectedOnboardingIndexImport } from './routes/_layout/_pages/_protected/onboarding/index' import { Route as LayoutPagesProtectedOnboardingIndexImport } from './routes/_layout/_pages/_protected/onboarding/index'
@@ -70,6 +70,12 @@ const LayoutauthAuthRoute = LayoutauthAuthImport.update({
getParentRoute: () => LayoutauthRoute, getParentRoute: () => LayoutauthRoute,
} as any) } as any)
const LayoutPagesSearchIndexRoute = LayoutPagesSearchIndexImport.update({
id: '/search/',
path: '/search/',
getParentRoute: () => LayoutPagesRoute,
} as any)
const LayoutPagestopicSplatRoute = LayoutPagestopicSplatImport.update({ const LayoutPagestopicSplatRoute = LayoutPagestopicSplatImport.update({
id: '/(topic)/$', id: '/(topic)/$',
path: '/$', path: '/$',
@@ -97,13 +103,6 @@ const LayoutPagesProtectedSettingsIndexRoute =
getParentRoute: () => LayoutPagesProtectedRoute, getParentRoute: () => LayoutPagesProtectedRoute,
} as any) } as any)
const LayoutPagesProtectedSearchIndexRoute =
LayoutPagesProtectedSearchIndexImport.update({
id: '/search/',
path: '/search/',
getParentRoute: () => LayoutPagesProtectedRoute,
} as any)
const LayoutPagesProtectedProfileIndexRoute = const LayoutPagesProtectedProfileIndexRoute =
LayoutPagesProtectedProfileIndexImport.update({ LayoutPagesProtectedProfileIndexImport.update({
id: '/profile/', id: '/profile/',
@@ -218,6 +217,13 @@ declare module '@tanstack/react-router' {
preLoaderRoute: typeof LayoutPagestopicSplatImport preLoaderRoute: typeof LayoutPagestopicSplatImport
parentRoute: typeof LayoutPagesImport parentRoute: typeof LayoutPagesImport
} }
'/_layout/_pages/search/': {
id: '/_layout/_pages/search/'
path: '/search'
fullPath: '/search'
preLoaderRoute: typeof LayoutPagesSearchIndexImport
parentRoute: typeof LayoutPagesImport
}
'/_layout/(auth)/_auth/sign-in/$': { '/_layout/(auth)/_auth/sign-in/$': {
id: '/_layout/(auth)/_auth/sign-in/$' id: '/_layout/(auth)/_auth/sign-in/$'
path: '/sign-in/$' path: '/sign-in/$'
@@ -267,13 +273,6 @@ declare module '@tanstack/react-router' {
preLoaderRoute: typeof LayoutPagesProtectedProfileIndexImport preLoaderRoute: typeof LayoutPagesProtectedProfileIndexImport
parentRoute: typeof LayoutPagesProtectedImport parentRoute: typeof LayoutPagesProtectedImport
} }
'/_layout/_pages/_protected/search/': {
id: '/_layout/_pages/_protected/search/'
path: '/search'
fullPath: '/search'
preLoaderRoute: typeof LayoutPagesProtectedSearchIndexImport
parentRoute: typeof LayoutPagesProtectedImport
}
'/_layout/_pages/_protected/settings/': { '/_layout/_pages/_protected/settings/': {
id: '/_layout/_pages/_protected/settings/' id: '/_layout/_pages/_protected/settings/'
path: '/settings' path: '/settings'
@@ -320,7 +319,6 @@ interface LayoutPagesProtectedRouteChildren {
LayoutPagesProtectedOnboardingIndexRoute: typeof LayoutPagesProtectedOnboardingIndexRoute LayoutPagesProtectedOnboardingIndexRoute: typeof LayoutPagesProtectedOnboardingIndexRoute
LayoutPagesProtectedPagesIndexRoute: typeof LayoutPagesProtectedPagesIndexRoute LayoutPagesProtectedPagesIndexRoute: typeof LayoutPagesProtectedPagesIndexRoute
LayoutPagesProtectedProfileIndexRoute: typeof LayoutPagesProtectedProfileIndexRoute LayoutPagesProtectedProfileIndexRoute: typeof LayoutPagesProtectedProfileIndexRoute
LayoutPagesProtectedSearchIndexRoute: typeof LayoutPagesProtectedSearchIndexRoute
LayoutPagesProtectedSettingsIndexRoute: typeof LayoutPagesProtectedSettingsIndexRoute LayoutPagesProtectedSettingsIndexRoute: typeof LayoutPagesProtectedSettingsIndexRoute
LayoutPagesProtectedTasksIndexRoute: typeof LayoutPagesProtectedTasksIndexRoute LayoutPagesProtectedTasksIndexRoute: typeof LayoutPagesProtectedTasksIndexRoute
LayoutPagesProtectedTopicsIndexRoute: typeof LayoutPagesProtectedTopicsIndexRoute LayoutPagesProtectedTopicsIndexRoute: typeof LayoutPagesProtectedTopicsIndexRoute
@@ -336,7 +334,6 @@ const LayoutPagesProtectedRouteChildren: LayoutPagesProtectedRouteChildren = {
LayoutPagesProtectedOnboardingIndexRoute, LayoutPagesProtectedOnboardingIndexRoute,
LayoutPagesProtectedPagesIndexRoute: LayoutPagesProtectedPagesIndexRoute, LayoutPagesProtectedPagesIndexRoute: LayoutPagesProtectedPagesIndexRoute,
LayoutPagesProtectedProfileIndexRoute: LayoutPagesProtectedProfileIndexRoute, LayoutPagesProtectedProfileIndexRoute: LayoutPagesProtectedProfileIndexRoute,
LayoutPagesProtectedSearchIndexRoute: LayoutPagesProtectedSearchIndexRoute,
LayoutPagesProtectedSettingsIndexRoute: LayoutPagesProtectedSettingsIndexRoute:
LayoutPagesProtectedSettingsIndexRoute, LayoutPagesProtectedSettingsIndexRoute,
LayoutPagesProtectedTasksIndexRoute: LayoutPagesProtectedTasksIndexRoute, LayoutPagesProtectedTasksIndexRoute: LayoutPagesProtectedTasksIndexRoute,
@@ -353,11 +350,13 @@ const LayoutPagesProtectedRouteWithChildren =
interface LayoutPagesRouteChildren { interface LayoutPagesRouteChildren {
LayoutPagesProtectedRoute: typeof LayoutPagesProtectedRouteWithChildren LayoutPagesProtectedRoute: typeof LayoutPagesProtectedRouteWithChildren
LayoutPagestopicSplatRoute: typeof LayoutPagestopicSplatRoute LayoutPagestopicSplatRoute: typeof LayoutPagestopicSplatRoute
LayoutPagesSearchIndexRoute: typeof LayoutPagesSearchIndexRoute
} }
const LayoutPagesRouteChildren: LayoutPagesRouteChildren = { const LayoutPagesRouteChildren: LayoutPagesRouteChildren = {
LayoutPagesProtectedRoute: LayoutPagesProtectedRouteWithChildren, LayoutPagesProtectedRoute: LayoutPagesProtectedRouteWithChildren,
LayoutPagestopicSplatRoute: LayoutPagestopicSplatRoute, LayoutPagestopicSplatRoute: LayoutPagestopicSplatRoute,
LayoutPagesSearchIndexRoute: LayoutPagesSearchIndexRoute,
} }
const LayoutPagesRouteWithChildren = LayoutPagesRoute._addFileChildren( const LayoutPagesRouteWithChildren = LayoutPagesRoute._addFileChildren(
@@ -409,6 +408,7 @@ export interface FileRoutesByFullPath {
'': typeof LayoutPagesProtectedRouteWithChildren '': typeof LayoutPagesProtectedRouteWithChildren
'/': typeof LayoutlandingIndexRoute '/': typeof LayoutlandingIndexRoute
'/$': typeof LayoutPagestopicSplatRoute '/$': typeof LayoutPagestopicSplatRoute
'/search': typeof LayoutPagesSearchIndexRoute
'/sign-in/$': typeof LayoutauthAuthSignInSplatRoute '/sign-in/$': typeof LayoutauthAuthSignInSplatRoute
'/sign-up/$': typeof LayoutauthAuthSignUpSplatRoute '/sign-up/$': typeof LayoutauthAuthSignUpSplatRoute
'/journals': typeof LayoutPagesProtectedJournalsIndexRoute '/journals': typeof LayoutPagesProtectedJournalsIndexRoute
@@ -416,7 +416,6 @@ export interface FileRoutesByFullPath {
'/onboarding': typeof LayoutPagesProtectedOnboardingIndexRoute '/onboarding': typeof LayoutPagesProtectedOnboardingIndexRoute
'/pages': typeof LayoutPagesProtectedPagesIndexRoute '/pages': typeof LayoutPagesProtectedPagesIndexRoute
'/profile': typeof LayoutPagesProtectedProfileIndexRoute '/profile': typeof LayoutPagesProtectedProfileIndexRoute
'/search': typeof LayoutPagesProtectedSearchIndexRoute
'/settings': typeof LayoutPagesProtectedSettingsIndexRoute '/settings': typeof LayoutPagesProtectedSettingsIndexRoute
'/tasks': typeof LayoutPagesProtectedTasksIndexRoute '/tasks': typeof LayoutPagesProtectedTasksIndexRoute
'/topics': typeof LayoutPagesProtectedTopicsIndexRoute '/topics': typeof LayoutPagesProtectedTopicsIndexRoute
@@ -428,6 +427,7 @@ export interface FileRoutesByTo {
'': typeof LayoutPagesProtectedRouteWithChildren '': typeof LayoutPagesProtectedRouteWithChildren
'/': typeof LayoutlandingIndexRoute '/': typeof LayoutlandingIndexRoute
'/$': typeof LayoutPagestopicSplatRoute '/$': typeof LayoutPagestopicSplatRoute
'/search': typeof LayoutPagesSearchIndexRoute
'/sign-in/$': typeof LayoutauthAuthSignInSplatRoute '/sign-in/$': typeof LayoutauthAuthSignInSplatRoute
'/sign-up/$': typeof LayoutauthAuthSignUpSplatRoute '/sign-up/$': typeof LayoutauthAuthSignUpSplatRoute
'/journals': typeof LayoutPagesProtectedJournalsIndexRoute '/journals': typeof LayoutPagesProtectedJournalsIndexRoute
@@ -435,7 +435,6 @@ export interface FileRoutesByTo {
'/onboarding': typeof LayoutPagesProtectedOnboardingIndexRoute '/onboarding': typeof LayoutPagesProtectedOnboardingIndexRoute
'/pages': typeof LayoutPagesProtectedPagesIndexRoute '/pages': typeof LayoutPagesProtectedPagesIndexRoute
'/profile': typeof LayoutPagesProtectedProfileIndexRoute '/profile': typeof LayoutPagesProtectedProfileIndexRoute
'/search': typeof LayoutPagesProtectedSearchIndexRoute
'/settings': typeof LayoutPagesProtectedSettingsIndexRoute '/settings': typeof LayoutPagesProtectedSettingsIndexRoute
'/tasks': typeof LayoutPagesProtectedTasksIndexRoute '/tasks': typeof LayoutPagesProtectedTasksIndexRoute
'/topics': typeof LayoutPagesProtectedTopicsIndexRoute '/topics': typeof LayoutPagesProtectedTopicsIndexRoute
@@ -452,6 +451,7 @@ export interface FileRoutesById {
'/_layout/_pages/_protected': typeof LayoutPagesProtectedRouteWithChildren '/_layout/_pages/_protected': typeof LayoutPagesProtectedRouteWithChildren
'/_layout/(landing)/': typeof LayoutlandingIndexRoute '/_layout/(landing)/': typeof LayoutlandingIndexRoute
'/_layout/_pages/(topic)/$': typeof LayoutPagestopicSplatRoute '/_layout/_pages/(topic)/$': typeof LayoutPagestopicSplatRoute
'/_layout/_pages/search/': typeof LayoutPagesSearchIndexRoute
'/_layout/(auth)/_auth/sign-in/$': typeof LayoutauthAuthSignInSplatRoute '/_layout/(auth)/_auth/sign-in/$': typeof LayoutauthAuthSignInSplatRoute
'/_layout/(auth)/_auth/sign-up/$': typeof LayoutauthAuthSignUpSplatRoute '/_layout/(auth)/_auth/sign-up/$': typeof LayoutauthAuthSignUpSplatRoute
'/_layout/_pages/_protected/journals/': typeof LayoutPagesProtectedJournalsIndexRoute '/_layout/_pages/_protected/journals/': typeof LayoutPagesProtectedJournalsIndexRoute
@@ -459,7 +459,6 @@ export interface FileRoutesById {
'/_layout/_pages/_protected/onboarding/': typeof LayoutPagesProtectedOnboardingIndexRoute '/_layout/_pages/_protected/onboarding/': typeof LayoutPagesProtectedOnboardingIndexRoute
'/_layout/_pages/_protected/pages/': typeof LayoutPagesProtectedPagesIndexRoute '/_layout/_pages/_protected/pages/': typeof LayoutPagesProtectedPagesIndexRoute
'/_layout/_pages/_protected/profile/': typeof LayoutPagesProtectedProfileIndexRoute '/_layout/_pages/_protected/profile/': typeof LayoutPagesProtectedProfileIndexRoute
'/_layout/_pages/_protected/search/': typeof LayoutPagesProtectedSearchIndexRoute
'/_layout/_pages/_protected/settings/': typeof LayoutPagesProtectedSettingsIndexRoute '/_layout/_pages/_protected/settings/': typeof LayoutPagesProtectedSettingsIndexRoute
'/_layout/_pages/_protected/tasks/': typeof LayoutPagesProtectedTasksIndexRoute '/_layout/_pages/_protected/tasks/': typeof LayoutPagesProtectedTasksIndexRoute
'/_layout/_pages/_protected/topics/': typeof LayoutPagesProtectedTopicsIndexRoute '/_layout/_pages/_protected/topics/': typeof LayoutPagesProtectedTopicsIndexRoute
@@ -473,6 +472,7 @@ export interface FileRouteTypes {
| '' | ''
| '/' | '/'
| '/$' | '/$'
| '/search'
| '/sign-in/$' | '/sign-in/$'
| '/sign-up/$' | '/sign-up/$'
| '/journals' | '/journals'
@@ -480,7 +480,6 @@ export interface FileRouteTypes {
| '/onboarding' | '/onboarding'
| '/pages' | '/pages'
| '/profile' | '/profile'
| '/search'
| '/settings' | '/settings'
| '/tasks' | '/tasks'
| '/topics' | '/topics'
@@ -491,6 +490,7 @@ export interface FileRouteTypes {
| '' | ''
| '/' | '/'
| '/$' | '/$'
| '/search'
| '/sign-in/$' | '/sign-in/$'
| '/sign-up/$' | '/sign-up/$'
| '/journals' | '/journals'
@@ -498,7 +498,6 @@ export interface FileRouteTypes {
| '/onboarding' | '/onboarding'
| '/pages' | '/pages'
| '/profile' | '/profile'
| '/search'
| '/settings' | '/settings'
| '/tasks' | '/tasks'
| '/topics' | '/topics'
@@ -513,6 +512,7 @@ export interface FileRouteTypes {
| '/_layout/_pages/_protected' | '/_layout/_pages/_protected'
| '/_layout/(landing)/' | '/_layout/(landing)/'
| '/_layout/_pages/(topic)/$' | '/_layout/_pages/(topic)/$'
| '/_layout/_pages/search/'
| '/_layout/(auth)/_auth/sign-in/$' | '/_layout/(auth)/_auth/sign-in/$'
| '/_layout/(auth)/_auth/sign-up/$' | '/_layout/(auth)/_auth/sign-up/$'
| '/_layout/_pages/_protected/journals/' | '/_layout/_pages/_protected/journals/'
@@ -520,7 +520,6 @@ export interface FileRouteTypes {
| '/_layout/_pages/_protected/onboarding/' | '/_layout/_pages/_protected/onboarding/'
| '/_layout/_pages/_protected/pages/' | '/_layout/_pages/_protected/pages/'
| '/_layout/_pages/_protected/profile/' | '/_layout/_pages/_protected/profile/'
| '/_layout/_pages/_protected/search/'
| '/_layout/_pages/_protected/settings/' | '/_layout/_pages/_protected/settings/'
| '/_layout/_pages/_protected/tasks/' | '/_layout/_pages/_protected/tasks/'
| '/_layout/_pages/_protected/topics/' | '/_layout/_pages/_protected/topics/'
@@ -565,7 +564,8 @@ export const routeTree = rootRoute
"parent": "/_layout", "parent": "/_layout",
"children": [ "children": [
"/_layout/_pages/_protected", "/_layout/_pages/_protected",
"/_layout/_pages/(topic)/$" "/_layout/_pages/(topic)/$",
"/_layout/_pages/search/"
] ]
}, },
"/_layout/(auth)": { "/_layout/(auth)": {
@@ -592,7 +592,6 @@ export const routeTree = rootRoute
"/_layout/_pages/_protected/onboarding/", "/_layout/_pages/_protected/onboarding/",
"/_layout/_pages/_protected/pages/", "/_layout/_pages/_protected/pages/",
"/_layout/_pages/_protected/profile/", "/_layout/_pages/_protected/profile/",
"/_layout/_pages/_protected/search/",
"/_layout/_pages/_protected/settings/", "/_layout/_pages/_protected/settings/",
"/_layout/_pages/_protected/tasks/", "/_layout/_pages/_protected/tasks/",
"/_layout/_pages/_protected/topics/", "/_layout/_pages/_protected/topics/",
@@ -608,6 +607,10 @@ export const routeTree = rootRoute
"filePath": "_layout/_pages/(topic)/$.tsx", "filePath": "_layout/_pages/(topic)/$.tsx",
"parent": "/_layout/_pages" "parent": "/_layout/_pages"
}, },
"/_layout/_pages/search/": {
"filePath": "_layout/_pages/search/index.tsx",
"parent": "/_layout/_pages"
},
"/_layout/(auth)/_auth/sign-in/$": { "/_layout/(auth)/_auth/sign-in/$": {
"filePath": "_layout/(auth)/_auth.sign-in.$.tsx", "filePath": "_layout/(auth)/_auth.sign-in.$.tsx",
"parent": "/_layout/(auth)/_auth" "parent": "/_layout/(auth)/_auth"
@@ -636,10 +639,6 @@ export const routeTree = rootRoute
"filePath": "_layout/_pages/_protected/profile/index.tsx", "filePath": "_layout/_pages/_protected/profile/index.tsx",
"parent": "/_layout/_pages/_protected" "parent": "/_layout/_pages/_protected"
}, },
"/_layout/_pages/_protected/search/": {
"filePath": "_layout/_pages/_protected/search/index.tsx",
"parent": "/_layout/_pages/_protected"
},
"/_layout/_pages/_protected/settings/": { "/_layout/_pages/_protected/settings/": {
"filePath": "_layout/_pages/_protected/settings/index.tsx", "filePath": "_layout/_pages/_protected/settings/index.tsx",
"parent": "/_layout/_pages/_protected" "parent": "/_layout/_pages/_protected"
@@ -1,5 +1,9 @@
import * as React from "react" import * as React from "react"
import { useAccount, useCoState } from "@/lib/providers/jazz-provider" import {
useAccount,
useAccountOrGuest,
useCoState,
} from "@/lib/providers/jazz-provider"
import { LaIcon } from "@/components/custom/la-icon" import { LaIcon } from "@/components/custom/la-icon"
import { Topic, PersonalLink, PersonalPage } from "@/lib/schema" import { Topic, PersonalLink, PersonalPage } from "@/lib/schema"
import { PublicGlobalGroup } from "@/lib/schema/master/public-group" import { PublicGlobalGroup } from "@/lib/schema/master/public-group"
@@ -8,7 +12,7 @@ import { createFileRoute } from "@tanstack/react-router"
import AiSearch from "~/components/custom/ai-search" import AiSearch from "~/components/custom/ai-search"
import { Link } from "@tanstack/react-router" import { Link } from "@tanstack/react-router"
export const Route = createFileRoute("/_layout/_pages/_protected/search/")({ export const Route = createFileRoute("/_layout/_pages/search/")({
component: () => <SearchComponent />, component: () => <SearchComponent />,
}) })
@@ -85,7 +89,7 @@ const SearchComponent = () => {
pages: PersonalPage[] pages: PersonalPage[]
}>({ topics: [], links: [], pages: [] }) }>({ topics: [], links: [], pages: [] })
const { me } = useAccount({ const { me } = useAccountOrGuest({
root: { personalLinks: [], personalPages: [] }, root: { personalLinks: [], personalPages: [] },
}) })
@@ -110,17 +114,21 @@ const SearchComponent = () => {
topic !== null && topic.prettyName.toLowerCase().startsWith(value), topic !== null && topic.prettyName.toLowerCase().startsWith(value),
) || [], ) || [],
links: links:
me?.root.personalLinks?.filter( me?._type === "Anonymous"
(link: PersonalLink | null): link is PersonalLink => ? []
link !== null && link.title.toLowerCase().startsWith(value), : me?.root.personalLinks?.filter(
) || [], (link: PersonalLink | null): link is PersonalLink =>
link !== null && link.title.toLowerCase().startsWith(value),
) || [],
pages: pages:
me?.root.personalPages?.filter( me?._type === "Anonymous"
(page): page is PersonalPage => ? []
page !== null && : me?.root.personalPages?.filter(
page.title !== undefined && (page): page is PersonalPage =>
page.title.toLowerCase().startsWith(value), page !== null &&
) || [], page.title !== undefined &&
page.title.toLowerCase().startsWith(value),
) || [],
}) })
} }