Skip to content

Commit

Permalink
Fix lint and issues
Browse files Browse the repository at this point in the history
  • Loading branch information
tananaev committed Feb 25, 2024
1 parent 3106f6a commit 8bd7cba
Show file tree
Hide file tree
Showing 11 changed files with 62 additions and 55 deletions.
28 changes: 0 additions & 28 deletions modern/.eslintrc.js

This file was deleted.

37 changes: 37 additions & 0 deletions modern/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"extends": "airbnb",
"parserOptions": {
"ecmaVersion": 2020
},
"overrides": [{
"files": ["*.jsx", "*.js"]
}],
"plugins": [
"react"
],
"ignorePatterns": ["build/", "switcher.js", "theme.js"],
"rules": {
"max-len": [0],
"no-shadow": [0],
"no-return-assign": [0],
"no-param-reassign": [0],
"no-prototype-builtins": [0],
"object-curly-newline": [1, {
"ObjectExpression": { "minProperties": 8, "multiline": true, "consistent": true },
"ObjectPattern": { "minProperties": 8, "multiline": true, "consistent": true },
"ImportDeclaration": { "minProperties": 4, "multiline": true, "consistent": true },
"ExportDeclaration": { "minProperties": 4, "multiline": true, "consistent": true }
}],
"import/no-unresolved": [1, {
"ignore": ["\\.svg", "virtual:"]
}],
"react/function-component-definition": [1, {
"namedComponents": "arrow-function",
"unnamedComponents": "arrow-function"
}],
"react/jsx-props-no-spreading": [0],
"jsx-a11y/anchor-is-valid": [0],
"jsx-a11y/label-has-associated-control": [0],
"react/prop-types": [0]
}
}
2 changes: 1 addition & 1 deletion modern/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"build": "vite build",
"generate-pwa-assets": "pwa-assets-generator --preset minimal public/logo.svg",
"lint": "eslint .",
"lint:fix": "eslint --fix --ext .js ."
"lint:fix": "eslint --fix ."
},
"browserslist": {
"production": [
Expand Down
22 changes: 11 additions & 11 deletions modern/src/UpdateController.jsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Snackbar, IconButton } from '@mui/material';
import RefreshIcon from '@mui/icons-material/Refresh';
import React from 'react'
import React from 'react';
import { useSelector } from 'react-redux';
import { useRegisterSW } from 'virtual:pwa-register/react';
import { useTranslation } from './common/components/LocalizationProvider';
import { useRegisterSW } from 'virtual:pwa-register/react'

// Based on https://vite-pwa-org.netlify.app/frameworks/react.html
function UpdateController() {
const UpdateController = () => {
const t = useTranslation();

const swUpdateInterval = useSelector((state) => state.session.server.attributes.serviceWorkerUpdateInterval || 3600000);
Expand All @@ -21,30 +21,30 @@ function UpdateController() {
if (!(!swRegistration.installing && navigator)) {
return;
}

if (('connection' in navigator) && !navigator.onLine) {
return;
}

const newSW = await fetch(swUrl, {
cache: 'no-store',
headers: {
'cache': 'no-store',
cache: 'no-store',
'cache-control': 'no-cache',
},
});

if (newSW?.status === 200) {
await swRegistration.update();
}
}, swUpdateInterval);
}
}
},
});

return (
<Snackbar
open={needRefresh}
<Snackbar
open={needRefresh}
message={t('settingsUpdateAvailable')}
action={(
<IconButton color="inherit" onClick={() => updateServiceWorker(true)}>
Expand All @@ -53,6 +53,6 @@ function UpdateController() {
)}
/>
);
}
};

