Skip to content

Commit

Permalink
Introduce path aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
svemat01 committed Dec 2, 2024
1 parent c615e4b commit 90a82a9
Show file tree
Hide file tree
Showing 26 changed files with 76 additions and 60 deletions.
9 changes: 6 additions & 3 deletions web/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@
"plugin:v3xlabs/recommended"
],
"ignorePatterns": [
"!**/*"
"!**/*",
"src/**/*.gen.ts"
],
"plugins": [
"v3xlabs"
],
"env": {
"browser": true
},
"rules": {}
}
"rules": {
"sonarjs/cognitive-complexity": "off"
}
}
9 changes: 5 additions & 4 deletions web/src/components/ActiveSessionsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import { clsx } from 'clsx';
import { FC } from 'react';
import { UAParser } from 'ua-parser-js';

import { useAuth } from '../api/auth';
import { useGeoIp } from '../api/geoip';
import { SessionResponse, useSessions } from '../api/sessions';
import { getRelativeTimeString } from '../util/date';
import { useAuth } from '@/api/auth';
import { useGeoIp } from '@/api/geoip';
import { SessionResponse, useSessions } from '@/api/sessions';
import { getRelativeTimeString } from '@/util/date';

import { LeafletPreview } from './LeafletPreview';

const ActiveSession: FC<{ session: SessionResponse }> = ({ session }) => {
Expand Down
5 changes: 3 additions & 2 deletions web/src/components/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import * as DropdownMenu from '@radix-ui/react-dropdown-menu';
import { Link } from '@tanstack/react-router';
import { FileRoutesByPath } from '@tanstack/react-router';

import { useAuth } from '../api/auth';
import { useApiMe } from '../api/me';
import { useAuth } from '@/api/auth';
import { useApiMe } from '@/api/me';

import { AvatarHolder, getInitials } from './UserProfile';

const LOGIN_URL = 'http://localhost:3000/login';
Expand Down
2 changes: 1 addition & 1 deletion web/src/components/Unauthorized.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SCPage } from '../layouts/SimpleCenterPage';
import { SCPage } from '@/layouts/SimpleCenterPage';

