Skip to content

Commit

Permalink
build: fix lint
Browse files Browse the repository at this point in the history
shalanah committed Mar 27, 2024
1 parent a463f77 commit 8fc1838
Showing 8 changed files with 30 additions and 56 deletions.
1 change: 1 addition & 0 deletions public/fallback-7DXoc7Qr5wMFmyUSbW8-f.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 0 additions & 28 deletions public/fallback-development.js

This file was deleted.

4 changes: 2 additions & 2 deletions src/components/experience.tsx
Original file line number Diff line number Diff line change
@@ -23,9 +23,9 @@ const Button = styled.button`

const config = { mass: 0.05, tension: 600, friction: 40 };
export default function Experience() {
const { activeIndex, iOSLacking, setNextFeature, filteredData } =
const { activeIndex, iOSMissingFeatures, setNextFeature, filteredData } =
useCanIUseContext();
const len = iOSLacking.length;
const len = iOSMissingFeatures.length;
const filteredLen = filteredData.length;
const turns = useRef(0);
const prevActiveIndex = usePrevious(activeIndex);
7 changes: 4 additions & 3 deletions src/components/filter.tsx
Original file line number Diff line number Diff line change
@@ -105,14 +105,15 @@ const Error = styled.div`
`;

export const Filter = () => {
const { filters, iOSLacking, filteredData, loading } = useCanIUseContext();
const { filters, iOSMissingFeatures, filteredData, loading } =
useCanIUseContext();
const len = Object.keys(filters.statuses).length;
const numChecked = Object.values(filters.statuses).filter((v) => v).length;
const filterCount = len - numChecked;

let count =
filteredData.length === iOSLacking.length
? `${iOSLacking.length} features`
filteredData.length === iOSMissingFeatures.length
? `${iOSMissingFeatures.length} features`
: `${filteredData.length} features`;
if (loading) {
count = 'Loading...';
5 changes: 1 addition & 4 deletions src/components/filterModalContentSpecs.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import React from 'react';
import { Checkbox } from './checkbox';
import useCanIUseContext, {
FiltersType,
SpecTypes,
} from '../hooks/useCanIUseContext';
import useCanIUseContext, { SpecTypes } from '../hooks/useCanIUseContext';
import { Badge } from './badge';
import styled from 'styled-components';

4 changes: 2 additions & 2 deletions src/components/milkcartontext.tsx
Original file line number Diff line number Diff line change
@@ -105,7 +105,7 @@ export const MilkCartonText = ({
rotation,
bind, // assures that we can also swipe on <a> tags
}) => {
const { iOSLacking, statuses } = useCanIUseContext();
const { iOSMissingFeatures, statuses } = useCanIUseContext();
const {
title,
description,
@@ -116,7 +116,7 @@ export const MilkCartonText = ({
key,
notes_by_num,
desktopSafariStat,
} = iOSLacking[index];
} = iOSMissingFeatures[index];

const iosMacSame = safariStat.slice(0, 1) === desktopSafariStat.slice(0, 1);

35 changes: 19 additions & 16 deletions src/hooks/useCanIUseContext.tsx
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@ import React, {
SetStateAction,
} from 'react';
import { useHash } from './useHash';
import { getIOSSafariLacking } from '../utils/parseCanIUseData';
import { getIOSMissingFeatures } from '../utils/parseCanIUseData';
import cloneDeep from 'lodash/cloneDeep';
import { useCanIUseData } from './useCanIUseData';
import { useFilters, type FiltersType } from './useFilters';
@@ -25,7 +25,7 @@ type StatusCounts = {
interface CanIUseContextInterface {
loading: boolean;
hasError: boolean;
iOSLacking: any;
iOSMissingFeatures: any;
activeIndex: number;
updateHash: (newHash: string) => void;
statusCounts: StatusCounts;
@@ -42,7 +42,7 @@ interface CanIUseContextInterface {
}) => void;
canIUseDataUpdated: number | undefined;
setHasError: (error: boolean) => void;
filteredByBrowser: any;
filteredByBrowserOnly: any;
}

// Game state... could probably be broken out into smaller files / hooks
@@ -58,31 +58,34 @@ export const CanIUseContextProvider = ({
children: ReactNode;
}) => {
const { canIUseData, loading, hasError, setHasError } = useCanIUseData();
const iOSLacking = useMemo(
() => getIOSSafariLacking(canIUseData),
const iOSMissingFeatures = useMemo(
() => getIOSMissingFeatures(canIUseData),
[canIUseData]
);
const [search, setSearch] = useState('');
const [filters, setFilters] = useFilters();
const [hash, updateHash] = useHash();

let activeIndex =
iOSLacking.length > 0 ? iOSLacking.findIndex((v) => v.key === hash) : -1;
if (activeIndex === -1 && iOSLacking.length > 0) activeIndex = 0;
iOSMissingFeatures.length > 0
? iOSMissingFeatures.findIndex((v) => v.key === hash)
: -1;
if (activeIndex === -1 && iOSMissingFeatures.length > 0) activeIndex = 0;

// If hash doesn't exist remove hash
useEffect(() => {
// Let's just remove if ever the hash is not found
if (
iOSLacking.length > 0 &&
iOSMissingFeatures.length > 0 &&
activeIndex !== -1 &&
hash !== iOSLacking[activeIndex]?.key
hash !== iOSMissingFeatures[activeIndex]?.key
) {
updateHash('');
}
}, [updateHash, activeIndex, iOSLacking, hash]);
}, [updateHash, activeIndex, iOSMissingFeatures, hash]);

const hasBrowsers = Object.values(filters.browsers).some((v) => v);
const filteredByBrowser = iOSLacking.filter((v) => {
const filteredByBrowserOnly = iOSMissingFeatures.filter((v) => {
return hasBrowsers
? Object.entries(filters.browsers)
.filter(([_, on]) => on)
@@ -92,7 +95,7 @@ export const CanIUseContextProvider = ({
: false;
});
// Add status filters
let filteredData = cloneDeep(filteredByBrowser).filter((v) => {
let filteredData = cloneDeep(filteredByBrowserOnly).filter((v) => {
return filters.statuses[v.status as keyof FiltersType['statuses']];
});
if (search.trim().length > 0) {
@@ -131,7 +134,7 @@ export const CanIUseContextProvider = ({
}
};

const statusCounts: StatusCounts = filteredByBrowser.reduce((acc, v) => {
const statusCounts: StatusCounts = filteredByBrowserOnly.reduce((acc, v) => {
acc[v.status] += 1;
return acc;
}, Object.fromEntries(Object.entries(canIUseData?.statuses || {}).map(([k, v]) => [k, 0])));
@@ -163,13 +166,13 @@ export const CanIUseContextProvider = ({
statusCounts,
loading,
hasError,
iOSLacking,
iOSMissingFeatures,
updateHash,
activeIndex,
statuses: canIUseData?.statuses,
filters,
filteredData,
filteredByBrowser,
filteredData, // browsers and specs applied
filteredByBrowserOnly, // specs not applied
setFilters,
setNextFeature,
canIUseDataUpdated: canIUseData?.updated,
2 changes: 1 addition & 1 deletion src/utils/parseCanIUseData.ts
Original file line number Diff line number Diff line change
@@ -75,7 +75,7 @@ const getFirstSeen = ({
};
};

export const getIOSSafariLacking = (canIUseData: any) => {
export const getIOSMissingFeatures = (canIUseData: any) => {
if (!canIUseData) return [];
// TODO: Make sure this is memorized?
const { data, agents } = canIUseData;

0 comments on commit 8fc1838

Please sign in to comment.