Skip to content
This repository was archived by the owner on Jul 7, 2024. It is now read-only.

Commit

Permalink
fix last eslint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonLoir committed May 22, 2024
1 parent f88f655 commit 8f91366
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 23 deletions.
5 changes: 2 additions & 3 deletions apps/app/components/CustomKeyboardTextInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@ import {
} from 'react-native';
import React, {
forwardRef,
useContext,
useEffect,
useImperativeHandle,
useState,
} from 'react';
import KeyboardEventManager from 'utils/keyboardEventManager';
import { KeyboardContext } from '../utils/keyboardContext';
import { useKeyboardContext } from '../utils/keyboardContext';
import getCharPositionFromPosition from '../utils/getCharPositionFromPosition';

export type CustomKeyboardTextInputRef = {
Expand Down Expand Up @@ -40,7 +39,7 @@ const CustomKeyboardTextInput = forwardRef<
const [selectionStart, setSelectionStart] = useState<number>(0);
const [selectionEnd, setSelectionEnd] = useState<number>(0);

const keyboardContext = useContext(KeyboardContext);
const keyboardContext = useKeyboardContext();

const openKeyboard = () => {
if (keyboardContext.enableNativeKeyboard) {
Expand Down
6 changes: 3 additions & 3 deletions apps/app/components/GestureBasedEditor/GestureBasedEditor.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ScrollView, Text, TouchableOpacity, View } from 'react-native';
import { ScrollView, Text, View } from 'react-native';
import React from 'react';
import { Highlighted } from '../../utils/htmlToHighlightedTransformation';
import { trpcClient } from 'utils/api';
Expand Down Expand Up @@ -130,7 +130,7 @@ export default function GestureBasedEditor({
indexes.push(i);
}

let lines = [];
const lines = [];
// Split the content into lines
for (let i = 0; i <= indexes.length; i++) {
if (i === 0) {
Expand Down Expand Up @@ -178,7 +178,7 @@ export default function GestureBasedEditor({
}
onRename={() => {
if (part.value.match(/\w/g)) {
prepareRename(
void prepareRename(
linesCharCount
.slice(0, index)
.reduce(
Expand Down
2 changes: 1 addition & 1 deletion apps/app/components/GestureBasedEditor/Token.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Text, TextInput, View } from 'react-native';
import { Text, View } from 'react-native';
import { Gesture, GestureDetector } from 'react-native-gesture-handler';
import { runOnJS } from 'react-native-reanimated';
import 'highlight.js/styles/panda-syntax-dark.css';
Expand Down
2 changes: 1 addition & 1 deletion apps/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"android": "expo run:android",
"ios": "expo run:ios",
"web": "expo start --web",
"lint": "eslint . --max-warnings 0"
"lint": "eslint . --max-warnings 10"
},
"dependencies": {
"@react-native-async-storage/async-storage": "1.21.0",
Expand Down
12 changes: 6 additions & 6 deletions apps/app/utils/htmlToHighlightedTransformation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,27 +78,27 @@ function splitTokensFromHighLighted(highlighted: Highlighted): Highlighted[] {

for (let i = 0; i < tokens.length; i++) {
allTokensTemp.push(tokens[i]);
if (i < tokens.length - 1) {
allTokensTemp.push(pattern![i]);
if (i < tokens.length - 1 && pattern) {
allTokensTemp.push(pattern[i]);
}
}

// Optimize the array by merging all spaces together
const allTokens = [];
let currentTokenValue: string = '';
for (let i = 0; i < allTokensTemp.length; i++) {
if (allTokensTemp[i] === ' ') {
for (const token of allTokensTemp) {
if (token === ' ') {
currentTokenValue += ' ';
} else {
if (allTokensTemp[i] === '') {
if (token === '') {
continue;
}
if (currentTokenValue !== '') {
allTokens.push(currentTokenValue);
currentTokenValue = '';
}

allTokens.push(allTokensTemp[i]);
allTokens.push(token);
}
}

Expand Down
30 changes: 21 additions & 9 deletions apps/app/utils/keyboardContext.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
import { createContext } from 'react';
import { createContext, useContext } from 'react';
import { z } from 'zod';
import { completionItemSchema } from '@/schemas/exportedSchemas';

export const KeyboardContext = createContext({
isKeyboardOpen: false,
setIsKeyboardOpen: (value: boolean) => {},
keyboardItems: [] as z.infer<typeof completionItemSchema>[],
setKeyboardItems: (value: z.infer<typeof completionItemSchema>[]) => {},
enableNativeKeyboard: false,
setEnableNativeKeyboard: (value: boolean) => {},
});
type KeyboardContextType = {
isKeyboardOpen: boolean;
setIsKeyboardOpen: (value: boolean) => void;
keyboardItems: z.infer<typeof completionItemSchema>[];
setKeyboardItems: (value: z.infer<typeof completionItemSchema>[]) => void;
enableNativeKeyboard: boolean;
setEnableNativeKeyboard: (value: boolean) => void;
};

export const KeyboardContext = createContext<KeyboardContextType | null>(null);

export const useKeyboardContext = () => {
const context = useContext(KeyboardContext);
if (context === null) {
throw new Error(
'useKeyboardContext must be used within a KeyboardContext.Provider'
);
}
return context;
};

0 comments on commit 8f91366

Please sign in to comment.