generated from TBD54566975/tbd-project-template
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add tanstack query to frontend
- Loading branch information
1 parent
0be0d0a
commit 5221781
Showing
18 changed files
with
500 additions
and
55 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
module.exports = { | ||
env: { | ||
browser: true, | ||
es2021: true, | ||
}, | ||
extends: [ | ||
'eslint:recommended', | ||
'plugin:@typescript-eslint/recommended', | ||
'plugin:react/recommended', | ||
'plugin:storybook/recommended', | ||
], | ||
overrides: [ | ||
{ | ||
env: { | ||
node: true, | ||
}, | ||
files: ['.eslintrc.{js,cjs}'], | ||
parserOptions: { | ||
sourceType: 'script', | ||
}, | ||
}, | ||
], | ||
parser: '@typescript-eslint/parser', | ||
parserOptions: { | ||
ecmaVersion: 'latest', | ||
sourceType: 'module', | ||
}, | ||
plugins: ['@typescript-eslint', 'react'], | ||
rules: { | ||
'semi': ['error', 'never'], | ||
'quotes': ['error', 'single', { 'avoidEscape': true, 'allowTemplateLiterals': true }], | ||
'jsx-quotes': ['error', 'prefer-single'], | ||
'no-trailing-spaces': 'error', | ||
'no-multiple-empty-lines': ['error', { 'max': 1, 'maxEOF': 0, 'maxBOF': 0 }], | ||
'eol-last': ['error', 'always'], | ||
'max-len': ['error', { 'code': 120, 'tabWidth': 4, 'ignoreUrls': true, 'ignoreComments': false, 'ignoreRegExpLiterals': true, 'ignoreStrings': true, 'ignoreTemplateLiterals': true }], | ||
'react/react-in-jsx-scope': 'off', | ||
'react/jsx-uses-react': 'off', | ||
'func-style': ['error', 'expression'], | ||
'react/prop-types': 'off', | ||
'@typescript-eslint/consistent-type-definitions': ['error', 'interface'], | ||
'@typescript-eslint/no-unused-vars': ['warn', { argsIgnorePattern: '^_', varsIgnorePattern: '^_' }], | ||
'@typescript-eslint/ban-ts-comment': [ | ||
'error', | ||
{ | ||
'ts-ignore': 'allow-with-description', | ||
}, | ||
], | ||
'indent': ['error', 2, { | ||
'SwitchCase': 1, | ||
'VariableDeclarator': 1, | ||
'outerIIFEBody': 1, | ||
'MemberExpression': 1, | ||
'FunctionDeclaration': { | ||
'parameters': 1, | ||
'body': 1, | ||
}, | ||
'FunctionExpression': { | ||
'parameters': 1, | ||
'body': 1, | ||
}, | ||
'CallExpression': { | ||
'arguments': 1, | ||
}, | ||
'ArrayExpression': 1, | ||
'ObjectExpression': 1, | ||
'ImportDeclaration': 1, | ||
'flatTernaryExpressions': false, | ||
'ignoreComments': false, | ||
}], | ||
'react/jsx-indent': ['error', 2], | ||
'react/jsx-indent-props': ['error', 2], | ||
'no-multi-spaces': ['error'], | ||
}, | ||
settings: { | ||
react: { | ||
version: 'detect', | ||
}, | ||
}, | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,25 +1,5 @@ | ||
import { Navigate, Route, Routes } from 'react-router-dom' | ||
import { ConsolePage } from './features/console/ConsolePage.tsx' | ||
import { DeploymentPage } from './features/deployments/DeploymentPage.tsx' | ||
import { DeploymentsPage } from './features/deployments/DeploymentsPage.tsx' | ||
import { TimelinePage } from './features/timeline/TimelinePage.tsx' | ||
import { VerbPage } from './features/verbs/VerbPage.tsx' | ||
import { Layout } from './layout/Layout.tsx' | ||
import { NotFoundPage } from './layout/NotFoundPage.tsx' | ||
import { AppProvider } from './providers/app-providers.tsx' | ||
|
||
export const App = () => { | ||
return ( | ||
<Routes> | ||
<Route path='/' element={<Layout />}> | ||
<Route path='/' element={<Navigate to='events' replace />} /> | ||
<Route path='events' element={<TimelinePage />} /> | ||
|
||
<Route path='deployments' element={<DeploymentsPage />} /> | ||
<Route path='deployments/:deploymentKey' element={<DeploymentPage />} /> | ||
<Route path='deployments/:deploymentKey/verbs/:verbName' element={<VerbPage />} /> | ||
<Route path='console' element={<ConsolePage />} /> | ||
</Route> | ||
<Route path='*' element={<NotFoundPage />} /> | ||
</Routes> | ||
) | ||
return <AppProvider /> | ||
} |
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,45 @@ | ||
import { ConsoleService } from '../../protos/xyz/block/ftl/v1/console/console_connect' | ||
import { GetModulesResponse } from '../../protos/xyz/block/ftl/v1/console/console_pb' | ||
|
||
import { Code, ConnectError } from '@connectrpc/connect' | ||
import { useClient } from '../../hooks/use-client' | ||
|
||
const fetchModules = async (client: ConsoleService, isVisible: boolean): Promise<GetModulesResponse> => { | ||
if (!isVisible) { | ||
throw new Error('Component is not visible') | ||
} | ||
|
||
const abortController = new AbortController() | ||
|
||
try { | ||
const modules = await client.getModules({}, { signal: abortController.signal }) | ||
return modules ?? [] | ||
} catch (error) { | ||
if (error instanceof ConnectError) { | ||
if (error.code !== Code.Canceled) { | ||
console.error('fetchModules - Connect error:', error) | ||
} | ||
} else { | ||
console.error('fetchModules:', error) | ||
} | ||
throw error | ||
} finally { | ||
abortController.abort() | ||
} | ||
} | ||
|
||
export const useModules = () => { | ||
const client = useClient(ConsoleService) | ||
const isVisible = useVisibility() | ||
const schema = useSchema() | ||
|
||
return useQuery<GetModulesResponse>( | ||
['modules', schema, isVisible], // The query key, include schema and isVisible as dependencies | ||
() => fetchModules(client, isVisible), | ||
{ | ||
enabled: isVisible, // Only run the query when the component is visible | ||
refetchOnWindowFocus: false, // Optional: Disable refetching on window focus | ||
staleTime: 1000 * 60 * 5, // Optional: Cache data for 5 minutes | ||
} | ||
) | ||
} |
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
Oops, something went wrong.