client/web: add eslint

Add eslint to require stricter typescript rules, particularly around
required hook dependencies. This commit also updates any files that
were now throwing errors with eslint.

Updates #10261

Signed-off-by: Sonia Appasamy <sonia@tailscale.com>
This commit is contained in:
Sonia Appasamy
2023-11-28 16:31:56 -05:00
committed by Sonia Appasamy
parent 5a9e935597
commit 6e30c9d1fe
12 changed files with 3255 additions and 533 deletions
+3 -2
View File
@@ -65,17 +65,18 @@ export default function useAuth() {
.catch((error) => {
console.error(error)
})
}, [])
}, [loadAuth])
useEffect(() => {
loadAuth().then((d) => {
if (
!d.canManageNode &&
new URLSearchParams(window.location.search).get("check") == "now"
new URLSearchParams(window.location.search).get("check") === "now"
) {
newSession()
}
})
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [])
return {
+5 -3
View File
@@ -71,6 +71,8 @@ export default function useExitNodes(tailnetName: string, filter?: string) {
}
}, [data, tailnetName])
const hasFilter = Boolean(filter)
const mullvadNodesSorted = useMemo(() => {
const nodes: ExitNode[] = []
@@ -91,7 +93,7 @@ export default function useExitNodes(tailnetName: string, filter?: string) {
})
}
if (!Boolean(filter)) {
if (!hasFilter) {
// When nothing is searched, only show a single best-matching
// exit node per-country.
//
@@ -121,7 +123,7 @@ export default function useExitNodes(tailnetName: string, filter?: string) {
}
return nodes.sort(compareByName)
}, [locationNodesMap, Boolean(filter)])
}, [hasFilter, locationNodesMap])
// Ordered and filtered grouping of exit nodes.
const exitNodeGroups = useMemo(() => {
@@ -165,7 +167,7 @@ function highestPriorityNode(nodes: ExitNode[]): ExitNode | undefined {
// compareName compares two exit nodes alphabetically by name.
function compareByName(a: ExitNode, b: ExitNode): number {
if (a.Location && b.Location && a.Location.Country == b.Location.Country) {
if (a.Location && b.Location && a.Location.Country === b.Location.Country) {
// Always put "<Country>: Best Match" node at top of country list.
if (a.Name.includes(": Best Match")) {
return -1
+2 -2
View File
@@ -120,7 +120,7 @@ export default function useNodeData() {
throw err
})
},
[data]
[data, isPosting, refreshData]
)
const updatePrefs = useCallback(
@@ -169,7 +169,7 @@ export default function useNodeData() {
}
},
// Run once.
[]
[refreshData]
)
return { data, refreshData, updateNode, updatePrefs, isPosting }
+5 -9
View File
@@ -29,15 +29,8 @@ export enum UpdateState {
// useInstallUpdate initiates and tracks a Tailscale self-update via the LocalAPI,
// and returns state messages showing the progress of the update.
export function useInstallUpdate(currentVersion: string, cv?: VersionInfo) {
if (!cv) {
return {
updateState: UpdateState.UpToDate,
updateLog: "",
}
}
const [updateState, setUpdateState] = useState<UpdateState>(
cv.RunningLatest ? UpdateState.UpToDate : UpdateState.Available
cv?.RunningLatest ? UpdateState.UpToDate : UpdateState.Available
)
const [updateLog, setUpdateLog] = useState<string>("")
@@ -132,7 +125,10 @@ export function useInstallUpdate(currentVersion: string, cv?: VersionInfo) {
if (timer) clearTimeout(timer)
timer = 0
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [])
return { updateState, updateLog }
return !cv
? { updateState: UpdateState.UpToDate, updateLog: "" }
: { updateState, updateLog }
}