export const UnauthorizedResourceModal = () => {
return (
Expand Down
4 changes: 2 additions & 2 deletions web/src/components/UserProfile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import clsx from 'clsx';
import { FC } from 'react';
import { match } from 'ts-pattern';

import { ApiMeResponse, useApiMe } from '../api/me';
import { useApiUserById } from '../api/user';
import { ApiMeResponse, useApiMe } from '@/api/me';
import { useApiUserById } from '@/api/user';

type Properties = {
user_id: string;
Expand Down
3 changes: 2 additions & 1 deletion web/src/components/input/NewItemIdInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { useMutation } from '@tanstack/react-query';
import { useEffect, useState } from 'react';
import { FiRefreshCcw } from 'react-icons/fi';

import { BASE_URL } from '../../api/core';
import { BASE_URL } from '@/api/core';

import { BaseInput, BaseInputProperties } from './BaseInput';

const placeholderValues = ['000001', '123456', 'AA17C', 'ABCDEF', '000013'];
Expand Down
4 changes: 2 additions & 2 deletions web/src/components/item/ItemPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import clsx from 'clsx';
import { FC } from 'react';
import { match } from 'ts-pattern';

import { formatId, useInstanceSettings } from '../../api/instance_settings';
import { ApiItemResponse, useApiItemById } from '../../api/item';
import { formatId, useInstanceSettings } from '@/api/instance_settings';
import { ApiItemResponse, useApiItemById } from '@/api/item';

type Properties = {
item_id: string;
Expand Down
6 changes: 3 additions & 3 deletions web/src/components/media/MediaPreview.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { FC, Suspense, useState } from 'react';
import { match } from 'ts-pattern';

import { useMedia } from '../../api/media';
import { ErrorBoundary } from '../ErrorBoundary';
import { StlPreviewWindow } from '../stl_preview/StlPreview';
import { useMedia } from '@/api/media';
import { ErrorBoundary } from '@/components/ErrorBoundary';
import { StlPreviewWindow } from '@/components/stl_preview/StlPreview';

export const MediaPreview: FC<{ media_id: number }> = ({ media_id }) => {
const { data: media } = useMedia(media_id);
Expand Down
2 changes: 1 addition & 1 deletion web/src/components/owned_elements.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Link } from '@tanstack/react-router';

import { useApiOwnedItems } from '../api/item';
import { useApiOwnedItems } from '@/api/item';

export const AllOwnedItems = () => {
const { data } = useApiOwnedItems();
Expand Down
2 changes: 1 addition & 1 deletion web/src/components/search/SearchInput.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BaseInput } from '../input/BaseInput';
import { BaseInput } from '@/components/input/BaseInput';

export const SearchInput = () => {
return (
Expand Down
6 changes: 3 additions & 3 deletions web/src/components/search_tasks/SearchTaskTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import en from 'javascript-time-ago/locale/en';
import { useEffect } from 'react';
import { FiLoader } from 'react-icons/fi';

import { useAuth } from '../../api/auth';
import { BASE_URL } from '../../api/core';
import { SearchTask, useTasks } from '../../api/searchtasks';
import { useAuth } from '@/api/auth';
import { BASE_URL } from '@/api/core';
import { SearchTask, useTasks } from '@/api/searchtasks';

TimeAgo.addDefaultLocale(en);
const timeAgo = new TimeAgo('en-US');
Expand Down
6 changes: 3 additions & 3 deletions web/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import { createRouter, RouterProvider } from '@tanstack/react-router';
import React from 'react';
import ReactDOM from 'react-dom/client';

import { preflightAuth } from './api/auth';
import { preflightAuth } from '@/api/auth';
// Import the generated route tree
import { routeTree } from './routeTree.gen';
import { queryClient } from './util/query';
import { routeTree } from '@/routeTree.gen';
import { queryClient } from '@/util/query';

// Create a new router instance
const router = createRouter({ routeTree });
Expand Down
2 changes: 1 addition & 1 deletion web/src/routes/__root.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createRootRoute, Outlet } from '@tanstack/react-router';

import { Navbar } from '../components/Navbar';
import { Navbar } from '@/components/Navbar';

export const Route = createRootRoute({
component: () => (
Expand Down
10 changes: 5 additions & 5 deletions web/src/routes/create.lazy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import { useForm } from '@tanstack/react-form';
import { createLazyFileRoute, useNavigate } from '@tanstack/react-router';
import { FiArrowRight } from 'react-icons/fi';

import { isValidId } from '../api/generate_id';
import { formatId, useInstanceSettings } from '../api/instance_settings';
import { useApiCreateItem } from '../api/item';
import { NewItemIdInput } from '../components/input/NewItemIdInput';
import { SCPage } from '../layouts/SimpleCenterPage';
import { isValidId } from '@/api/generate_id';
import { formatId, useInstanceSettings } from '@/api/instance_settings';
import { useApiCreateItem } from '@/api/item';
import { NewItemIdInput } from '@/components/input/NewItemIdInput';
import { SCPage } from '@/layouts/SimpleCenterPage';

const component = () => {
const { data: instanceSettings } = useInstanceSettings();
Expand Down
8 changes: 4 additions & 4 deletions web/src/routes/index.lazy.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { createLazyFileRoute } from '@tanstack/react-router';

import { ItemPreview } from '../components/item/ItemPreview';
import { SearchTaskTable } from '../components/search_tasks/SearchTaskTable';
import { UserProfile } from '../components/UserProfile';
import { SCPage } from '../layouts/SimpleCenterPage';
import { ItemPreview } from '@/components/item/ItemPreview';
import { SearchTaskTable } from '@/components/search_tasks/SearchTaskTable';
import { UserProfile } from '@/components/UserProfile';
import { SCPage } from '@/layouts/SimpleCenterPage';

const component = () => {
return (
Expand Down
4 changes: 2 additions & 2 deletions web/src/routes/item/$itemId/edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import {
} from '@tanstack/react-router';
import { FC } from 'react';

import { useApiDeleteItem } from '../../../api/item';
import { SCPage } from '../../../layouts/SimpleCenterPage';
import { useApiDeleteItem } from '@/api/item';
import { SCPage } from '@/layouts/SimpleCenterPage';

export const DeleteItemModal: FC<{ itemId: string }> = ({ itemId }) => {
const { mutate: deleteItem } = useApiDeleteItem();
Expand Down
14 changes: 7 additions & 7 deletions web/src/routes/item/$itemId/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import {
useParams,
} from '@tanstack/react-router';

import { formatId, getInstanceSettings } from '../../../api/instance_settings';
import { useApiItemById } from '../../../api/item';
import { MediaGallery } from '../../../components/media/MediaGallery';
import { UnauthorizedResourceModal } from '../../../components/Unauthorized';
import { UserProfile } from '../../../components/UserProfile';
import { SCPage } from '../../../layouts/SimpleCenterPage';
import { queryClient } from '../../../util/query';
import { formatId, getInstanceSettings } from '@/api/instance_settings';
import { useApiItemById } from '@/api/item';
import { MediaGallery } from '@/components/media/MediaGallery';
import { UnauthorizedResourceModal } from '@/components/Unauthorized';
import { UserProfile } from '@/components/UserProfile';
import { SCPage } from '@/layouts/SimpleCenterPage';
import { queryClient } from '@/util/query';

export const Route = createFileRoute('/item/$itemId/')({
// if item_id is not formatId(item_id, instanceSettings), redirect to the formatted item_id
Expand Down
4 changes: 2 additions & 2 deletions web/src/routes/items/index.lazy.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createLazyFileRoute } from '@tanstack/react-router';

import { AllOwnedItems } from '../../components/owned_elements';
import { SCPage } from '../../layouts/SimpleCenterPage';
import { AllOwnedItems } from '@/components/owned_elements';
import { SCPage } from '@/layouts/SimpleCenterPage';

export const Route = createLazyFileRoute('/items/')({
component: () => (
Expand Down
2 changes: 1 addition & 1 deletion web/src/routes/logs/index.lazy.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createLazyFileRoute } from '@tanstack/react-router';

import { SCPage } from '../../layouts/SimpleCenterPage';
import { SCPage } from '@/layouts/SimpleCenterPage';

export const Route = createLazyFileRoute('/logs/')({
component: () => (
Expand Down
2 changes: 1 addition & 1 deletion web/src/routes/products/index.lazy.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createLazyFileRoute } from '@tanstack/react-router';

import { SCPage } from '../../layouts/SimpleCenterPage';
import { SCPage } from '@/layouts/SimpleCenterPage';

export const Route = createLazyFileRoute('/products/')({
component: () => (
Expand Down
4 changes: 2 additions & 2 deletions web/src/routes/search/index.lazy.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createLazyFileRoute, Link } from '@tanstack/react-router';

import { SearchInput } from '../../components/search/SearchInput';
import { SCPage } from '../../layouts/SimpleCenterPage';
import { SearchInput } from '@/components/search/SearchInput';
import { SCPage } from '@/layouts/SimpleCenterPage';

export const Route = createLazyFileRoute('/search/')({
component: () => (
Expand Down
6 changes: 3 additions & 3 deletions web/src/routes/sessions.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { createFileRoute } from '@tanstack/react-router';
import { FC } from 'react';

import { useAuth } from '../api/auth';
import { ActiveSessionsTable } from '../components/ActiveSessionsTable';
import { SCPage } from '../layouts/SimpleCenterPage';
import { useAuth } from '@/api/auth';
import { ActiveSessionsTable } from '@/components/ActiveSessionsTable';
import { SCPage } from '@/layouts/SimpleCenterPage';

const component: FC = () => {
return (
Expand Down
2 changes: 1 addition & 1 deletion web/src/routes/settings/index.lazy.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createLazyFileRoute } from '@tanstack/react-router';

import { SCPage } from '../../layouts/SimpleCenterPage';
import { SCPage } from '@/layouts/SimpleCenterPage';

export const Route = createLazyFileRoute('/settings/')({
component: () => (
Expand Down
4 changes: 2 additions & 2 deletions web/src/routes/user/$userId.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createFileRoute, useParams } from '@tanstack/react-router';

import { useApiUserById } from '../../api/user';
import { SCPage } from '../../layouts/SimpleCenterPage';
import { useApiUserById } from '@/api/user';
import { SCPage } from '@/layouts/SimpleCenterPage';

export const Route = createFileRoute('/user/$userId')({
component: () => {
Expand Down
7 changes: 6 additions & 1 deletion web/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@

/* Completeness */
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
"skipLibCheck": true /* Skip type checking all .d.ts files. */
"skipLibCheck": true, /* Skip type checking all .d.ts files. */
"paths": {
"@/*": [
"./src/*"
]
}
}
}
9 changes: 7 additions & 2 deletions web/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import { TanStackRouterVite } from '@tanstack/router-plugin/vite';
import react from '@vitejs/plugin-react';
import { defineConfig } from 'vite';

// https://vitejs.dev/config/
export default defineConfig({
plugins: [TanStackRouterVite(), react()],
resolve: {
alias: {
'@': new URL('src', import.meta.url).pathname,
},
},
});

0 comments on commit 90a82a9

Please sign in to comment.