Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some linting #51

Merged
merged 30 commits into from
Feb 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
3ae759d
refactor: Remove unused imports and reorder imports in settings.tsx
harperreed Feb 12, 2025
26aa573
refactor: Remove unused exhaustiveCheck variable in TextReducer
harperreed Feb 12, 2025
8974987
refactor: Fix linting warnings in TextContext
harperreed Feb 12, 2025
adad767
refactor: Remove unused imports and variables in HomeScreen
harperreed Feb 12, 2025
c3be3d6
fix: Resolve unused variable warning in TextContext error handling
harperreed Feb 12, 2025
aae33e8
refactor: Remove unused theme variable in ErrorDisplay component
harperreed Feb 12, 2025
2dd212d
refactor: Remove unused useTheme import from ErrorBoundary
harperreed Feb 12, 2025
9149431
refactor: Remove unused imports and add empty state test assertion
harperreed Feb 12, 2025
84a23aa
refactor: Remove unused imports from about.tsx
harperreed Feb 12, 2025
d9f17ad
refactor: Remove unused handleWikiPress function in WelcomeModal
harperreed Feb 12, 2025
ad9c48b
fix: Resolve unused error parameter in TextContext catch block
harperreed Feb 12, 2025
522084c
refactor: Remove unused imports and fix useEffect dependency
harperreed Feb 12, 2025
aad34f8
fix: Resolve unused error variable in TextContext
harperreed Feb 12, 2025
cccb484
refactor: Add debouncedCalculate to useEffect dependency array
harperreed Feb 12, 2025
50420be
refactor: Mark unused error parameter with underscore in TextContext
harperreed Feb 12, 2025
ada52d6
refactor: Remove unused StoredMessage import from storage test
harperreed Feb 12, 2025
3b92639
refactor: Remove unused error variable and improve error handling in …
harperreed Feb 12, 2025
0569748
refactor: Mark unused error parameter with underscore in TextContext
harperreed Feb 12, 2025
d3eb546
refactor: Fix linting warnings in history.tsx
harperreed Feb 12, 2025
ed3d6e0
refactor: Fix React Hook dependency warnings in history.tsx
harperreed Feb 12, 2025
4001abd
fix: Initialize filteredMessages with empty array
harperreed Feb 12, 2025
ee73b1f
refactor: Add missing loadMessages dependency to useEffect hook
harperreed Feb 12, 2025
9b6fe22
refactor: Remove unused error variable in TextContext
harperreed Feb 12, 2025
c944701
refactor: Remove unused fireEvent import in accessibility test
harperreed Feb 12, 2025
011f313
refactor: Remove unused getByTestId and use screen helper in HomeScre…
harperreed Feb 12, 2025
1a4ffe7
fix: Resolve unused error parameter in TextContext by prefixing with …
harperreed Feb 12, 2025
e4897ad
refactor: Remove unused getByTestId variable in HomeScreen test
harperreed Feb 12, 2025
9a351d0
refactor: Remove unused queryByText variable in HistoryScreen test
harperreed Feb 12, 2025
5ec3e13
refactor: Rename unused error variable to _error in TextContext
harperreed Feb 12, 2025
37b95fe
refactor: Handle error message in TextContext catch block
harperreed Feb 12, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/chat/app/__tests__/HistoryScreen.test.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { render, fireEvent, act } from '@testing-library/react-native';
import AsyncStorage from '@react-native-async-storage/async-storage';
import { Alert } from 'react-native';
import HistoryScreen from '../history';
import { clearHistory, storeMessage } from '../utils/storage';
import { storeMessage } from '../utils/storage';

