Skip to content

Commit 3f81f71

Browse files
committed
style: Fix linting errors and warnings
1 parent e038115 commit 3f81f71

File tree

11 files changed

+45
-32
lines changed

11 files changed

+45
-32
lines changed

App.tsx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { View } from 'react-native';
1+
import { StyleSheet, View } from 'react-native';
22

33
import Divider from '@components/Divider';
44
import HabitList from './src/ui/HabitList';
@@ -12,16 +12,21 @@ export default function App() {
1212
const { theme } = useTheme();
1313
return (
1414
<SafeAreaProvider>
15-
<SafeAreaView style={{ flex: 1, backgroundColor: theme.colors.background }}>
15+
<SafeAreaView style={[styles.container, { backgroundColor: theme.colors.background }]}>
1616
<HabitList />
17-
<View style={{ margin: 8 }}>
17+
<View style={styles.spacing}>
1818
<TokenManagement />
1919
</View>
2020
<Divider />
21-
<View style={{ margin: 8 }}>
21+
<View style={styles.spacing}>
2222
<ManualSync />
2323
</View>
2424
</SafeAreaView>
2525
</SafeAreaProvider>
2626
);
27-
}
27+
}
28+
29+
const styles = StyleSheet.create({
30+
container: { flex: 1 },
31+
spacing: { margin: 8 },
32+
});

lib/settings/_utils/NamedSubscriberStore.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,8 @@ export class NamedSubscriberStore<State extends Record<string, any>> {
2323
this.listeners.set(name, namedListeners)
2424

2525
const unsubscribe = () => {
26-
const namedListeners = this.listeners.get(name) ?? []
27-
const index = namedListeners.indexOf(callback)
28-
if (index !== -1) {
29-
namedListeners.splice(index, 1)
30-
this.listeners.set(name, namedListeners)
31-
}
26+
const listeners = this.listeners.get(name) ?? []
27+
this.listeners.set(name, listeners.filter(l => l !== callback))
3228
}
3329
return unsubscribe
3430
}
@@ -49,12 +45,13 @@ export class NamedSubscriberStore<State extends Record<string, any>> {
4945
}
5046

