From a7e0f8cc479ac7a2af7a396180bd16397999cdfb Mon Sep 17 00:00:00 2001 From: Andreas Knudsen Alstrp Date: Fri, 24 Nov 2023 13:52:06 +0100 Subject: [PATCH 1/5] Init tests + setup GunDB test --- __tests__/CreateAccount.test.ts | 27 +++++ components/__tests__/StyledText-test.js | 10 -- jest.config.js | 9 ++ package-lock.json | 154 +++++++++++++++++++++++- package.json | 9 +- 5 files changed, 189 insertions(+), 20 deletions(-) create mode 100644 __tests__/CreateAccount.test.ts delete mode 100644 components/__tests__/StyledText-test.js create mode 100644 jest.config.js diff --git a/__tests__/CreateAccount.test.ts b/__tests__/CreateAccount.test.ts new file mode 100644 index 0000000..c5f68d4 --- /dev/null +++ b/__tests__/CreateAccount.test.ts @@ -0,0 +1,27 @@ +import Gun from "gun/gun"; +import SEA from 'gun/sea'; +import { IGunInstance, IGunInstanceRoot, IGunUserInstance, ISEA } from 'gun/types'; + +const gun = Gun({ + radisk: true, + localStorage: false +}); + +type GunDB = { + gun: IGunInstance, + user: IGunUserInstance>>, + SEA: ISEA, +} + +const GunDB: GunDB = { + gun: gun, + user: gun.user(), + SEA: SEA, +} + +test('first GunDb test', async () => { + GunDB.user.create('12345678', '12345678', (ack: any) => { + expect(ack.err).toBe(ack.err !== "User already created!"); + expect(ack.err).toBe(ack.err !== "Password too short!"); + }); +}) \ No newline at end of file diff --git a/components/__tests__/StyledText-test.js b/components/__tests__/StyledText-test.js deleted file mode 100644 index f569ce8..0000000 --- a/components/__tests__/StyledText-test.js +++ /dev/null @@ -1,10 +0,0 @@ -import * as React from 'react'; -import renderer from 'react-test-renderer'; - -import { MonoText } from '../StyledText'; - -it(`renders correctly`, () => { - const tree = renderer.create(Snapshot test!).toJSON(); - - expect(tree).toMatchSnapshot(); -}); diff --git a/jest.config.js b/jest.config.js new file mode 100644 index 0000000..e318e14 --- /dev/null +++ b/jest.config.js @@ -0,0 +1,9 @@ +module.exports = { + testEnvironment: 'node', + transform: { + '^.+\\.ts?$': 'ts-jest', + }, + moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'], + transformIgnorePatterns: ['/node_modules/'], + forceExit: true, // Gun keeps background workers running, which do not exit as of v0.2020.520. + }; \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 68018c0..5937034 100644 --- a/package-lock.json +++ b/package-lock.json @@ -43,11 +43,13 @@ }, "devDependencies": { "@babel/core": "^7.20.0", + "@types/jest": "^29.5.10", "@types/react": "~18.2.14", - "jest": "^29.2.1", + "jest": "^29.7.0", "jest-expo": "~49.0.0", "react-test-renderer": "18.2.0", - "typescript": "^5.1.3" + "ts-jest": "^29.1.1", + "typescript": "^5.3.2" } }, "node_modules/@ampproject/remapping": { @@ -6580,6 +6582,48 @@ "@types/istanbul-lib-report": "*" } }, + "node_modules/@types/jest": { + "version": "29.5.10", + "resolved": "https://registry.npmjs.org/@types/jest/-/jest-29.5.10.tgz", + "integrity": "sha512-tE4yxKEphEyxj9s4inideLHktW/x6DwesIwWZ9NN1FKf9zbJYsnhBoA9vrHA/IuIOKwPa5PcFBNV4lpMIOEzyQ==", + "dev": true, + "dependencies": { + "expect": "^29.0.0", + "pretty-format": "^29.0.0" + } + }, + "node_modules/@types/jest/node_modules/ansi-styles": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-5.2.0.tgz", + "integrity": "sha512-Cxwpt2SfTzTtXcfOlzGEee8O+c+MmUgGrNiBcXnuWxuFJHe6a5Hz7qwhwe5OgaSYI0IJvkLqWX1ASG+cJOkEiA==", + "dev": true, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/ansi-styles?sponsor=1" + } + }, + "node_modules/@types/jest/node_modules/pretty-format": { + "version": "29.7.0", + "resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-29.7.0.tgz", + "integrity": "sha512-Pdlw/oPxN+aXdmM9R00JVC9WVFoCLTKJvDVLgmJ+qAffBMxsV85l/Lu7sNx4zSzPyoL2euImuEwHhOXdEgNFZQ==", + "dev": true, + "dependencies": { + "@jest/schemas": "^29.6.3", + "ansi-styles": "^5.0.0", + "react-is": "^18.0.0" + }, + "engines": { + "node": "^14.15.0 || ^16.10.0 || >=18.0.0" + } + }, + "node_modules/@types/jest/node_modules/react-is": { + "version": "18.2.0", + "resolved": "https://registry.npmjs.org/react-is/-/react-is-18.2.0.tgz", + "integrity": "sha512-xWGDIW6x921xtzPkhiULtthJHoJvBbF3q26fzloPCK0hsvxtPVelvftw3zjbHWSkR2km9Z+4uxbDDK/6Zw9B8w==", + "dev": true + }, "node_modules/@types/jsdom": { "version": "20.0.1", "resolved": "https://registry.npmjs.org/@types/jsdom/-/jsdom-20.0.1.tgz", @@ -8673,6 +8717,18 @@ "node": "^6 || ^7 || ^8 || ^9 || ^10 || ^11 || ^12 || >=13.7" } }, + "node_modules/bs-logger": { + "version": "0.2.6", + "resolved": "https://registry.npmjs.org/bs-logger/-/bs-logger-0.2.6.tgz", + "integrity": "sha512-pd8DCoxmbgc7hyPKOvxtqNcjYoOsABPQdcCUjGp3d42VR2CX1ORhk2A87oqqu5R1kk+76nsxZupkmyd+MVtCog==", + "dev": true, + "dependencies": { + "fast-json-stable-stringify": "2.x" + }, + "engines": { + "node": ">= 6" + } + }, "node_modules/bser": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/bser/-/bser-2.1.1.tgz", @@ -14719,6 +14775,12 @@ "resolved": "https://registry.npmjs.org/lodash.debounce/-/lodash.debounce-4.0.8.tgz", "integrity": "sha512-FT1yDzDYEoYWhnSGnpE/4Kj1fLZkDFyqRb7fNt6FdYOSxlUWAtp42Eh6Wb0rGIv/m9Bgo7x4GhQbm5Ys4SG5ow==" }, + "node_modules/lodash.memoize": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/lodash.memoize/-/lodash.memoize-4.1.2.tgz", + "integrity": "sha512-t7j+NzmgnQzTAYXcsHYLgimltOV1MXHtlOWf6GjL9Kj8GK5FInw5JotxvbOs+IvV1/Dzo04/fCGfLVs7aXb4Ag==", + "dev": true + }, "node_modules/lodash.throttle": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/lodash.throttle/-/lodash.throttle-4.1.1.tgz", @@ -14954,6 +15016,12 @@ "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==", "dev": true }, + "node_modules/make-error": { + "version": "1.3.6", + "resolved": "https://registry.npmjs.org/make-error/-/make-error-1.3.6.tgz", + "integrity": "sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==", + "dev": true + }, "node_modules/makeerror": { "version": "1.0.12", "resolved": "https://registry.npmjs.org/makeerror/-/makeerror-1.0.12.tgz", @@ -18969,6 +19037,82 @@ "resolved": "https://registry.npmjs.org/ts-interface-checker/-/ts-interface-checker-0.1.13.tgz", "integrity": "sha512-Y/arvbn+rrz3JCKl9C4kVNfTfSm2/mEp5FSz5EsZSANGPSlQrpRI5M4PKF+mJnE52jOO90PnPSc3Ur3bTQw0gA==" }, + "node_modules/ts-jest": { + "version": "29.1.1", + "resolved": "https://registry.npmjs.org/ts-jest/-/ts-jest-29.1.1.tgz", + "integrity": "sha512-D6xjnnbP17cC85nliwGiL+tpoKN0StpgE0TeOjXQTU6MVCfsB4v7aW05CgQ/1OywGb0x/oy9hHFnN+sczTiRaA==", + "dev": true, + "dependencies": { + "bs-logger": "0.x", + "fast-json-stable-stringify": "2.x", + "jest-util": "^29.0.0", + "json5": "^2.2.3", + "lodash.memoize": "4.x", + "make-error": "1.x", + "semver": "^7.5.3", + "yargs-parser": "^21.0.1" + }, + "bin": { + "ts-jest": "cli.js" + }, + "engines": { + "node": "^14.15.0 || ^16.10.0 || >=18.0.0" + }, + "peerDependencies": { + "@babel/core": ">=7.0.0-beta.0 <8", + "@jest/types": "^29.0.0", + "babel-jest": "^29.0.0", + "jest": "^29.0.0", + "typescript": ">=4.3 <6" + }, + "peerDependenciesMeta": { + "@babel/core": { + "optional": true + }, + "@jest/types": { + "optional": true + }, + "babel-jest": { + "optional": true + }, + "esbuild": { + "optional": true + } + } + }, + "node_modules/ts-jest/node_modules/lru-cache": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", + "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", + "dev": true, + "dependencies": { + "yallist": "^4.0.0" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/ts-jest/node_modules/semver": { + "version": "7.5.4", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.5.4.tgz", + "integrity": "sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA==", + "dev": true, + "dependencies": { + "lru-cache": "^6.0.0" + }, + "bin": { + "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/ts-jest/node_modules/yallist": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", + "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==", + "dev": true + }, "node_modules/tslib": { "version": "2.6.2", "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.6.2.tgz", @@ -19006,9 +19150,9 @@ } }, "node_modules/typescript": { - "version": "5.2.2", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.2.2.tgz", - "integrity": "sha512-mI4WrpHsbCIcwT9cF4FZvr80QUeKvsUsUvKDoR+X/7XHQH98xYD8YHZg7ANtz2GtZt/CBq2QJ0thkGJMHfqc1w==", + "version": "5.3.2", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.3.2.tgz", + "integrity": "sha512-6l+RyNy7oAHDfxC4FzSJcz9vnjTKxrLpDG5M2Vu4SHRVNg6xzqZp6LYSR9zjqQTu8DU/f5xwxUdADOkbrIX2gQ==", "dev": true, "bin": { "tsc": "bin/tsc", diff --git a/package.json b/package.json index 8b7da7f..279b1ee 100644 --- a/package.json +++ b/package.json @@ -10,9 +10,6 @@ "test": "jest --watchAll", "postinstall": "npx jscodeshift --force --babel --transform ./node_modules/babel-plugin-react-rename-unsafe-lifecycle/lib/rename-unsafe-lifecycles.js ./node_modules/react-native-action-button" }, - "jest": { - "preset": "jest-expo" - }, "dependencies": { "@bacons/expo-router-top-tabs": "^0.1.0", "@expo/vector-icons": "^13.0.0", @@ -48,11 +45,13 @@ }, "devDependencies": { "@babel/core": "^7.20.0", + "@types/jest": "^29.5.10", "@types/react": "~18.2.14", - "jest": "^29.2.1", + "jest": "^29.7.0", "jest-expo": "~49.0.0", "react-test-renderer": "18.2.0", - "typescript": "^5.1.3" + "ts-jest": "^29.1.1", + "typescript": "^5.3.2" }, "overrides": { "react-refresh": "~0.14.0", From f24deaf5271799fe3752392b90f5667b2b2aaf1c Mon Sep 17 00:00:00 2001 From: Mike Jensen Date: Wed, 29 Nov 2023 13:20:49 +0100 Subject: [PATCH 2/5] Create calculateExpenses.test.ts --- __test__/unitTests/calculateExpenses.test.ts | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 __test__/unitTests/calculateExpenses.test.ts diff --git a/__test__/unitTests/calculateExpenses.test.ts b/__test__/unitTests/calculateExpenses.test.ts new file mode 100644 index 0000000..e69de29 From dac3b2daae56faa30c2ca216aebb837c977e29c4 Mon Sep 17 00:00:00 2001 From: Mike Jensen <43805784+mikejensen0@users.noreply.github.com> Date: Wed, 29 Nov 2023 13:33:16 +0100 Subject: [PATCH 3/5] Update package.json --- package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/package.json b/package.json index 1c5f20a..4ff35e6 100644 --- a/package.json +++ b/package.json @@ -62,7 +62,6 @@ "devDependencies": { "@babel/core": "^7.20.0", "@types/jest": "^29.5.10", -======= "@types/gun": "^0.9.5", "@types/react": "~18.2.14", "jest": "^29.7.0", From 986f4624938d1542b86d6b34328e32197bea2f06 Mon Sep 17 00:00:00 2001 From: Mike Jensen Date: Wed, 29 Nov 2023 13:40:56 +0100 Subject: [PATCH 4/5] Revert "Update package.json" This reverts commit dac3b2daae56faa30c2ca216aebb837c977e29c4. --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 4ff35e6..1c5f20a 100644 --- a/package.json +++ b/package.json @@ -62,6 +62,7 @@ "devDependencies": { "@babel/core": "^7.20.0", "@types/jest": "^29.5.10", +======= "@types/gun": "^0.9.5", "@types/react": "~18.2.14", "jest": "^29.7.0", From 9b82cf647faaf805d19ab706f6bcb938edfa1baa Mon Sep 17 00:00:00 2001 From: Mike Jensen Date: Wed, 29 Nov 2023 13:41:02 +0100 Subject: [PATCH 5/5] Revert "Merge branch '55-test' into issue/45-test" This reverts commit e9d2cb9c26fda954855a63d368217dc22fa93c8a, reversing changes made to a7e0f8cc479ac7a2af7a396180bd16397999cdfb. --- .github/workflows/build.yml | 6 +- .github/workflows/update.yml | 3 - __test__/unitTests/calculateExpenses.test.ts | 0 app/(login)/CreateAccountScreen.tsx | 160 - app/(login)/GroupScreen.tsx | 5 - app/(login)/LoginScreen.tsx | 89 - app/(login)/styles.tsx | 80 - .../{shoppingList => (index)}/_layout.tsx | 0 .../{shoppingList => (index)}/bought.tsx | 0 .../{shoppingList => (index)}/index.tsx | 76 +- app/(tabs)/_layout.tsx | 18 +- app/(tabs)/expenses/balance.tsx | 7 +- app/(tabs)/expenses/index.tsx | 25 +- app/(tabs)/notice.tsx | 3 +- app/(tabs)/settings.tsx | 117 +- app/_layout.tsx | 12 +- app/index.tsx | 12 - assets/images/accountScreensImage.png | Bin 3879809 -> 0 bytes assets/images/coshareLogo.png | Bin 2956 -> 0 bytes babel.config.js | 1 + components/AreYouSureModal.tsx | 83 - components/LogoAndName.tsx | 30 - constants/Database.ts | 32 - hooks/useGun.ts | 15 + package-lock.json | 2852 +++++------------ package.json | 30 +- 26 files changed, 821 insertions(+), 2835 deletions(-) delete mode 100644 __test__/unitTests/calculateExpenses.test.ts delete mode 100644 app/(login)/CreateAccountScreen.tsx delete mode 100644 app/(login)/GroupScreen.tsx delete mode 100644 app/(login)/LoginScreen.tsx delete mode 100644 app/(login)/styles.tsx rename app/(tabs)/{shoppingList => (index)}/_layout.tsx (100%) rename app/(tabs)/{shoppingList => (index)}/bought.tsx (100%) rename app/(tabs)/{shoppingList => (index)}/index.tsx (79%) delete mode 100644 app/index.tsx delete mode 100644 assets/images/accountScreensImage.png delete mode 100644 assets/images/coshareLogo.png delete mode 100644 components/AreYouSureModal.tsx delete mode 100644 components/LogoAndName.tsx delete mode 100644 constants/Database.ts create mode 100644 hooks/useGun.ts diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e70d54a..b3408b6 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -2,9 +2,9 @@ name: Build on: workflow_dispatch: - # pull_request: - # branches: - # - main + pull_request: + branches: + - main jobs: build: diff --git a/.github/workflows/update.yml b/.github/workflows/update.yml index 0e1d292..35ddb90 100644 --- a/.github/workflows/update.yml +++ b/.github/workflows/update.yml @@ -2,9 +2,6 @@ name: Update on: workflow_dispatch: - pull_request: - branches: - - main push: branches: - main diff --git a/__test__/unitTests/calculateExpenses.test.ts b/__test__/unitTests/calculateExpenses.test.ts deleted file mode 100644 index e69de29..0000000 diff --git a/app/(login)/CreateAccountScreen.tsx b/app/(login)/CreateAccountScreen.tsx deleted file mode 100644 index 681cc91..0000000 --- a/app/(login)/CreateAccountScreen.tsx +++ /dev/null @@ -1,160 +0,0 @@ -import styles from './styles' -import { Text, View, } from '../../components/Themed'; -import { TextInput } from 'react-native-gesture-handler'; -import { ImageBackground, Pressable } from 'react-native'; -import { router } from 'expo-router'; -import { MaterialCommunityIcons } from '@expo/vector-icons'; -import { LogoAndName } from '../../components/LogoAndName'; -import { useState } from 'react'; - -export default function CreateAccountScreen () { - const [phoneNumber, setPhoneNumber] = useState('') - const [password, setPassword] = useState('') - const [repeatPassword, setRepeatPassword] = useState('') - const [fullName, setFullName] = useState('') - const [email, setEmail] = useState('') - const [error, setError] = useState('') - const [showWrongPasswords, setShowWrongPasswords] = useState(false) - const [hidePassword, setHidePassword] = useState(true) - const [submitActive, setSubmitActive] = useState(false) - const [creatingUser, setCreatingUser] = useState(false) - - const toggleHidePassword = () => setHidePassword(!hidePassword) - - const validatePhone = (phone : string) => phone.length == 8 - - const validatePass = (pass: string) => pass.length > 7 - - function passwordsMatch (pass : string, repPass : string) { - let equal : boolean = pass == repPass - let value : boolean = (pass != '' && repPass != '') && (!equal) - setShowWrongPasswords(value) - return equal - } - - function toggleSubmitButton (phone : string, pass : string, repPass : string) { //We need params to mitigate the async updating - setSubmitActive(passwordsMatch(pass, repPass) && validatePhone(phone) && validatePass(pass)) - } - - function createAccount(ack : any) { - if (ack?.err){ - setCreatingUser(false); - console.log("Some error on user creation") - if (ack.err == "User already created!"){ - setError("User already exists") - } - else{//The other possible error is: "User is already being created or authenticated!" which probably means the user has clicked create user multiple times - return - } - } - else{ - let newUser = gun.user(ack.pub) - if (fullName != ''){ - newUser.get('fullName').put(fullName) - } - if (email != '') { - newUser.get('email').put(email) - } - setShowWrongPasswords(false) - user.auth(phoneNumber,password, login) - } - } - - function login (ack : any) { - if (!ack.err){ - if (user.is){ - console.log("Redirect to GroupScreen") - router.replace('/GroupScreen') - } - else{ - console.log("User somehow doesn't exist"); - } - } - else{ - console.log("Newly created user cannot be authenticated, something went wrong with the database"); - // Not sure how this should be handled - } - } - - return ( - <> - - - - - {error != "" && {error} } - Phone Number* - - { - setPhoneNumber(newPhoneNumber) - toggleSubmitButton(newPhoneNumber, password, repeatPassword) - } - }/> - - Password* - - { - setPassword(newPassword) - toggleSubmitButton(phoneNumber, newPassword, repeatPassword) - } - } - /> - - - {!validatePass(password) && Password needs at least 7 characters} - Repeat Password* - - { - setRepeatPassword(newRepeatPassword) - toggleSubmitButton(phoneNumber, password, newRepeatPassword) - } - } - /> - - {showWrongPasswords && Passwords do not match} - Full Name - - setFullName(fullName)} - /> - - E-mail - - - setEmail(email)} - /> - - - { - setCreatingUser(true); - user.create(phoneNumber, password, createAccount) - } : () => {}}> - Create account - - - - - ) - -} \ No newline at end of file diff --git a/app/(login)/GroupScreen.tsx b/app/(login)/GroupScreen.tsx deleted file mode 100644 index 4e1fa1a..0000000 --- a/app/(login)/GroupScreen.tsx +++ /dev/null @@ -1,5 +0,0 @@ -import { Redirect } from 'expo-router'; - -export default function GroupScreen() { - return -} \ No newline at end of file diff --git a/app/(login)/LoginScreen.tsx b/app/(login)/LoginScreen.tsx deleted file mode 100644 index 0787fa8..0000000 --- a/app/(login)/LoginScreen.tsx +++ /dev/null @@ -1,89 +0,0 @@ -import styles from './styles' -import { Text, View, } from '../../components/Themed'; -import { TextInput } from 'react-native-gesture-handler'; -import { ImageBackground, Pressable } from 'react-native'; -import { useState } from 'react'; -import { Link, router } from 'expo-router'; -import { MaterialCommunityIcons } from '@expo/vector-icons'; -import { LogoAndName } from '../../components/LogoAndName'; - -export default function loginScreen () { - const [phoneNumber, setPhoneNumber] = useState('12345678') - const [password, setPassword] = useState('12345678') - const [wrongCredentials, setWrongCredentials] = useState(false) - const [hidePassword, setHidePassword] = useState(true) - const [authing, setAuthing] = useState(false) - - const toggleHidePassword = () => setHidePassword(!hidePassword) - - function checkSuccesfulLogin (ack: any) { - if (!ack.err){ - if (user.is){ - let newUser = gun.user(ack.pub) - let inGroup = true - newUser.get("group").once((ack) =>{ - if(ack == undefined){ - console.log("Group not found") - router.replace('/GroupScreen') - } else { - console.log("Group found") - router.replace('../(tabs)/ShoppingList/index') - } - }) - }else{ - console.log("User somehow doesn't exist"); - } - }else{ - setWrongCredentials(true) - setAuthing(false) - } - } - return ( - - - - Phone Number - - { - setPhoneNumber(phoneNumber) - } - } - /> - - Password - - setPassword(password)} - /> - - - - {wrongCredentials && Wrong credentials} - - - { - if (!authing){ - setAuthing(true) - user.auth(phoneNumber,password, checkSuccesfulLogin) - } - }}> - Sign in - - Create new account - - - - ); - } - diff --git a/app/(login)/styles.tsx b/app/(login)/styles.tsx deleted file mode 100644 index 8a350e6..0000000 --- a/app/(login)/styles.tsx +++ /dev/null @@ -1,80 +0,0 @@ -import { StyleSheet } from 'react-native'; -import {Dimensions} from 'react-native'; -const styles = StyleSheet.create({ - container: { - flex: 1, - alignItems: 'center', - justifyContent: 'center', - }, - title: { - fontSize: 20, - fontWeight: 'bold', - }, - error: { - fontSize: 14, - fontWeight: 'bold', - color: "red", - }, - descriptiveText: { - fontSize: 13, - color: "white", - }, - separator: { - marginVertical: 30, - height: 1, - width: '80%', - }, - inputField: { - height: 40, - width: 200, - - justifyContent: 'center', - color: "white", - }, - eye: { - marginLeft: -24, - color:"#aaa", - }, - inputBox: { - flexDirection: 'row', - alignItems: 'center', - backgroundColor: 'black', - opacity: 0.7, - borderRadius: 4, - color: "white", - }, - backgroundImage: { - justifyContent: 'center', - width: Dimensions.get('window').width, - height: Dimensions.get('window').height, - alignItems: 'center', - resizeMode: 'cover', - }, - button: { - alignItems: 'center', - justifyContent: 'center', - paddingVertical: 12, - paddingHorizontal: 32, - borderRadius: 4, - elevation: 3, - width: 0.6 * Dimensions.get('window').width, - backgroundColor: '#5CBCA9', - }, - disabledButton: { - alignItems: 'center', - justifyContent: 'center', - paddingVertical: 12, - paddingHorizontal: 32, - borderRadius: 4, - elevation: 3, - width: 0.6 * Dimensions.get('window').width, - backgroundColor: 'grey', - }, - buttonText: { - color: "white", - fontSize: 15, - fontWeight: "bold", - }, - }); - - export default styles \ No newline at end of file diff --git a/app/(tabs)/shoppingList/_layout.tsx b/app/(tabs)/(index)/_layout.tsx similarity index 100% rename from app/(tabs)/shoppingList/_layout.tsx rename to app/(tabs)/(index)/_layout.tsx diff --git a/app/(tabs)/shoppingList/bought.tsx b/app/(tabs)/(index)/bought.tsx similarity index 100% rename from app/(tabs)/shoppingList/bought.tsx rename to app/(tabs)/(index)/bought.tsx diff --git a/app/(tabs)/shoppingList/index.tsx b/app/(tabs)/(index)/index.tsx similarity index 79% rename from app/(tabs)/shoppingList/index.tsx rename to app/(tabs)/(index)/index.tsx index 8d982bf..ce86d39 100644 --- a/app/(tabs)/shoppingList/index.tsx +++ b/app/(tabs)/(index)/index.tsx @@ -1,8 +1,8 @@ -import { Button, Pressable, StyleSheet, TextInput, TouchableOpacity, useColorScheme } from 'react-native'; +import { Button, Pressable, StyleSheet, TextInput, useColorScheme } from 'react-native'; import Modal from "react-native-modal"; import { Text, View, } from '../../../components/Themed'; import { useState } from 'react'; -import { FlatList, Gesture, GestureDetector } from 'react-native-gesture-handler'; +import { FlatList } from 'react-native-gesture-handler'; import { FontAwesome5 } from '@expo/vector-icons'; import CheckBox from 'expo-checkbox'; import Swipeable from 'react-native-gesture-handler/Swipeable'; @@ -10,6 +10,9 @@ import Colors from '../../../constants/Colors'; import ActionButton from 'react-native-action-button'; import { MultiSelect } from 'react-native-element-dropdown'; import moment from 'moment'; +import { LogBox } from 'react-native'; + +LogBox.ignoreLogs(['Warning: componentWillReceiveProps has been renamed']); const usersDropdown = [ { label: 'Test bruger', value: 'Test bruger' }, @@ -75,7 +78,7 @@ function rightSwipeAction() { export default function ToBeBoughtScreen() { const colorScheme = useColorScheme() ?? 'light'; - const [isModalAddOrEditItemVisible, setIsModalAddOrEditItemVisible] = useState(false); + const [isModalAddItemVisible, setIsModalAddItemVisible] = useState(false); const [isModalDeleteVisible, setIsModalDeleteVisible] = useState(false); const [products, setProducts] = useState(seedData) @@ -84,49 +87,20 @@ export default function ToBeBoughtScreen() { const [alreadyBought, setAlreadyBought] = useState(false); const [price, setPrice] = useState('0'); - const [itemToEdit, setItemToEdit] = useState() const [itemToDelete, setItemToDelete] = useState(0) const swipeableRows : Swipeable[] = [] - const handleModalAddOrEditItem = () => { console.log(!isModalAddOrEditItemVisible); setIsModalAddOrEditItemVisible(() => !isModalAddOrEditItemVisible); } + const handleModalAddItem = () => setIsModalAddItemVisible(() => !isModalAddItemVisible); const handleModalDelete = () => setIsModalDeleteVisible(() => !isModalDeleteVisible); const handleCheckbox = () => setAlreadyBought(() => !alreadyBought); - const clearProduct = () => { setProductName('') setSelectedUsers(usersDropdown.map((user) => user.value)) setAlreadyBought(false) setPrice('0') - setItemToEdit(undefined) - } - - const editProduct = (index : number) => { - setProductName(products[index].name) - setSelectedUsers(products[index].data.users.map((user) => user.name)) - } - - const saveEditedProduct = () => { - setProducts(products.map((product, index) => { - if (itemToEdit && product === products[itemToEdit]) { - return { ...product, - name: productName, - data: { - ...product.data, - users: selectedUsers.map(user => ({name: user})), - bought: alreadyBought ? {user: "Me", date: moment().format('YYYY.MM.DD'), price: Number(price)} : undefined - } - } - } - else { - return product; - } - })) - - handleModalAddOrEditItem() } - - const saveAddedProduct = () => { + const addProduct = () => { const time = moment().format('YYYY.MM.DD'); const newProduct = { name: productName, @@ -136,17 +110,17 @@ export default function ToBeBoughtScreen() { bought: alreadyBought ? {user: "Me", date: time, price: Number(price)} : undefined } } - if(newProduct.data.bought === undefined) { + if(newProduct.data.bought === undefined){ //Add to GUN here console.log(newProduct.name + ' added') } - else { + else{ //Move to GUN bought list here console.log(newProduct.name + ' bought by ' + newProduct.data.bought.user) } setProducts(products => [...products, newProduct]) - handleModalAddOrEditItem() + handleModalAddItem() } function swipeHandler(dir: 'left' | 'right', index: number) { @@ -188,21 +162,13 @@ export default function ToBeBoughtScreen() { renderLeftActions={leftSwipeAction} renderRightActions={rightSwipeAction} onSwipeableOpen={(dir) => swipeHandler(dir, index)}> - - { - setItemToEdit(index) - editProduct(index) - handleModalAddOrEditItem() - })}> - - - {item.name} - - Added by {item.data.added.user} {item.data.added.date} - - - + + + {item.name} + + Added by {item.data.added.user} {item.data.added.date} + ) } @@ -214,7 +180,7 @@ export default function ToBeBoughtScreen() { data={products} renderItem={renderItem} /> - setIsModalAddOrEditItemVisible(false)} onModalHide={clearProduct}> + Product : null} -