// Mock Alert
jest.mock('react-native', () => ({
Expand Down Expand Up @@ -30,6 +29,7 @@ describe('HistoryScreen', () => {
await act(async () => {});

expect(queryByText('Clear History')).toBeNull();
expect(queryByText('No messages yet')).toBeTruthy();
});

it('displays stored messages', async () => {
Expand All @@ -45,7 +45,7 @@ describe('HistoryScreen', () => {
it('clears history when clear button is pressed', async () => {
await storeMessage('Test message');

const { getByText, queryByText } = render(<HistoryScreen />);
const { getByText } = render(<HistoryScreen />);
await act(async () => {});

const clearButton = getByText('Clear History');
Expand Down
6 changes: 3 additions & 3 deletions packages/chat/app/__tests__/HomeScreen.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ describe("HomeScreen", () => {
});

it("displays text with large font size for short text", () => {
const { getByTestId } = render(<HomeScreen />);
const display = getByTestId("big-text-display");
render(<HomeScreen />);
const display = screen.getByTestId("big-text-display");
expect(display.props.style).toEqual(
expect.objectContaining({
fontSize: 48
Expand All @@ -60,7 +60,7 @@ describe("HomeScreen", () => {
});

it("reduces font size for long text", () => {
const { getByTestId } = render(<HomeScreen />);
render(<HomeScreen />);
const display = screen.getByTestId("big-text-display");

fireEvent.changeText(display, "This is a very long text that should cause the font size to decrease");
Expand Down
2 changes: 1 addition & 1 deletion packages/chat/app/__tests__/accessibility.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { render, fireEvent } from '@testing-library/react-native';
import { render } from '@testing-library/react-native';
import { AccessibilityInfo } from 'react-native';
import HomeScreen from '../components/HomeScreen';
import BottomBar from '../components/BottomBar';
Expand Down
2 changes: 1 addition & 1 deletion packages/chat/app/__tests__/storage.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import AsyncStorage from '@react-native-async-storage/async-storage';
import { storeMessage, getMessages, StoredMessage } from '../utils/storage';
import { storeMessage, getMessages } from '../utils/storage';

describe('Storage Utils', () => {
beforeEach(() => {
Expand Down
3 changes: 0 additions & 3 deletions packages/chat/app/about.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import { StyleSheet, Linking } from "react-native";
import {
Modal,
Portal,
Surface,
Text,
Button,
useTheme,
} from "react-native-paper";
import PageLayout from "./components/PageLayout";
Expand Down
8 changes: 4 additions & 4 deletions packages/chat/app/components/BigTextDisplay.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { StyleSheet, useWindowDimensions, LayoutChangeEvent, Platform, Keyboard } from "react-native";
import { useWindowDimensions, LayoutChangeEvent, Platform, Keyboard } from "react-native";
import { TextInput, useTheme } from 'react-native-paper';
import { useState, useEffect, useCallback, useRef, RefObject, useMemo } from "react";
import { useState, useEffect, useCallback, useRef, useMemo } from "react";
import { useIsMounted } from '../hooks/useIsMounted';
import { useSettings } from '../context/SettingsContext';
import { debounce } from 'lodash';
Expand Down Expand Up @@ -94,7 +94,7 @@ export default function BigTextDisplay({
return () => {
abortControllerRef.current?.abort();
};
}, []);
}, [debouncedCalculate]);

// Handle keyboard events and cleanup
useEffect(() => {
Expand Down Expand Up @@ -127,7 +127,7 @@ export default function BigTextDisplay({
listeners.forEach(listener => listener.remove());
debouncedCalculate.cancel();
};
}, [isMounted]);
}, [isMounted, debouncedCalculate]);
const onLayout = useCallback((event: LayoutChangeEvent) => {
const { width, height } = event.nativeEvent.layout;
setContainerSize({ width, height });
Expand Down
4 changes: 1 addition & 3 deletions packages/chat/app/components/ErrorBoundary.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import { View, StyleSheet } from 'react-native';
import { Text, Button, useTheme } from 'react-native-paper';
import { Text, Button } from 'react-native-paper';

interface Props {
children: React.ReactNode;
Expand Down Expand Up @@ -47,8 +47,6 @@ interface ErrorDisplayProps {
}

function ErrorDisplay({ error, onReset }: ErrorDisplayProps) {
const theme = useTheme();

return (
<View
style={styles.container}
Expand Down
4 changes: 2 additions & 2 deletions packages/chat/app/components/HomeScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
Animated,
} from "react-native";
import RNShake from 'react-native-shake';
import { Surface, Snackbar, ActivityIndicator, Portal } from 'react-native-paper';
import { Surface, Snackbar } from 'react-native-paper';
import BottomBar from "./BottomBar";
import { useCallback, useEffect, useState } from "react";
import { useSettings } from "../context/SettingsContext";
Expand All @@ -18,7 +18,7 @@ import { useText } from "../context/TextContext";
import { AccessibilityInfo } from 'react-native';

export default function HomeScreen() {
const { text, handleTextChange, restoreLastSession, error, isLoading } = useText();
const { text, handleTextChange, restoreLastSession, error } = useText();
const announceError = useCallback((error: string) => {
AccessibilityInfo.announceForAccessibility(error);
}, []);
Expand Down
4 changes: 0 additions & 4 deletions packages/chat/app/components/WelcomeModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ export function WelcomeModal() {
Linking.openURL("mailto:feedback@orbiting.com");
};

const handleWikiPress = (name: string) => {
Linking.openURL(`https://en.wikipedia.org/wiki/${name}`);
};

const styles = StyleSheet.create({
modalContainer: {
backgroundColor: theme.colors.background,
Expand Down
15 changes: 8 additions & 7 deletions packages/chat/app/context/TextContext.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { createContext, useContext, useReducer, useCallback, useEffect, useRef } from 'react';
import { storeMessage, clearHistory, getMessages } from '../utils/storageUtils';
import { storeMessage, getMessages } from '../utils/storageUtils';
import { TextState, TextAction, textReducer, TEXT_ACTIONS } from './TextReducer';

interface TextContextType {
Expand Down Expand Up @@ -79,7 +79,7 @@ export function TextProvider({ children }: { children: React.ReactNode }) {
clearTimeout(saveTimeoutRef.current);
}
};
}, [state.text, state.isDirty]);
}, [state]);

const handleTextChange = useCallback(async (newText: string) => {
try {
Expand All @@ -88,13 +88,13 @@ export function TextProvider({ children }: { children: React.ReactNode }) {
type: TEXT_ACTIONS.SET_TEXT,
payload: newText
});
} catch (error) {
const errorMessage = error instanceof Error ? error.message : 'Failed to update text';
} catch (_error) {
const errorMessage = _error instanceof Error ? _error.message : 'Failed to update text';
dispatch({
type: TEXT_ACTIONS.SET_ERROR,
payload: errorMessage
});
console.error('Text update error:', error);
console.error('Text update error:', _error);
} finally {
dispatch({ type: TEXT_ACTIONS.SET_LOADING, payload: false });
}
Expand Down Expand Up @@ -122,10 +122,11 @@ export function TextProvider({ children }: { children: React.ReactNode }) {
payload: messages[0]
});
}
} catch (error) {
} catch (_error) {
const errorMessage = _error instanceof Error ? _error.message : 'Failed to restore session';
dispatch({
type: TEXT_ACTIONS.SET_ERROR,
payload: 'Failed to restore session'
payload: errorMessage
});
}
}, []);
Expand Down
3 changes: 2 additions & 1 deletion packages/chat/app/context/TextReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ export function textReducer(state: TextState, action: TextAction): TextState {
};

default: {
const exhaustiveCheck: never = action;
const _exhaustiveCheck: never = action;
void _exhaustiveCheck; // Explicitly mark as used
return state;
}
}
Expand Down
14 changes: 6 additions & 8 deletions packages/chat/app/history.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { StyleSheet, View, Platform } from "react-native";
import { StyleSheet, View } from "react-native";
import {
Text,
Button,
Expand Down Expand Up @@ -27,9 +27,7 @@ import { FlashList } from "@shopify/flash-list";
export default function HistoryScreen() {
const theme = useTheme();
const [messages, setMessages] = useState<StoredMessage[]>([]);
const [filteredMessages, setFilteredMessages] = useState<StoredMessage[]>(
[],
);
const [filteredMessages, setFilteredMessages] = useState<StoredMessage[]>([]);
const [isLoading, setIsLoading] = useState(false);
const [isLoadingMore, setIsLoadingMore] = useState(false);
const [hasMore, setHasMore] = useState(true);
Expand Down Expand Up @@ -82,20 +80,20 @@ export default function HistoryScreen() {
setIsLoadingMore(false);
}
},
[],
[searchQuery],
);

useEffect(() => {
loadMessages(null);
}, [loadMessages]);
}, [loadMessages, searchQuery]);

useEffect(() => {
// Reset pagination and reload with search
setCursor(null);
setMessages([]);
setFilteredMessages([]);
loadMessages(null, false);
}, [searchQuery]);
}, [searchQuery, loadMessages]);

const handleClearHistory = useCallback(async () => {
try {
Expand Down Expand Up @@ -185,7 +183,7 @@ export default function HistoryScreen() {
/>
</TouchableRipple>
),
[router],
[router, theme.colors.onSurfaceVariant],
);

if (isLoading) {
Expand Down
8 changes: 4 additions & 4 deletions packages/chat/app/settings.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { StyleSheet, View, Dimensions } from 'react-native';
import { Text, Switch, Button, List, Surface, useTheme, Portal, Modal, TouchableRipple, RadioButton } from 'react-native-paper';
import { StyleSheet, View } from 'react-native';
import { Text, Button, List, Surface, useTheme, Portal, Modal, TouchableRipple, RadioButton } from 'react-native-paper';
import { useState } from 'react';
import { MaterialCommunityIcons } from '@expo/vector-icons';
import Slider from '@react-native-community/slider';
import PageLayout from './components/PageLayout';
import { useSettings } from './context/SettingsContext';
import type { ThemeType } from './context/SettingsContext';

import { THEMES } from './themes';

const FONT_SIZES = [16, 18, 20, 24, 28, 32, 36, 40];
const MIN_FONT_SIZE = Math.min(...FONT_SIZES);
const MAX_FONT_SIZE = Math.max(...FONT_SIZES);

import { THEMES } from './themes';

const COLOR_SCHEMES = [
{ label: 'System', value: 'system', icon: 'theme-light-dark' },
{ label: 'Light', value: 'light', icon: 'white-balance-sunny' },
Expand Down
Loading