diff --git a/.nvmrc b/.nvmrc index 0cf077e..4a58985 100644 --- a/.nvmrc +++ b/.nvmrc @@ -1 +1 @@ -16.14 +18.18 diff --git a/package.json b/package.json index cadb02a..ae0d9db 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,8 @@ "dev": "parcel serve ./src/index.html", "lint": "yarn lint:scripts && yarn lint:styles", "lint:scripts": "eslint .", - "lint:styles": "stylelint 'src/**/*.tsx'" + "lint:styles": "stylelint 'src/**/*.tsx'", + "type": "yarn tsc --noEmit" }, "dependencies": { "@emotion/react": "^11.9.3", diff --git a/src/components/Preferences/BookmarkRow.tsx b/src/components/Preferences/BookmarkRow.tsx index 23c27ef..1ce6c1e 100644 --- a/src/components/Preferences/BookmarkRow.tsx +++ b/src/components/Preferences/BookmarkRow.tsx @@ -4,7 +4,7 @@ import axios from 'axios' import styled from '@emotion/styled' -import type { BookmarkLink } from '../../types' +import type { BookmarkLink, BookmarkLinks } from '../../types' import { SettingsContext } from '../../context/SettingsProvider' @@ -79,7 +79,7 @@ const BookmarkRow = ({ bookmark }: Props): JSX.Element => { const newBookmark = { id: Date.now(), label, url, icon, category } if (bookmarks !== undefined) { - setSetting('bookmarks', [...bookmarks, newBookmark]) + setSetting('bookmarks', [...bookmarks, newBookmark]) } else { setSetting('bookmarks', [newBookmark]) } @@ -93,7 +93,7 @@ const BookmarkRow = ({ bookmark }: Props): JSX.Element => { const updateBookmark = () => { const b = bookmarks || [] const i = - bookmarks?.findIndex((c: BookmarkLink) => c.id === bookmark?.id) || 0 + bookmarks?.findIndex((c: BookmarkLink) => c.id === bookmark?.id) ?? 0 b[i as number] = { ...b[i as number], label, diff --git a/src/components/Preferences/Theme.tsx b/src/components/Preferences/Theme.tsx index fdb867f..bb6315d 100644 --- a/src/components/Preferences/Theme.tsx +++ b/src/components/Preferences/Theme.tsx @@ -1,5 +1,6 @@ import * as React from 'react' +import type { Theme } from '@emotion/react' import styled from '@emotion/styled' import { SettingsContext } from '../../context/SettingsProvider' @@ -45,7 +46,7 @@ type AvailableOption = | 'highlight' | 'inputFocus' -const Theme = (): JSX.Element => { +const Themer = (): JSX.Element => { const { settings: { prefersDarkMode = matchMediaFallback() }, setSetting, @@ -59,18 +60,21 @@ const Theme = (): JSX.Element => { {theme && - Object.keys(theme.colors).map((option: string) => ( + Object.keys(theme.colors).map(option => (
{ - setSetting(prefersDarkMode ? 'themeDark' : 'themeLight', { - colors: { - ...theme.colors, - [option]: e.target.value, - }, - }) + setSetting( + prefersDarkMode ? 'themeDark' : 'themeLight', + { + colors: { + ...theme.colors, + [option]: e.target.value, + }, + } + ) }} /> @@ -89,4 +93,4 @@ const Theme = (): JSX.Element => { ) } -export default Theme +export default Themer diff --git a/src/context/SettingsProvider.tsx b/src/context/SettingsProvider.tsx index 537df42..5d9fb5c 100644 --- a/src/context/SettingsProvider.tsx +++ b/src/context/SettingsProvider.tsx @@ -36,14 +36,7 @@ export interface Settings { interface SettingsContextType { settings: Settings - setSetting: < - T extends - | string - | boolean - | BookmarkLink[] - | undefined - | Record - >( + setSetting: ( setting: string, value: T ) => void @@ -71,12 +64,7 @@ const SettingsProvider = ({ children }: SettingsProviderProps): JSX.Element => { }, []) const setSetting = < - T extends - | string - | boolean - | BookmarkLink[] - | undefined - | Record + T extends string | boolean | BookmarkLink[] | undefined | Theme, >( setting: string, value: T @@ -96,10 +84,10 @@ const SettingsProvider = ({ children }: SettingsProviderProps): JSX.Element => { setSettings(s) } + const value = { settings, setSetting, deleteSetting, setSettings, store } + return ( - + {children} ) diff --git a/src/types.ts b/src/types.ts index 071a796..2a93557 100644 --- a/src/types.ts +++ b/src/types.ts @@ -8,7 +8,7 @@ export type BookmarkLink = { id: number label: string url: string - icon?: string + icon?: string | null category?: string }