Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updates #332

Merged
merged 5 commits into from
Jan 6, 2025
Merged
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
7 changes: 4 additions & 3 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"scripts": {
"quick": "cross-env PGLITE=true tsx scripts/quick.ts && cross-env PGLITE=true pnpm dev",
"start": "tsx dist/index.js",
"dev": "pnpm run studio & tsup --watch --onSuccess \"tsx dist/index.js\"",
"dev": "concurrently \"pnpm run studio\" \"tsup --watch --onSuccess \\\"tsx dist/index.js\\\"\"",
"check:types": "tsc",
"build": "cross-env NODE_ENV=production tsup",
"build:dev": "tsup",
Expand Down Expand Up @@ -36,7 +36,7 @@
"@electric-sql/pglite": "^0.2.15",
"@hono/node-server": "^1.13.7",
"@hono/sentry": "^1.2.0",
"@hono/zod-openapi": "0.16.4",
"@hono/zod-openapi": "0.18.3",
"@logtail/node": "^0.5.2",
"@lucia-auth/adapter-drizzle": "^1.1.0",
"@lucia-auth/adapter-postgresql": "^3.1.2",
Expand Down Expand Up @@ -100,7 +100,8 @@
"papaparse": "^5.4.1",
"tsup": "^8.3.5",
"tsx": "^4.19.2",
"typescript": "^5.7.2"
"typescript": "^5.7.2",
"concurrently": "^9.1.2"
},
"imports": {
"#/*": ["./dist/src/*"]
Expand Down
16 changes: 4 additions & 12 deletions backend/src/lib/route-config.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,22 @@
import { createRoute } from '@hono/zod-openapi';
import type { MiddlewareHandler } from 'hono';
import type { Env } from '#/types/app';
import type { NonEmptyArray } from '#/types/common';

export type RouteOptions = Parameters<typeof createRoute>[0] & {
guard: MiddlewareHandler | NonEmptyArray<MiddlewareHandler>;
middleware?: MiddlewareHandler<Env> | NonEmptyArray<MiddlewareHandler<Env>>;
};

export type RouteConfig = {
route: ReturnType<typeof createRoute>;
guard: RouteOptions['guard'];
};

export type Route<
P extends string,
R extends Omit<RouteOptions, 'path'> & {
path: P;
},
> = ReturnType<typeof createRoute<P, Omit<R, 'guard'>>>;
export type Route<P extends string, R extends Omit<RouteOptions, 'path'> & { path: P }> = ReturnType<typeof createRoute<P, Omit<R, 'guard'>>>;

// Custom wrapper around hono createRoute to extend it with setting guard and other middleware.
export const createRouteConfig = <
P extends string,
R extends Omit<RouteOptions, 'path'> & {
path: P;
},
>({
export const createRouteConfig = <P extends string, R extends Omit<RouteOptions, 'path'> & { path: P }>({
guard,
...routeConfig
}: R): Route<P, R> => {
Expand Down
66 changes: 0 additions & 66 deletions frontend/src/api/me.ts

This file was deleted.

75 changes: 0 additions & 75 deletions frontend/src/api/users.ts

This file was deleted.

2 changes: 1 addition & 1 deletion frontend/src/hooks/use-mutations.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { type UseMutationOptions, type UseMutationResult, useMutation as useBaseMutation } from '@tanstack/react-query';
import type { ApiError } from '~/api';
import type { ApiError } from '~/lib/api';

export const useMutation = <TData = unknown, TError = ApiError, TVariables = void, TContext = unknown>(
options: UseMutationOptions<TData, TError, TVariables, TContext>,
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion frontend/src/lib/imado.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { type UploadResult, Uppy, type UppyFile, type UppyOptions } from '@uppy/core';
import Tus from '@uppy/tus';
import { config } from 'config';
import { getUploadToken } from '~/api/general';
import { getUploadToken } from '~/modules/general/api';
import type { UploadParams, UploadType, UploadedUppyFile } from '~/types/common';

import '@uppy/core/dist/style.min.css';
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/lib/query-client.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { type FetchInfiniteQueryOptions, type FetchQueryOptions, onlineManager } from '@tanstack/react-query';
import i18next from 'i18next';
import { ApiError } from '~/api';
import { ApiError } from '~/lib/api';
import { i18n } from '~/lib/i18n';
import router, { queryClient } from '~/lib/router';
import { flushStoresAndCache } from '~/modules/auth/sign-out';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { config } from 'config';
import { clientConfig, handleResponse } from '~/lib/api';
import { attachmentsHc } from '#/modules/attachments/hc';
import { clientConfig, handleResponse } from '.';

// Create Hono clients to make requests to the backend
export const client = attachmentsHc(config.backendUrl, clientConfig);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import { useMutation } from '@tanstack/react-query';
import { config } from 'config';
import { t } from 'i18next';
import { toast } from 'sonner';
import { createAttachment, deleteAttachments, updateAttachment } from '~/api/attachments';
import { queryClient } from '~/lib/router';
import { createAttachment, deleteAttachments, updateAttachment } from '~/modules/attachments/api';
import { attachmentsKeys } from '~/modules/attachments/query';
import { compareQueryKeys } from '~/query/helpers';
import { formatUpdatedData, getCancelingRefetchQueries, getQueries, getQueryItems, handleNoOldData } from '~/query/helpers/mutate-query';
import { attachmentsKeys } from '~/query/query-key-factories';
import type { ContextProp, InfiniteQueryData, QueryData } from '~/query/types';
import type { Attachment } from '~/types/common';
import { nanoid } from '~/utils/nanoid';
Expand Down
38 changes: 38 additions & 0 deletions frontend/src/modules/attachments/query.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { infiniteQueryOptions } from '@tanstack/react-query';
import { config } from 'config';

import { type GetAttachmentsParams, getAttachments } from '~/modules/attachments/api';

// Keys for attachments queries
export const attachmentsKeys = {
all: ['attachments'] as const,
list: () => [...attachmentsKeys.all, 'list'] as const,
table: (filters?: GetAttachmentsParams) => [...attachmentsKeys.list(), filters] as const,
similar: (filters?: Pick<GetAttachmentsParams, 'orgIdOrSlug'>) => [...attachmentsKeys.list(), filters] as const,
create: () => [...attachmentsKeys.all, 'create'] as const,
update: () => [...attachmentsKeys.all, 'update'] as const,
delete: () => [...attachmentsKeys.all, 'delete'] as const,
};

// Infinite Query Options to get a paginated list of attachments
export const attachmentsQueryOptions = ({
orgIdOrSlug,
q = '',
sort: initialSort,
order: initialOrder,
limit = config.requestLimits.attachments,
}: GetAttachmentsParams) => {
const sort = initialSort || 'createdAt';
const order = initialOrder || 'desc';

const queryKey = attachmentsKeys.table({ orgIdOrSlug, q, sort, order });

return infiniteQueryOptions({
queryKey,
initialPageParam: 0,
retry: 1,
refetchOnWindowFocus: false,
queryFn: async ({ pageParam: page, signal }) => await getAttachments({ page, q, sort, order, limit, orgIdOrSlug, offset: page * limit }, signal),
getNextPageParam: (_lastPage, allPages) => allPages.length,
});
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { TFunction } from 'i18next';
import { CopyCheckIcon, CopyIcon } from 'lucide-react';
import { useCopyToClipboard } from '~/hooks/use-copy-to-clipboard';
import AttachmentThumb from '~/modules/attachments/attachment-thumb';
import { formatBytes } from '~/modules/attachments/attachments-table/helpers';
import { formatBytes } from '~/modules/attachments/table/helpers';
import CheckboxColumn from '~/modules/common/data-table/checkbox-column';
import type { ColumnOrColumnGroup } from '~/modules/common/data-table/columns-view';
import HeaderCell from '~/modules/common/data-table/header-cell';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { onlineManager } from '@tanstack/react-query';
import { t } from 'i18next';
import { Suspense } from 'react';
import { createToast } from '~/lib/toasts';
import { useAttachmentCreateMutation } from '~/modules/attachments/query-mutations';
import UploadUppy from '~/modules/attachments/upload/upload-uppy';
import { dialog } from '~/modules/common/dialoger/state';
import { useAttachmentCreateMutation } from '~/query/mutations/attachments';
import { UploadType, type UploadedUppyFile } from '~/types/common';
import { nanoid } from '~/utils/nanoid';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { config } from 'config';
import { useEffect } from 'react';
import { queryClient } from '~/lib/router';

import type { AttachmentInfiniteQueryData } from '~/query/mutations/attachments';
import type { AttachmentInfiniteQueryData } from '~/modules/attachments/query-mutations';

import { env } from '~/../env';
import { useOnlineManager } from '~/hooks/use-online-manager';
import { attachmentsQueryOptions } from '~/query/infinite-query-options';
import { attachmentsQueryOptions } from '~/modules/attachments/query';
import type { Attachment } from '~/types/common';
import { objectKeys } from '~/utils/object';
import { attachmentsTableColumns } from '#/db/schema/attachments';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ import type { z } from 'zod';
import { useTranslation } from 'react-i18next';
import useSearchParams from '~/hooks/use-search-params';
import { createToast } from '~/lib/toasts';
import RemoveAttachmentsForm from '~/modules/attachments/attachments-table/remove-attachments-form';
import { AttachmentsTableHeader } from '~/modules/attachments/attachments-table/table-header';
import RemoveAttachmentsForm from '~/modules/attachments/table/remove-attachments-form';
import { AttachmentsTableHeader } from '~/modules/attachments/table/table-header';
import type { ColumnOrColumnGroup } from '~/modules/common/data-table/columns-view';
import { useSortColumns } from '~/modules/common/data-table/sort-columns';
import { dialog } from '~/modules/common/dialoger/state';
import type { attachmentsSearchSchema } from '~/routes/organizations';
import type { Attachment, BaseTableMethods, Organization } from '~/types/common';
import { arraysHaveSameElements } from '~/utils';

const BaseDataTable = lazy(() => import('~/modules/attachments/attachments-table/table'));
const BaseDataTable = lazy(() => import('~/modules/attachments/table/table'));
const LIMIT = config.requestLimits.attachments;

export type AttachmentSearch = z.infer<typeof attachmentsSearchSchema>;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useAttachmentDeleteMutation } from '~/modules/attachments/query-mutations';
import { DeleteForm } from '~/modules/common/delete-form';
import { dialog } from '~/modules/common/dialoger/state';
import { useAttachmentDeleteMutation } from '~/query/mutations/attachments';
import type { Attachment } from '~/types/common';

interface Props {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { motion } from 'framer-motion';
import { Trash, Upload, XSquare } from 'lucide-react';
import { useTranslation } from 'react-i18next';
import type { AttachmentSearch, AttachmentsTableProps } from '~/modules/attachments/attachments-table';
import { openUploadDialog } from '~/modules/attachments/attachments-table/helpers';
import type { AttachmentSearch, AttachmentsTableProps } from '~/modules/attachments/table';
import { openUploadDialog } from '~/modules/attachments/table/helpers';
import ColumnsView from '~/modules/common/data-table/columns-view';
import TableCount from '~/modules/common/data-table/table-count';
import { FilterBarActions, FilterBarContent, TableFilterBar } from '~/modules/common/data-table/table-filter-bar';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ import { Paperclip } from 'lucide-react';
import type { RowsChangeData } from 'react-data-grid';
import { useTranslation } from 'react-i18next';
import { useBreakpoints } from '~/hooks/use-breakpoints';
import type { AttachmentSearch, AttachmentsTableProps } from '~/modules/attachments/attachments-table';
import { useColumns } from '~/modules/attachments/attachments-table/columns';
import { useSync } from '~/modules/attachments/attachments-table/helpers/use-sync';
import { openAttachmentDialog } from '~/modules/attachments/helpers';
import { attachmentsQueryOptions } from '~/modules/attachments/query';
import { useAttachmentUpdateMutation } from '~/modules/attachments/query-mutations';
import type { AttachmentSearch, AttachmentsTableProps } from '~/modules/attachments/table';
import { useColumns } from '~/modules/attachments/table/columns';
import { useSync } from '~/modules/attachments/table/helpers/use-sync';
import ContentPlaceholder from '~/modules/common/content-placeholder';
import { DataTable } from '~/modules/common/data-table';
import type { ColumnOrColumnGroup } from '~/modules/common/data-table/columns-view';
import { dialog } from '~/modules/common/dialoger/state';
import { useDataFromSuspenseInfiniteQuery } from '~/query/hooks/use-data-from-query';
import { attachmentsQueryOptions } from '~/query/infinite-query-options';
import { useAttachmentUpdateMutation } from '~/query/mutations/attachments';
import { useUserStore } from '~/store/user';
import type { Attachment, BaseTableMethods, BaseTableProps } from '~/types/common';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { config } from 'config';
import { clientConfig, handleResponse } from '~/lib/api';
import { authHc } from '#/modules/auth/hc';
import { clientConfig, handleResponse } from '.';

// Create Hono clients to make requests to the backend
export const client = authHc(config.backendUrl, clientConfig);
Expand Down
Loading
Loading