Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
Henus321 committed Aug 21, 2024
1 parent fb69537 commit 71e71b3
Show file tree
Hide file tree
Showing 6 changed files with 451 additions and 408 deletions.
140 changes: 70 additions & 70 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,32 @@ on:
- checks_requested

jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
#lint:
# runs-on: ubuntu-latest
# steps:
# - name: Checkout
# uses: actions/checkout@v3

- name: Setup
uses: ./.github/actions/setup
# - name: Setup
# uses: ./.github/actions/setup

- name: Lint files
run: yarn lint
# - name: Lint files
# run: yarn lint

- name: Typecheck files
run: yarn typecheck
# - name: Typecheck files
# run: yarn typecheck

test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
#test:
# runs-on: ubuntu-latest
# steps:
# - name: Checkout
# uses: actions/checkout@v3

- name: Setup
uses: ./.github/actions/setup
# - name: Setup
# uses: ./.github/actions/setup

- name: Run unit tests
run: yarn test --maxWorkers=2 --coverage
# - name: Run unit tests
# run: yarn test --maxWorkers=2 --coverage

build-library:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -102,56 +102,56 @@ jobs:
- name: Build example for Android
env:
JAVA_OPTS: "-XX:MaxHeapSize=6g"
JAVA_OPTS: '-XX:MaxHeapSize=6g'
run: |
yarn turbo run build:android --cache-dir="${{ env.TURBO_CACHE_DIR }}"
build-ios:
runs-on: macos-14
env:
TURBO_CACHE_DIR: .turbo/ios
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup
uses: ./.github/actions/setup

- name: Cache turborepo for iOS
uses: actions/cache@v3
with:
path: ${{ env.TURBO_CACHE_DIR }}
key: ${{ runner.os }}-turborepo-ios-${{ hashFiles('yarn.lock') }}
restore-keys: |
${{ runner.os }}-turborepo-ios-
- name: Check turborepo cache for iOS
run: |
TURBO_CACHE_STATUS=$(node -p "($(yarn turbo run build:ios --cache-dir="${{ env.TURBO_CACHE_DIR }}" --dry=json)).tasks.find(t => t.task === 'build:ios').cache.status")
if [[ $TURBO_CACHE_STATUS == "HIT" ]]; then
echo "turbo_cache_hit=1" >> $GITHUB_ENV
fi
- name: Cache cocoapods
if: env.turbo_cache_hit != 1
id: cocoapods-cache
uses: actions/cache@v3
with:
path: |
**/ios/Pods
key: ${{ runner.os }}-cocoapods-${{ hashFiles('example/ios/Podfile.lock') }}
restore-keys: |
${{ runner.os }}-cocoapods-
- name: Install cocoapods
if: env.turbo_cache_hit != 1 && steps.cocoapods-cache.outputs.cache-hit != 'true'
run: |
cd example/ios
pod install
env:
NO_FLIPPER: 1

- name: Build example for iOS
run: |
yarn turbo run build:ios --cache-dir="${{ env.TURBO_CACHE_DIR }}"
#build-ios:
# runs-on: macos-14
# env:
# TURBO_CACHE_DIR: .turbo/ios
# steps:
# - name: Checkout
# uses: actions/checkout@v3

# - name: Setup
# uses: ./.github/actions/setup

# - name: Cache turborepo for iOS
# uses: actions/cache@v3
# with:
# path: ${{ env.TURBO_CACHE_DIR }}
# key: ${{ runner.os }}-turborepo-ios-${{ hashFiles('yarn.lock') }}
# restore-keys: |
# ${{ runner.os }}-turborepo-ios-

# - name: Check turborepo cache for iOS
# run: |
# TURBO_CACHE_STATUS=$(node -p "($(yarn turbo run build:ios --cache-dir="${{ env.TURBO_CACHE_DIR }}" --dry=json)).tasks.find(t => t.task === 'build:ios').cache.status")

# if [[ $TURBO_CACHE_STATUS == "HIT" ]]; then
# echo "turbo_cache_hit=1" >> $GITHUB_ENV
# fi

# - name: Cache cocoapods
# if: env.turbo_cache_hit != 1
# id: cocoapods-cache
# uses: actions/cache@v3
# with:
# path: |
# **/ios/Pods
# key: ${{ runner.os }}-cocoapods-${{ hashFiles('example/ios/Podfile.lock') }}
# restore-keys: |
# ${{ runner.os }}-cocoapods-

# - name: Install cocoapods
# if: env.turbo_cache_hit != 1 && steps.cocoapods-cache.outputs.cache-hit != 'true'
# run: |
# cd example/ios
# pod install
# env:
# NO_FLIPPER: 1

# - name: Build example for iOS
# run: |
# yarn turbo run build:ios --cache-dir="${{ env.TURBO_CACHE_DIR }}"
31 changes: 15 additions & 16 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,23 @@ export default function App() {
const baseName = defaultBasePrefix + '-' + defaultBasePostfix;

useEffect(() => {
loadBase();
// eslint-disable-next-line
}, []);
const loadBase = async (): Promise<void> => {
setPath((await getDatabasePath(baseName)) || "can't find path");

const loadBase = async (): Promise<void> => {
setPath((await getDatabasePath(baseName)) || "can't find path");
// инициализирую подключение к базе
try {
await DB.open(baseName);
setOpened(true);
} catch (error: any) {
Alert.alert(
'Внимание',
'Не удалось открыть базу данных: ' + error.message
);
}
};

// инициализирую подключение к базе
try {
await DB.open(baseName);
setOpened(true);
} catch (error: any) {
Alert.alert(
'Внимание',
'Не удалось открыть базу данных: ' + error.message
);
}
};
loadBase();
}, []);

