Skip to content
Draft
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 convex/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ export default defineSchema({
'by_owner_status', ['owner', 'status'],
).index(
'by_owner_energyAvailable', ['owner', 'energyBudget.available'],
).searchIndex(
'search_tasks', {
searchField: 'title',
filterFields: ['owner'],
}
),
// .index(
// 'by_embeddingId', ['embeddingId'],
Expand Down
12 changes: 11 additions & 1 deletion convex/tasks/public.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,21 @@ export const findAll = query({
export const findAllPaginated = query({
args: {
paginationOpts: paginationOptionsSchema,
search: z.string().optional(),
},
handler: async (ctx, { paginationOpts }) => {
handler: async (ctx, { paginationOpts, search }) => {
//
const currentUser = await getCurrentUser(ctx, {});

// Use search index if search term is provided
if (search && search.trim()) {
return await ctx.db
.query('tasks')
.withSearchIndex('search_tasks', (q) => q.search('title', search.trim()).eq('owner', currentUser._id))
.paginate(paginationOpts);
}

// Default query sorted by available budget (descending, highest first)
return await ctx.db
.query('tasks')
.withIndex('by_owner_energyAvailable', (q) => q.eq('owner', currentUser._id))
Expand Down
22 changes: 19 additions & 3 deletions src/components/CommandMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,27 @@ export function CommandMenuDialog() {
setSearch(pathname + searchStr);
}, [pathname, searchStr]);

const shouldFilter = useMemo(() => {
const isSearching = useMemo(() => {
return search !== pathname + searchStr;
}, [search, pathname, searchStr]);

const searchQuery = useMemo(() => {
//
if (!isSearching) return undefined;

return search;
//
}, [isSearching, search]);

const shouldFilter = useMemo(() => {
//
// Disable client-side filtering when doing server-side search
if (searchQuery) return false;

return isSearching;
//
}, [searchQuery, isSearching]);

const onSelect = useCallback(
(value: string) => {
close();
Expand All @@ -134,14 +151,13 @@ export function CommandMenuDialog() {

// TODO: implement FN+Up/Down to navigate through the list

// TODO: server-side search
const {
results: tasks,
status: paginationStatus,
loadMore,
} = usePaginatedQuery(
api.tasks.public.findAllPaginated,
{ paginationOpts: { numItems: PAGE_SIZE, cursor: null } },
{ search: searchQuery },
{ initialNumItems: PAGE_SIZE },
);

Expand Down