🎨(frontend) Minor refactoring

- improve condition statements
- add "no-var" rule in eslint
- remove some unnecessary variables

Signed-off-by: Zorin95670 <moittie.vincent@gmail.com>
This commit is contained in:
Zorin95670
2025-05-07 12:04:08 +02:00
committed by Anthony LC
parent e5f029ad1d
commit 4d541c5d52
10 changed files with 11 additions and 26 deletions

View File

@@ -48,10 +48,7 @@ const nextConfig = {
swDest: '../public/service-worker.js', swDest: '../public/service-worker.js',
include: [ include: [
({ asset }) => { ({ asset }) => {
if (asset.name.match(/.*(static).*/)) { return !!asset.name.match(/.*(static).*/);
return true;
}
return false;
}, },
], ],
}), }),

View File

@@ -23,11 +23,9 @@ export const fetchAPI = async (
delete headers?.['Content-Type' as keyof typeof headers]; delete headers?.['Content-Type' as keyof typeof headers];
} }
const response = await fetch(apiUrl, { return await fetch(apiUrl, {
...init, ...init,
credentials: 'include', credentials: 'include',
headers, headers,
}); });
return response;
}; };

View File

@@ -35,8 +35,7 @@ export function AppProvider({ children }: { children: React.ReactNode }) {
); );
useEffect(() => { useEffect(() => {
const cleanupResizeListener = initializeResizeListener(); return initializeResizeListener();
return cleanupResizeListener;
}, [initializeResizeListener]); }, [initializeResizeListener]);
useEffect(() => { useEffect(() => {

View File

@@ -53,13 +53,11 @@ export function useConfig() {
const cachedData = getCachedTranslation(); const cachedData = getCachedTranslation();
const oneHour = 1000 * 60 * 60; const oneHour = 1000 * 60 * 60;
const response = useQuery<ConfigResponse, APIError, ConfigResponse>({ return useQuery<ConfigResponse, APIError, ConfigResponse>({
queryKey: [KEY_CONFIG], queryKey: [KEY_CONFIG],
queryFn: () => getConfig(), queryFn: () => getConfig(),
initialData: cachedData, initialData: cachedData,
staleTime: oneHour, staleTime: oneHour,
initialDataUpdatedAt: Date.now() - oneHour, // Force initial data to be considered stale initialDataUpdatedAt: Date.now() - oneHour, // Force initial data to be considered stale
}); });
return response;
} }

View File

@@ -31,7 +31,7 @@ const useSaveDoc = (docId: string, yDoc: Y.Doc, canSave: boolean) => {
_updatedDoc: Y.Doc, _updatedDoc: Y.Doc,
transaction: Y.Transaction, transaction: Y.Transaction,
) => { ) => {
setIsLocalChange(transaction.local ? true : false); setIsLocalChange(transaction.local);
}; };
yDoc.on('update', onUpdate); yDoc.on('update', onUpdate);

View File

@@ -25,14 +25,10 @@ export class PostHogAnalytic extends AbstractAnalytic {
} }
public isFeatureFlagActivated(flagName: string): boolean { public isFeatureFlagActivated(flagName: string): boolean {
if ( return !(
posthog.featureFlags.getFlags().includes(flagName) && posthog.featureFlags.getFlags().includes(flagName) &&
posthog.isFeatureEnabled(flagName) === false posthog.isFeatureEnabled(flagName) === false
) { );
return false;
}
return true;
} }
} }

View File

@@ -40,11 +40,7 @@ export function isSafeUrl(url: string): boolean {
} }
// Check for directory traversal attempts // Check for directory traversal attempts
if (url.includes('..') || url.includes('../') || url.includes('..\\')) { return !(url.includes('..') || url.includes('../') || url.includes('..\\'));
return false;
}
return true;
} catch { } catch {
return false; return false;
} }

View File

@@ -56,6 +56,7 @@ const globalRules = {
'error', 'error',
{ varsIgnorePattern: '^_', argsIgnorePattern: '^_' }, { varsIgnorePattern: '^_', argsIgnorePattern: '^_' },
], ],
'no-var': 'error',
'react/jsx-curly-brace-presence': [ 'react/jsx-curly-brace-presence': [
'error', 'error',
{ props: 'never', children: 'never', propElementValues: 'always' }, { props: 'never', children: 'never', propElementValues: 'always' },

View File

@@ -13,5 +13,5 @@ module.exports = {
rules: { rules: {
'@next/next/no-html-link-for-pages': 'off', '@next/next/no-html-link-for-pages': 'off',
}, },
ignorePatterns: ['node_modules', '.eslintrc.js'], ignorePatterns: ['node_modules'],
}; };

View File

@@ -1,4 +1,4 @@
var config = { const config = {
rootDir: './__tests__', rootDir: './__tests__',
testEnvironment: 'node', testEnvironment: 'node',
transform: { transform: {