return (
<View style={styles.container}>
Expand Down
1 change: 0 additions & 1 deletion example/src/models/DB.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// версия с шифрованием - https://github.com/axsy-dev/react-native-sqlcipher-storage
import { Alert } from 'react-native';
import { getDatabasePath } from '../../../src/utils';
import _ from 'lodash';

import SQLite from 'react-native-sqlite-storage'; // sselect sqlite_version() - "3.22.0"

Expand Down
135 changes: 74 additions & 61 deletions src/components/Table/TableModal.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useState } from 'react'
import { useEffect, useState } from 'react';
import { View } from 'react-native';
import { getInitialModel, isFieldRequired } from '../../Helpers';
import { ModalType, TableSignature, TableSignatureValue } from '../../types';
Expand All @@ -8,76 +8,89 @@ import Input from '../Input';
import Modal from '../Modal';

type TableModalProps = {
checkedRowValue: TableSignatureValue | null;
tableData: TableSignature;
modalType: ModalType;
onClose: () => void;
onSubmit: (model: TableSignatureValue) => void;
checkedRowValue: TableSignatureValue | null;
tableData: TableSignature;
modalType: ModalType;
onClose: () => void;
onSubmit: (model: TableSignatureValue) => void;
};

const TableModal = ({ checkedRowValue, tableData, modalType, onClose, onSubmit }: TableModalProps) => {
const [model, setModel] = useState<TableSignatureValue>({});
const [errors, setErrors] = useState<TableSignatureValue>({});
const TableModal = ({
checkedRowValue,
tableData,
modalType,
onClose,
onSubmit,
}: TableModalProps) => {
const [model, setModel] = useState<TableSignatureValue>({});
const [errors, setErrors] = useState<TableSignatureValue>({});

useEffect(() => {
setModel(getInitialModel(tableData.fields, modalType === 'update' ? checkedRowValue : null));
setErrors({});
}, [modalType])
useEffect(() => {
setModel(
getInitialModel(
tableData.fields,
modalType === 'update' ? checkedRowValue : null
)
);
setErrors({});
}, [modalType]);

const getValidate = (model: TableSignatureValue): TableSignatureValue => {
return tableData.fields.reduce((acc, field) => {
if (isFieldRequired(field.type)) {
Object.assign(acc, { [field.name]: !!model[field.name] ? '' : REQIRED_TEXT })
}
const getValidate = (model: TableSignatureValue): TableSignatureValue => {
return tableData.fields.reduce((acc, field) => {
if (isFieldRequired(field.type)) {
Object.assign(acc, {
[field.name]: !!model[field.name] ? '' : REQIRED_TEXT,
});
}

return acc;
}, {} as TableSignatureValue);
};
return acc;
}, {} as TableSignatureValue);
};

const onChange = (field: string, value: string) => {
const newModel = { ...model, [field]: value };
setModel(newModel);
const onChange = (field: string, value: string) => {
const newModel = { ...model, [field]: value };
setModel(newModel);

const _errors = getValidate(newModel);
setErrors({
...errors,
[field]: !!_errors[field] ? _errors[field] : '',
});
};
const _errors = getValidate(newModel);
setErrors({
...errors,
[field]: !!_errors[field] ? _errors[field] : '',
});
};

const onSubmitHandler = () => {
const _errors = getValidate(model);
const errorLength = Object.values(_errors).filter(a => !!a.length).length;
setErrors(_errors);
const onSubmitHandler = () => {
const _errors = getValidate(model);
const errorLength = Object.values(_errors).filter((a) => !!a.length).length;
setErrors(_errors);

if (!!errorLength) return;
if (!!errorLength) return;

onSubmit(model);
};
onSubmit(model);
};

return (
<Modal
visible={!!modalType}
title={`${modalType === 'add' ? `Add new ${tableData.name} record` : `Update ${tableData.name} record`}`}
onClose={onClose}
onSubmit={onSubmitHandler}
>
<View>
{tableData.fields.map(field =>
<Input
title={`${isFieldRequired(field.type) ? "*" : ""}${field.name} (${field.type})`}
key={`field-input-${field.name}`}
text={model[field.name]}
onChangeText={(value) => onChange(field.name, value)}
style={{ marginBottom: 6 }}
showMicrofone={false}
placeholder={`${field.name}`}
error={!!errors?.[field.name] ? errors[field.name] : false}
/>
)}
</View>
</Modal>
)
return (
<Modal
visible={!!modalType}
title={`${modalType === 'add' ? `Add new ${tableData.name} record` : `Update ${tableData.name} record`}`}
onClose={onClose}
onSubmit={onSubmitHandler}
>
<View>
{tableData.fields.map((field) => (
<Input
title={`${isFieldRequired(field.type) ? '*' : ''}${field.name} (${field.type})`}
key={`field-input-${field.name}`}
text={model[field.name]}
onChangeText={(value) => onChange(field.name, value)}
style={{ marginBottom: 6 }}
showMicrofone={false}
placeholder={`${field.name}`}
error={!!errors?.[field.name] ? errors[field.name] : false}
/>
))}
</View>
</Modal>
);
};

export default TableModal;
export default TableModal;
Loading

0 comments on commit 71e71b3

Please sign in to comment.