5147
/** Assesses if the setting can be assigned the value */
52-
protected isValidUpdate<S extends keyof State>(setting: S, value: State[S]): boolean {
48+
protected isValidUpdate<S extends keyof State>(setting: S, value: State[S]): boolean { // eslint-disable-line @typescript-eslint/no-unused-vars
5349
return true
5450
}
5551

52+
5653
/** Allows child classes to trigger additional effects after successful updates (e.g. sync external stores) */
57-
protected onUpdate<S extends keyof State>(setting: S, value: State[S]) { }
54+
protected onUpdate<S extends keyof State>(setting: S, value: State[S]) { } // eslint-disable-line @typescript-eslint/no-unused-vars
5855

5956
getSnapshot(): State {
6057
if (this.snapshot === null) this.snapshot = structuredClone(this.state)

lib/settings/createSettings.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ export default function createSettings<S extends Settings>(definitions: S) {
2020
}
2121

2222
function useSettings(callerName: string = 'settings') {
23-
const subscribe = useCallback<Parameters<typeof useSyncExternalStore>[0]>((listener) => store.subscribe(listener, callerName), [store, callerName]);
24-
const getSnapshot = useCallback(() => store.getSnapshot(), [store]);
23+
const subscribe = useCallback<Parameters<typeof useSyncExternalStore>[0]>((listener) => store.subscribe(listener, callerName), [callerName]);
24+
const getSnapshot = useCallback(() => store.getSnapshot(), []);
2525

2626
const snapshot = useSyncExternalStore(subscribe, getSnapshot);
2727
const update = (updates: Partial<typeof snapshot>) => store.update(updates);

lib/stores/KeyValueStore.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export default class KeyValueStore {
2121

2222
async put(key: string, value: string): Promise<void> {
2323
if (!this.setters.has(key)) {
24-
const setter = async (value: string) => await this.external.set(key, value);
24+
const setter = async (newVal: string) => await this.external.set(key, newVal);
2525
this.setters.set(key, debounce(setter, 1000, { trailing: true }));
2626
}
2727
return this.setters.get(key)!(value);

lib/theme/useTheme.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ function useTheme() {
4747
const [settings, updateSettings] = useSettings('useTheme');
4848
const colorScheme = useColorScheme();
4949

50-
const scheme = settings.scheme === "system" ? colorScheme ?? DEFAULT_SYSTEM_COLOR_SCHEME : settings.scheme;
51-
const theme = scheme === "dark" ? settings.theme.dark : settings.theme.light;
50+
const currentScheme = settings.scheme === "system" ? colorScheme ?? DEFAULT_SYSTEM_COLOR_SCHEME : settings.scheme;
51+
const colors = currentScheme === "dark" ? settings.theme.dark : settings.theme.light;
5252

5353
return {
54-
theme: { fonts: settings.theme.fonts, colors: theme } as Theme,
54+
theme: { fonts: settings.theme.fonts, colors } as Theme,
5555
setTheme: (theme: ThemeDefinition) => updateSettings({ theme }),
5656
setScheme: (scheme: ColorScheme) => updateSettings({ scheme }),
5757
resetTheme: () => updateSettings({ theme: DEFAULT_THEME, scheme: DEFAULT_COLOR_SCHEME }),

src/lib/Todoist.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ async function queryRawTasks(apiToken: string, since: Date): Promise<TodoistTask
1919
},
2020
);
2121
const json = await tasks.json();
22-
if (json['error']) {
22+
if (json.error) {
2323
throw new Error(JSON.stringify(json));
2424
}
25-
return json['items'] as TodoistTask[];
25+
return json.items as TodoistTask[];
2626
}
2727

2828
export async function queryTasks(apiToken: string, since: Date): Promise<Task[]> {

src/tasks/TodoistHabitSync.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ module.exports = async () => {
99
const apiToken = Storage.ApiKey.read();
1010
const recentlyCompletedTaskIDs = (await queryTasks(apiToken, Storage.LastSync.read())).map(t => t.id);
1111
const storedTasks = Storage.Tasks.read()
12-
const habitTasks = storedTasks.filter(t => t.habit != undefined).filter(t => recentlyCompletedTaskIDs.includes(t.id))
12+
const habitTasks = storedTasks.filter(t => t.habit !== undefined).filter(t => recentlyCompletedTaskIDs.includes(t.id))
1313
console.log(`Marking ${habitTasks.length} habits as done.`)
1414
// @ts-ignore
1515
habitTasks.forEach(async t => await LoopHabitModule.takeHabitAction(t.habit.id, t.habit.action));

src/ui/HabitList.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Alert, FlatList, NativeModules, View } from 'react-native';
1+
import { Alert, FlatList, NativeModules, StyleSheet, View } from 'react-native';
22
import { LoopHabit, PersistentTask } from '../types';
33
import { useCallback, useState } from 'react';
44

@@ -185,9 +185,9 @@ function HabitList() {
185185
const tasks = useTodoistTasks();
186186
console.debug(new Date(), tasks.length);
187187
return (
188-
<View style={{ flex: 1 }}>
188+
<View style={styles.container}>
189189
{tasks.length === 0 ? (
190-
<View style={{ flex: 1, justifyContent: 'center', marginHorizontal: "10%" }}>
190+
<View style={styles.empty}>
191191
<Text>
192192
<Text>No recently completed recurring tasks found in Todoist.</Text>
193193
<Text>{'\n\n'}</Text>
@@ -201,11 +201,17 @@ function HabitList() {
201201
data={tasks}
202202
renderItem={({ item }) => <Habit item={item} />}
203203
keyExtractor={item => item.id}
204-
contentContainerStyle={{ gap: 8, padding: 8 }}
204+
contentContainerStyle={styles.contentContainer}
205205
/>
206206
)}
207207
</View>
208208
);
209209
}
210210

211+
const styles = StyleSheet.create({
212+
container: { flex: 1 },
213+
contentContainer: { gap: 8, padding: 8 },
214+
empty: { flex: 1, justifyContent: 'center', marginHorizontal: "10%" },
215+
});
216+
211217
export default HabitList;

src/ui/TokenManagement.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Linking, View } from 'react-native';
1+
import { Linking, StyleSheet, View } from 'react-native';
22

33
import Button from '@components/Button';
44
import Dialog from '@components/Dialog';
@@ -7,6 +7,11 @@ import TextInput from '@components/TextInput';
77
import { useApiKey } from './useStorage';
88
import { useState } from 'react';
99

10+
const styles = StyleSheet.create({
11+
container: { gap: 10 },
12+
inset: { marginHorizontal: 2 },
13+
})
14+
1015
export function TokenManagement() {
1116
const [token, setToken] = useApiKey();
1217
const [text, setText] = useState(token);
@@ -16,8 +21,8 @@ export function TokenManagement() {
1621
<>
1722
{token && <Button mode="outlined" intent="danger" onPress={() => setClearDialogVisible(true)}>Clear API Token</Button>}
1823
{!token && (
19-
<View style={{ gap: 10 }}>
20-
<View style={{ marginHorizontal: 2 }}>
24+
<View style={styles.container}>
25+
<View style={styles.inset}>
2126
<TextInput
2227
placeholder='Todoist API Token'
2328
value={text}

src/ui/useStorage.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ export function useTasks() {
1919
const dedupTasks = (tasks: Task[]) => Array.from(new Map(tasks.map(task => [task.id, task])).values());
2020
const sortTasks = (tasks: Task[]) => tasks.sort((a, b) => (a.ignored ? 1 : 0) - (b.ignored ? 1 : 0) || (a.habit ? 1 : 0) - (b.habit ? 1 : 0) || a.title.localeCompare(b.title));
2121
const [tasks, setTasks] = useState<Task[]>(sortTasks(dedupTasks(Storage.Tasks.read())));
22-
const saveTasks = (tasks: Task[]) => {
23-
const dedupedTasks = sortTasks(dedupTasks(tasks));
22+
const saveTasks = (latestTasks: Task[]) => {
23+
const dedupedTasks = sortTasks(dedupTasks(latestTasks));
2424
Storage.Tasks.write(dedupedTasks);
2525
setTasks(dedupedTasks);
2626
}

0 commit comments

Comments
 (0)