export default UpdateController;
2 changes: 1 addition & 1 deletion modern/src/login/LoginPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ const LoginPage = () => {
const query = `email=${encodeURIComponent(email)}&password=${encodeURIComponent(password)}`;
const response = await fetch('/api/session', {
method: 'POST',
body: new URLSearchParams(code.length ? query + `&code=${code}` : query),
body: new URLSearchParams(code.length ? `${query}&code=${code}` : query),
});
if (response.ok) {
const user = await response.json();
Expand Down
6 changes: 3 additions & 3 deletions modern/src/main/DeviceRow.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,15 @@ const DeviceRow = ({ data, index, style }) => {
{position.attributes.hasOwnProperty('batteryLevel') && (
<Tooltip title={`${t('positionBatteryLevel')}: ${formatPercentage(position.attributes.batteryLevel)}`}>
<IconButton size="small">
{position.attributes.batteryLevel > 70 ? (
{(position.attributes.batteryLevel > 70 && (
position.attributes.charge
? (<BatteryChargingFullIcon fontSize="small" className={classes.success} />)
: (<BatteryFullIcon fontSize="small" className={classes.success} />)
) : position.attributes.batteryLevel > 30 ? (
)) || (position.attributes.batteryLevel > 30 && (
position.attributes.charge
? (<BatteryCharging60Icon fontSize="small" className={classes.warning} />)
: (<Battery60Icon fontSize="small" className={classes.warning} />)
) : (
)) || (
position.attributes.charge
? (<BatteryCharging20Icon fontSize="small" className={classes.error} />)
: (<Battery20Icon fontSize="small" className={classes.error} />)
Expand Down
1 change: 0 additions & 1 deletion modern/src/other/PositionPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import makeStyles from '@mui/styles/makeStyles';
import ArrowBackIcon from '@mui/icons-material/ArrowBack';
import { useNavigate, useParams } from 'react-router-dom';
import { useEffectAsync } from '../reactHelper';
import { prefixString } from '../common/util/stringUtils';
import { useTranslation } from '../common/components/LocalizationProvider';
import PositionValue from '../common/components/PositionValue';
import usePositionAttributes from '../common/attributes/usePositionAttributes';
Expand Down
4 changes: 2 additions & 2 deletions modern/src/reports/EventReportPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -204,15 +204,15 @@ const EventReportPage = () => {
{!loading ? items.map((item) => (
<TableRow key={item.id}>
<TableCell className={classes.columnAction} padding="none">
{item.positionId ? selectedItem === item ? (
{(item.positionId && (selectedItem === item ? (
<IconButton size="small" onClick={() => setSelectedItem(null)}>
<GpsFixedIcon fontSize="small" />
</IconButton>
) : (
<IconButton size="small" onClick={() => setSelectedItem(item)}>
<LocationSearchingIcon fontSize="small" />
</IconButton>
) : ''}
))) || ''}
</TableCell>
{columns.map((key) => (
<TableCell key={key}>
Expand Down
4 changes: 2 additions & 2 deletions modern/src/reports/LogsPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const LogsPage = () => {
const registerDevice = (uniqueId) => {
const query = new URLSearchParams({ uniqueId });
navigate(`/settings/device?${query.toString()}`);
}
};

return (
<PageLayout menu={<ReportsMenu />} breadcrumbs={['reportTitle', 'statisticsTitle']}>
Expand All @@ -55,7 +55,7 @@ const LogsPage = () => {
</TableRow>
</TableHead>
<TableBody>
{items.map((item, index) => (
{items.map((item, index) => /* eslint-disable react/no-array-index-key */ (
<TableRow key={index}>
<TableCell className={classes.columnAction} padding="none">
{item.deviceId ? (
Expand Down
3 changes: 1 addition & 2 deletions modern/src/settings/UserPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {
IconButton,
OutlinedInput,
} from '@mui/material';
import makeStyles from '@mui/styles/makeStyles';
import ExpandMoreIcon from '@mui/icons-material/ExpandMore';
import DeleteForeverIcon from '@mui/icons-material/DeleteForever';
import CachedIcon from '@mui/icons-material/Cached';
Expand Down Expand Up @@ -84,7 +83,7 @@ const UserPage = () => {
const handleGenerateTotp = useCatch(async () => {
const response = await fetch('/api/users/totp', { method: 'POST' });
if (response.ok) {
setItem({ ...item, totpKey: await response.text() })
setItem({ ...item, totpKey: await response.text() });
} else {
throw Error(await response.text());
}
Expand Down
8 changes: 4 additions & 4 deletions modern/src/settings/UsersPage.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useState } from 'react';
import { useNavigate } from 'react-router-dom';
import {
Table, TableRow, TableCell, TableHead, TableBody, Switch, TableFooter, FormControlLabel, FormControl, FormGroup, Grid,
Table, TableRow, TableCell, TableHead, TableBody, Switch, TableFooter, FormControlLabel,
} from '@mui/material';
import LoginIcon from '@mui/icons-material/Login';
import LinkIcon from '@mui/icons-material/Link';
Expand Down Expand Up @@ -81,7 +81,7 @@ const UsersPage = () => {
<TableCell>{t('userAdmin')}</TableCell>
<TableCell>{t('sharedDisabled')}</TableCell>
<TableCell>{t('userExpirationTime')}</TableCell>
<TableCell className={classes.columnAction}></TableCell>
<TableCell className={classes.columnAction} />
</TableRow>
</TableHead>
<TableBody>
Expand All @@ -108,13 +108,13 @@ const UsersPage = () => {
<TableRow>
<TableCell colSpan={6} align="right">
<FormControlLabel
control={
control={(
<Switch
value={temporary}
onChange={(e) => setTemporary(e.target.checked)}
size="small"
/>
}
)}
label={t('userTemporary')}
labelPlacement="start"
/>
Expand Down

0 comments on commit 8bd7cba

Please sign in to comment.