├── .eslintrc ├── .gitignore ├── LICENSE ├── README.md ├── assets ├── carbon.png ├── deploy-function-1.png ├── deploy-function-14.png ├── react-integration-3.gif ├── token.png └── users-2.gif ├── example ├── README.md ├── package-lock.json ├── package.json ├── public │ ├── favicon.ico │ ├── index.html │ └── manifest.json ├── src │ ├── App.tsx │ ├── CardElement.tsx │ ├── DbCardElement.tsx │ ├── DbExample.tsx │ ├── ProjectUser.tsx │ ├── QueryCardElement.tsx │ ├── QueryExample.tsx │ ├── UseReturnExample.tsx │ ├── UseReturnStressTest.tsx │ ├── index.tsx │ ├── react-app-env.d.ts │ └── styles.css └── tsconfig.json ├── native-example ├── .buckconfig ├── .gitattributes ├── .gitignore ├── App.js ├── android │ ├── app │ │ ├── BUCK │ │ ├── build.gradle │ │ ├── build_defs.bzl │ │ ├── debug.keystore │ │ ├── proguard-rules.pro │ │ └── src │ │ │ ├── debug │ │ │ ├── AndroidManifest.xml │ │ │ └── java │ │ │ │ └── com │ │ │ │ └── nativeexample │ │ │ │ └── ReactNativeFlipper.java │ │ │ └── main │ │ │ ├── AndroidManifest.xml │ │ │ ├── java │ │ │ └── com │ │ │ │ └── nativeexample │ │ │ │ ├── MainActivity.java │ │ │ │ └── MainApplication.java │ │ │ └── res │ │ │ ├── drawable │ │ │ ├── splashscreen.xml │ │ │ └── splashscreen_image.png │ │ │ ├── mipmap-hdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-mdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xhdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xxhdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xxxhdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ │ └── values │ │ │ ├── colors.xml │ │ │ ├── strings.xml │ │ │ └── styles.xml │ ├── build.gradle │ ├── gradle.properties │ ├── gradle │ │ └── wrapper │ │ │ ├── gradle-wrapper.jar │ │ │ └── gradle-wrapper.properties │ ├── gradlew │ ├── gradlew.bat │ └── settings.gradle ├── app.json ├── babel.config.js ├── index.js ├── ios │ ├── Podfile │ ├── Podfile.lock │ ├── nativeexample.xcodeproj │ │ ├── project.pbxproj │ │ └── xcshareddata │ │ │ └── xcschemes │ │ │ └── nativeexample.xcscheme │ ├── nativeexample.xcworkspace │ │ ├── contents.xcworkspacedata │ │ └── xcshareddata │ │ │ └── IDEWorkspaceChecks.plist │ └── nativeexample │ │ ├── AppDelegate.h │ │ ├── AppDelegate.m │ │ ├── Base.lproj │ │ └── LaunchScreen.xib │ │ ├── Images.xcassets │ │ ├── AppIcon.appiconset │ │ │ └── Contents.json │ │ ├── Contents.json │ │ ├── SplashScreen.imageset │ │ │ ├── Contents.json │ │ │ └── splashscreen.png │ │ └── SplashScreenBackground.imageset │ │ │ ├── Contents.json │ │ │ └── background.png │ │ ├── Info.plist │ │ ├── SplashScreen.storyboard │ │ ├── Supporting │ │ └── Expo.plist │ │ └── main.m ├── metro.config.js └── package.json ├── native └── package.json ├── package.json ├── src ├── EasybaseContext.tsx ├── EasybaseProvider.tsx ├── assets │ ├── image-extensions.json │ └── video-extensions.json ├── cache.native.ts ├── cache.ts ├── callFunction.tsx ├── index.tsx ├── storage │ ├── error.js │ ├── index.d.ts │ └── index.js ├── types │ ├── decs.d.ts │ ├── react-app-env.d.ts │ ├── types.tsx │ └── typings.d.ts ├── ui │ ├── Auth │ │ ├── Auth.tsx │ │ ├── components │ │ │ ├── Container.tsx │ │ │ ├── EmailInput.tsx │ │ │ ├── ErrorText.tsx │ │ │ ├── ForgotPassword.tsx │ │ │ ├── Form.tsx │ │ │ ├── GenderSelect.tsx │ │ │ ├── HeaderText.tsx │ │ │ ├── PasswordInput.tsx │ │ │ ├── SecondaryButton.tsx │ │ │ ├── SecondaryText.tsx │ │ │ ├── Spacer.tsx │ │ │ ├── SubmitButton.tsx │ │ │ └── internal │ │ │ │ ├── Input.tsx │ │ │ │ ├── Label.tsx │ │ │ │ ├── Select.tsx │ │ │ │ └── TextButton.tsx │ │ ├── index.tsx │ │ └── pages │ │ │ ├── ForgotPassword.tsx │ │ │ ├── SignIn.tsx │ │ │ └── SignUp.tsx │ ├── NativeAuth │ │ ├── NativeAuth.tsx │ │ ├── components.tsx │ │ └── pages │ │ │ ├── ForgotPassword.tsx │ │ │ ├── SignIn.tsx │ │ │ └── SignUp.tsx │ ├── ReactNative.tsx │ ├── themes │ │ ├── material.ts │ │ ├── minimal-dark.ts │ │ └── minimal.ts │ ├── uiTypes.ts │ └── utils.tsx └── useEasybase.tsx ├── tsconfig.json └── typedoc.json /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "parser": "@typescript-eslint/parser", 3 | "extends": [ 4 | "standard", 5 | "standard-react", 6 | "plugin:@typescript-eslint/eslint-recommended" 7 | ], 8 | "env": { 9 | "node": true 10 | }, 11 | "parserOptions": { 12 | "ecmaVersion": 2020, 13 | "ecmaFeatures": { 14 | "legacyDecorators": true, 15 | "jsx": true 16 | } 17 | }, 18 | "settings": { 19 | "react": { 20 | "version": "16" 21 | } 22 | }, 23 | "rules": { 24 | "space-before-function-paren": 0, 25 | "react/prop-types": 0, 26 | "react/jsx-handler-names": 0, 27 | "react/jsx-fragments": 0, 28 | "react/no-unused-prop-types": 0, 29 | "react/jsx-indent": 0, 30 | "import/export": 0, 31 | "indent": 0, 32 | "semi": 0, 33 | "quotes": 0, 34 | "no-trailing-spaces": 0, 35 | "no-unused-vars": 0, 36 | "jsx-quotes": 0, 37 | "react/jsx-indent-props": 0, 38 | "no-use-before-define": 0 39 | } 40 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # builds 2 | build 3 | dist 4 | .rpt2_cache 5 | 6 | # misc 7 | .DS_Store 8 | .env 9 | .env.local 10 | .env.development.local 11 | .env.test.local 12 | .env.production.local 13 | 14 | npm-debug.log* 15 | yarn-debug.log* 16 | yarn-error.log* 17 | 18 | .vscode/* 19 | node_modules/* 20 | package-lock.json 21 | 22 | example/node_modules/* 23 | 24 | ebconfig.json 25 | ebconfig.js 26 | 27 | ebconfig2.json 28 | ebconfig2.js 29 | 30 | docs/* 31 | docs-api/* 32 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Easybase Inc. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |
2 |
3 | 4 |

5 | 6 | easybase logo black 7 | 8 |

9 | 10 |
11 | 12 |

13 | npm 14 | GitHub 15 | npm bundle size 16 | npm 17 |

18 | 19 | 20 |

21 | 22 | 23 | Check out the full React & React Native walkthrough 📗📘 24 | 25 | 26 |

27 | 28 |
29 | 30 | 31 | ## Documentation 32 | 33 | Formal documentation for this library [is available here](https://easybase.io/docs/easybase-react/). 34 | 35 | Information on **database querying** [can be found in the EasyQB docs](https://easybase.github.io/EasyQB/). 36 | 37 | ## Getting Started 38 | 39 | [Get your project up and running in just a couple of minutes](https://easybase.io/react/#setup): 40 | 41 | 1. Download your `ebconfig` token and place it at the root of your project 42 | 43 | ``` 44 | ├── src/ 45 | │ ├── App.js 46 | │ ├── index.js 47 | │ └── ebconfig.js <––– 48 | ├── assets/ 49 | ├── package.json 50 | └── ... 51 | ``` 52 | 53 | 2. Then, wrap your root component in *EasybaseProvider* with your credentials. 54 | ``` 55 | npm install easybase-react 56 | ``` 57 | 58 | ```jsx 59 | import React, { useEffect } from "react"; 60 | import { EasybaseProvider, useEasybase } from 'easybase-react'; 61 | import ebconfig from "./ebconfig"; 62 | 63 | function App() { 64 | return ( 65 | 66 | 67 | 68 | ); 69 | } 70 | ``` 71 | 72 | ## Examples 73 | 74 | * [Single Component User Authentication](https://easybase.io/react-and-react-native-user-authentication/) 75 | 76 | * [Stateful Database](https://easybase.io/react-database-app-tutorial/) 77 | 78 | * [Google Analytics Integration](https://easybase.io/react/#google-analytics-integration) 79 | 80 | 81 | ## Contact 82 | 83 | [@easybase_io](https://twitter.com/easybase_io) – hello@easybase.io 84 | -------------------------------------------------------------------------------- /assets/carbon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/easybase/easybase-react/7d9276b7a991842b1239fcbb48db23e9ceeee0ee/assets/carbon.png -------------------------------------------------------------------------------- /assets/deploy-function-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/easybase/easybase-react/7d9276b7a991842b1239fcbb48db23e9ceeee0ee/assets/deploy-function-1.png -------------------------------------------------------------------------------- /assets/deploy-function-14.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/easybase/easybase-react/7d9276b7a991842b1239fcbb48db23e9ceeee0ee/assets/deploy-function-14.png -------------------------------------------------------------------------------- /assets/react-integration-3.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/easybase/easybase-react/7d9276b7a991842b1239fcbb48db23e9ceeee0ee/assets/react-integration-3.gif -------------------------------------------------------------------------------- /assets/token.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/easybase/easybase-react/7d9276b7a991842b1239fcbb48db23e9ceeee0ee/assets/token.png -------------------------------------------------------------------------------- /assets/users-2.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/easybase/easybase-react/7d9276b7a991842b1239fcbb48db23e9ceeee0ee/assets/users-2.gif -------------------------------------------------------------------------------- /example/README.md: -------------------------------------------------------------------------------- 1 | This example was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). 2 | 3 | It is linked to the easybase-react package in the parent directory for development purposes. 4 | 5 | You can run `npm install` and then `npm start` to test your package. 6 | -------------------------------------------------------------------------------- /example/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "easybase-react-example", 3 | "homepage": ".", 4 | "version": "0.0.0", 5 | "private": true, 6 | "scripts": { 7 | "start": "node ../node_modules/react-scripts/bin/react-scripts.js start", 8 | "build": "node ../node_modules/react-scripts/bin/react-scripts.js build" 9 | }, 10 | "dependencies": { 11 | "@types/react-router-dom": "^5.1.6", 12 | "easybase-react": "file:..", 13 | "react": "file:../node_modules/react", 14 | "react-dom": "file:../node_modules/react-dom", 15 | "react-router-dom": "^5.2.0", 16 | "react-scripts": "file:../node_modules/react-scripts", 17 | "semantic-ui-css": "^2.4.1", 18 | "semantic-ui-react": "^2.0.3", 19 | "typescript": "^4.2.4" 20 | }, 21 | "eslintConfig": { 22 | "extends": "react-app" 23 | }, 24 | "browserslist": { 25 | "production": [ 26 | ">0.2%", 27 | "not dead", 28 | "not op_mini all" 29 | ], 30 | "development": [ 31 | "last 1 chrome version", 32 | "last 1 firefox version", 33 | "last 1 safari version" 34 | ] 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /example/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/easybase/easybase-react/7d9276b7a991842b1239fcbb48db23e9ceeee0ee/example/public/favicon.ico -------------------------------------------------------------------------------- /example/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 10 | 11 | 12 | 16 | 17 | 18 | 27 | easybase-react 28 | 29 | 30 | 31 | 34 | 35 |
36 | 37 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /example/public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "easybase-react", 3 | "name": "easybase-react", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | } 10 | ], 11 | "start_url": ".", 12 | "display": "standalone", 13 | "theme_color": "#000000", 14 | "background_color": "#ffffff" 15 | } 16 | -------------------------------------------------------------------------------- /example/src/App.tsx: -------------------------------------------------------------------------------- 1 | /* eslint-disable @typescript-eslint/no-unused-vars */ 2 | import React from 'react' 3 | import ebconfig from "./ebconfig"; 4 | import ebconfig2 from "./ebconfig2"; 5 | import { EasybaseProvider, Auth, useEasybase } from 'easybase-react'; 6 | import QueryExample from "./QueryExample"; 7 | import DbExample from "./DbExample"; 8 | import "./styles.css"; 9 | import { 10 | HashRouter, 11 | Switch, 12 | Route, 13 | Link 14 | } from "react-router-dom"; 15 | import ProjectUser from "./ProjectUser"; 16 | import UseReturnExample from './UseReturnExample'; 17 | import UseReturnStressTest from './UseReturnStressTest'; 18 | import 'semantic-ui-css/semantic.min.css' 19 | 20 | const IntegrationExample = () => { 21 | React.useEffect(() => console.log("MOUNTING INTEGRATION EXAMPLE"), []); 22 | return ( 23 | 24 |

Visual Query

25 | 26 |
27 |

Db

28 | 29 |
30 |

Use Return

31 | 32 |
33 | ) 34 | } 35 | 36 | const AuthExample = () => { 37 | React.useEffect(() => console.log("MOUNTING AUTH EXAMPLE"), []); 38 | const { signOut } = useEasybase(); 39 | return ( 40 | 48 |

You're in!

49 | 50 |
51 | ) 52 | } 53 | 54 | 55 | const App = () => { 56 | return ( 57 | 58 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | ) 90 | } 91 | 92 | export default App; 93 | -------------------------------------------------------------------------------- /example/src/CardElement.tsx: -------------------------------------------------------------------------------- 1 | import React, { useRef } from "react"; 2 | import { useEasybase } from "easybase-react"; 3 | 4 | const CardElement = ({ rating, picture, app_name, hq, latest_release, index }: any) => { 5 | 6 | const inputEl = useRef(null); 7 | 8 | const { 9 | Frame, 10 | sync, 11 | updateRecordImage, 12 | updateRecordVideo 13 | } = useEasybase(); 14 | 15 | const onRatingChange = (change: number) => { 16 | Frame(index).rating += change; 17 | sync(); 18 | } 19 | 20 | const onDelete = () => { 21 | Frame().splice(index, 1); 22 | sync(); 23 | } 24 | 25 | const onImageClick = () => { 26 | if (inputEl && inputEl.current) { 27 | inputEl.current.onchange = () => { 28 | if (inputEl && inputEl.current && inputEl.current.files && inputEl.current.files.length > 0) { 29 | const imageFile = inputEl.current.files[0]; 30 | if (imageFile.type.includes("image")) { 31 | updateRecordImage({ columnName: "picture", record: Frame()[index], attachment: imageFile }); 32 | } else if (imageFile.type.includes("video")) { 33 | updateRecordVideo({ columnName: "picture", record: Frame()[index], attachment: imageFile }) 34 | } 35 | } 36 | 37 | }; 38 | 39 | inputEl.current.click(); 40 | } 41 | } 42 | 43 | return ( 44 |
45 |
46 | 47 | 48 |

{latest_release ? latest_release.slice(0, 10) : ""}

49 |
50 |
{app_name}
51 | {hq} 52 |
53 |
54 | 55 |

{rating}

56 | 57 |
58 |
59 | ) 60 | } 61 | 62 | export default CardElement; 63 | -------------------------------------------------------------------------------- /example/src/DbCardElement.tsx: -------------------------------------------------------------------------------- 1 | import React, { useRef } from "react"; 2 | import { useEasybase } from "easybase-react"; 3 | 4 | const CardElement = ({ rating, picture, app_name, hq, latest_release, _key, tableName }: any) => { 5 | 6 | const inputEl = useRef(null); 7 | 8 | const { db, setImage } = useEasybase(); 9 | 10 | const onRatingChange = (change: number) => { 11 | db(tableName || "").set({ 'rating': rating + change }).where({ _key }).all() 12 | } 13 | 14 | const onDelete = () => { 15 | db(tableName || "").delete().where({ _key }).one(); 16 | } 17 | 18 | const onImageClick = () => { 19 | if (inputEl && inputEl.current) { 20 | inputEl.current.onchange = () => { 21 | if (inputEl && inputEl.current && inputEl.current.files && inputEl.current.files.length > 0) { 22 | const imageFile = inputEl.current.files[0]; 23 | if (imageFile.type.includes("image")) { 24 | setImage(_key, "picture", imageFile); 25 | } 26 | } 27 | }; 28 | 29 | inputEl.current.click(); 30 | } 31 | } 32 | 33 | return ( 34 |
35 |
36 | 37 | 38 |

{latest_release ? latest_release.slice(0, 10) : ""}

39 |
40 |
{app_name}
41 | {hq} 42 |
43 |
44 | 45 |

{rating}

46 | 47 |
48 |
49 | ) 50 | } 51 | 52 | export default CardElement; 53 | -------------------------------------------------------------------------------- /example/src/DbExample.tsx: -------------------------------------------------------------------------------- 1 | import React, { useEffect, useState } from "react"; 2 | import { useEasybase } from 'easybase-react'; 3 | import DbCardElement from "./DbCardElement"; 4 | 5 | const DbExample = () => { 6 | 7 | const [tableLength, setTableLength] = useState(0); 8 | const [frameLength, setFrameLength] = useState(10); 9 | const [frameOffset, setFrameOffset] = useState(0); 10 | const [currentData, setCurrentData] = useState([]); 11 | 12 | const { 13 | db, 14 | fullTableSize, 15 | tableTypes 16 | } = useEasybase(); 17 | 18 | useEffect(() => { 19 | const mounted = async () => { 20 | setTableLength(await fullTableSize()); 21 | } 22 | mounted(); 23 | }, []); 24 | 25 | useEffect(() => { 26 | const runEffect = async () => { 27 | setCurrentData(await db().return().limit(frameLength).offset(frameOffset).all()); 28 | } 29 | runEffect(); 30 | }, [frameOffset, frameLength]) 31 | 32 | 33 | const onAddPage = async () => { 34 | await db().insert({ rating: 50, "app name": "Inserted App", _position: 0 }).all(); 35 | setCurrentData(await db().return().limit(frameLength).offset(frameOffset).all()); 36 | } 37 | 38 | const tableAndFrameStats = async () => { 39 | console.log((await tableTypes())); 40 | console.log((await fullTableSize())); 41 | } 42 | 43 | const changePage = async (change: number) => { 44 | setFrameOffset(prev => Math.abs(prev + change)); 45 | } 46 | 47 | const deleteSecondRecord = async () => { 48 | const firstRecord = currentData[1]; 49 | if (firstRecord) { 50 | console.log("Second record begin deleted: ", firstRecord); 51 | await db().delete(firstRecord as any).all(); 52 | setCurrentData(await db().return().limit(frameLength).offset(frameOffset).all()); 53 | } 54 | } 55 | 56 | const getFirstRecord = async () => { 57 | await db().return("app_name").where({ _position: 0 }).one(); 58 | await db().return("app_name").where({ _position: 0 }).all(); 59 | await db().return().where({ _position: 0 }).one(); 60 | await db().return().where({ _position: 0 }).all(); 61 | } 62 | 63 | return ( 64 |
65 |
66 |
67 | 68 |
69 | {Array.isArray(currentData) && currentData.map((ele, index) => )} 70 |
71 |
72 |
73 | 74 |

{frameOffset} - {frameOffset + Number(frameLength)} of {tableLength}

75 | 76 |
77 |
78 |

Edit db limit:

79 | setFrameLength(+e.target.value)} value={frameLength} /> 80 |
81 |
82 | 83 | 84 |
85 | 86 |
87 |
88 |
89 | ) 90 | } 91 | 92 | export default DbExample; 93 | -------------------------------------------------------------------------------- /example/src/ProjectUser.tsx: -------------------------------------------------------------------------------- 1 | import React, { useState, useEffect } from "react"; 2 | import { useEasybase } from "easybase-react"; 3 | import DbCardElement from "./DbCardElement"; 4 | import { Modal, Button, Form } from 'semantic-ui-react' 5 | 6 | export default function ProjectUser() { 7 | 8 | const [usernameValue, setUsernameValue] = useState(""); 9 | const [passwordValue, setPasswordValue] = useState(""); 10 | const [data, setData] = useState[]>([]); 11 | 12 | const [forgotDialogOpen, setForgotDialogOpen] = useState(false); 13 | const [forgotDialogStep, setForgotDialogStep] = useState(0); 14 | const [forgotUsernameVal, setForgotUsernameVal] = useState(""); 15 | const [forgotNewPassVal, setForgotNewPassVal] = useState(""); 16 | const [forgotCodeVal, setForgotCodeVal] = useState(""); 17 | 18 | const { 19 | isUserSignedIn, 20 | signIn, 21 | signUp, 22 | signOut, 23 | getUserAttributes, 24 | resetUserPassword, 25 | onSignIn, 26 | db, 27 | forgotPassword, 28 | forgotPasswordConfirm, 29 | userID 30 | } = useEasybase(); 31 | 32 | const onSignUpClick = async () => { 33 | const res = await signUp(usernameValue, passwordValue, { 34 | testKey: "testValue" 35 | }); 36 | console.log(res); 37 | } 38 | 39 | const onUserAttrsClick = async () => { 40 | const res = await getUserAttributes(); 41 | console.log(res); 42 | } 43 | 44 | useEffect(() => { 45 | console.log("Mobile Apps allowed when not signed in"); 46 | db('MOBILE APPS').return().limit(10).all().then((res: any[]) => { 47 | setData(res as Record[]); 48 | }); 49 | 50 | onSignIn(() => { 51 | console.log("Signed In!"); 52 | db('REACT TEST', true).return().limit(10).all().then((res: any[]) => { 53 | setData(res as Record[]); 54 | }); 55 | }); 56 | 57 | }, []); 58 | 59 | const addUserRecord = async () => { 60 | await db('REACT TEST', true).insert({ rating: 68, app_name: "this is only for this user" }).one(); 61 | const res = await db('REACT TEST', true).return().limit(10).all(); 62 | setData(res as Record[]); 63 | } 64 | 65 | const resetPassword = async () => { 66 | const current_pass = prompt("Enter your current password", ""); 67 | const new_pass = prompt("Enter new password", ""); 68 | if (!new_pass || !current_pass) return; 69 | console.log(await resetUserPassword(current_pass, new_pass)); 70 | signOut(); 71 | } 72 | 73 | const onForgotSubmit = async () => { 74 | switch (forgotDialogStep) { 75 | case 0: 76 | if (forgotUsernameVal) { 77 | await forgotPassword(forgotUsernameVal, { appName: "My React Test" }) 78 | setForgotDialogStep(1); 79 | } 80 | break; 81 | case 1: 82 | if (forgotCodeVal && forgotNewPassVal) { 83 | await forgotPasswordConfirm(forgotCodeVal, forgotUsernameVal, forgotNewPassVal) 84 | setForgotCodeVal("") 85 | setForgotNewPassVal("") 86 | setForgotUsernameVal("") 87 | setForgotDialogStep(0) 88 | setForgotDialogOpen(false) 89 | } 90 | break; 91 | default: 92 | break; 93 | } 94 | } 95 | 96 | const handleSignIn = async () => { 97 | const res = await signIn(usernameValue, passwordValue) 98 | console.log(res) 99 | } 100 | 101 | if (isUserSignedIn()) { 102 | return ( 103 |
104 |
105 |
User ID: {userID()}
106 | 107 | 108 | 109 | 110 |
111 |
112 | {data.map((ele, index) => )} 113 |
114 |
115 | ) 116 | } else { 117 | return ( 118 |
119 |
120 |

Username

121 | setUsernameValue(e.target.value)} /> 122 |

Password

123 | setPasswordValue(e.target.value)} /> 124 | 125 | 126 | setForgotDialogOpen(true)}>Forgot Password 127 |
128 |
129 | {data.map((ele, index) => )} 130 |
131 | setForgotDialogOpen(false)}> 132 | 133 |
134 | {forgotDialogStep === 0 && 135 | 136 | 137 | setForgotUsernameVal(e.target.value)} /> 138 | 139 | } 140 | {forgotDialogStep === 1 && 141 | <> 142 | 143 | 144 | setForgotCodeVal(e.target.value)} /> 145 | 146 | 147 | 148 | setForgotNewPassVal(e.target.value)} /> 149 | 150 | 151 | } 152 | 153 |
154 |
155 | 156 | 159 | 160 |
161 |
162 | ) 163 | } 164 | } -------------------------------------------------------------------------------- /example/src/QueryCardElement.tsx: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | 3 | const QueryCardElement = ({ rating, picture, app_name, hq, latest_release }: any) => { 4 | 5 | return ( 6 |
7 | 8 |

{latest_release ? latest_release.slice(0, 10) : ""}

9 |
10 |
{app_name}
11 | {hq} 12 |
13 |
14 |

{rating}

15 |
16 |
17 | ) 18 | } 19 | 20 | export default QueryCardElement; 21 | -------------------------------------------------------------------------------- /example/src/QueryExample.tsx: -------------------------------------------------------------------------------- 1 | import React, { useState } from "react"; 2 | import QueryCardElement from "./QueryCardElement"; 3 | import { useEasybase } from "easybase-react"; 4 | 5 | const QueryExample = () => { 6 | 7 | const [queryInputValue, setQueryInputValue] = useState(""); 8 | const [queryArray, setQueryArray] = useState[]>([]); 9 | const [limit, setLimit] = useState(10); 10 | const [offset, setOffset] = useState(0); 11 | const [sortBy, setSortBy] = useState(""); 12 | 13 | const { Query } = useEasybase(); 14 | 15 | const getQuery = async() => { 16 | const res = await Query({ 17 | queryName: queryInputValue, 18 | descending: false, 19 | sortBy, 20 | limit, 21 | offset 22 | }); 23 | console.log(res); 24 | setQueryArray(res); 25 | } 26 | 27 | return ( 28 |
29 |
30 |
31 |

Query:

32 | setQueryInputValue(e.target.value)} placeholder="Enter Query Name" /> 33 |
34 |
35 |

Limit:

36 | setLimit(+e.target.value)} placeholder="Limit" /> 37 |
38 |
39 |

Offset:

40 | setOffset(+e.target.value)} placeholder="Offset" /> 41 |
42 |
43 |

Sort By:

44 | setSortBy(e.target.value)} placeholder="Sort By Column" /> 45 |
46 | 47 |
48 |
49 | {queryArray.map((ele, index) => )} 50 |
51 |
52 | ) 53 | } 54 | 55 | export default QueryExample; -------------------------------------------------------------------------------- /example/src/UseReturnExample.tsx: -------------------------------------------------------------------------------- 1 | import React, { useEffect, useState } from "react"; 2 | import { useEasybase } from 'easybase-react'; 3 | import CardElement from "./DbCardElement"; 4 | 5 | interface IE { 6 | time: Date; 7 | success: boolean; 8 | } 9 | 10 | const UseReturnExample = () => { 11 | 12 | const [tableLength, setTableLength] = useState(0); 13 | const [frameLength, setFrameLength] = useState(10); 14 | const [frameOffset, setFrameOffset] = useState(0); 15 | const [ratingState, setRatingState] = useState(50); 16 | 17 | const { 18 | db, 19 | useReturn, 20 | fullTableSize, 21 | e 22 | } = useEasybase(); 23 | 24 | const { frame, manualFetch, unsubscribe, loading } = useReturn(() => db().return().where(e.lt('rating', ratingState)).limit(frameLength).offset(frameOffset), [ frameLength, frameOffset, ratingState ]); 25 | 26 | useEffect(() => { 27 | async function mounted() { 28 | setTableLength(await fullTableSize()) 29 | } 30 | mounted(); 31 | }, []) 32 | 33 | 34 | const onAddPage = async () => { 35 | await db().insert({ rating: 68, "app name": "Inserted App", _position: 0 }).all(); 36 | } 37 | 38 | const changePage = async (change: number) => { 39 | setFrameOffset(prev => Math.abs(prev + change)); 40 | } 41 | 42 | const getFirstRecord = async () => { 43 | console.log(await db().return("app_name").where({ _position: 0 }).one()); 44 | console.log(await db().return("app_name").where({ _position: 0 }).all()); 45 | console.log(await db().return().where({ _position: 0 }).one()); 46 | console.log(await db().return().where({ _position: 0 }).all()); 47 | } 48 | 49 | return ( 50 |
51 |
52 |
53 | 54 |
55 | {loading ?
: frame.map((ele: any, index: any) => )} 56 |
57 |
58 |
59 | 60 |

{frameOffset} - {frameOffset + Number(frameLength)} of {tableLength}

61 | 62 |
63 |
64 |

Edit db limit:

65 | setFrameLength(+e.target.value)} value={frameLength} /> 66 |
67 |

Edit Rating filter:

68 | setRatingState(+e.target.value)} value={ratingState} /> 69 |
70 |
71 | 72 |
73 | 74 | 75 |
76 |
77 |
78 | ) 79 | } 80 | 81 | export default UseReturnExample; 82 | -------------------------------------------------------------------------------- /example/src/UseReturnStressTest.tsx: -------------------------------------------------------------------------------- 1 | import React, { useState } from "react"; 2 | import { useEasybase } from 'easybase-react'; 3 | import CardElement from "./DbCardElement"; 4 | 5 | const ChildUseReturn = () => { 6 | const [ratingState, setRatingState] = useState(50); 7 | 8 | const { 9 | db, 10 | useReturn, 11 | e 12 | } = useEasybase(); 13 | 14 | const { frame, loading } = useReturn(() => db() 15 | .return() 16 | .where(e.lt('rating', ratingState)) 17 | .limit(10), 18 | [ratingState]); 19 | 20 | return ( 21 |
22 |
23 | {loading ?
: frame.map((ele: any, index: any) => )} 24 |
25 |
26 |
27 |

Edit Rating filter:

28 | setRatingState(+e.target.value)} value={ratingState} /> 29 |
30 |
31 |
32 | ) 33 | } 34 | 35 | const UseReturnStressTest = () => { 36 | const [showChild, setShowChild] = useState(true); 37 | 38 | const { 39 | db, 40 | } = useEasybase(); 41 | 42 | const onAddPage = async () => { 43 | await db().insert({ rating: 68, "app name": "Inserted App", _position: 0 }).all(); 44 | } 45 | 46 | return ( 47 |
48 |
49 | 50 | 54 | 55 | { showChild && } 56 |
57 |
58 | ) 59 | } 60 | 61 | export default UseReturnStressTest; 62 | -------------------------------------------------------------------------------- /example/src/index.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | import App from './App'; 4 | 5 | ReactDOM.render(, document.getElementById('root')); 6 | -------------------------------------------------------------------------------- /example/src/react-app-env.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | -------------------------------------------------------------------------------- /example/src/styles.css: -------------------------------------------------------------------------------- 1 | .d-flex { 2 | display: flex; 3 | } 4 | 5 | .align-items-center { 6 | align-items: center; 7 | } 8 | 9 | .m-4 { 10 | margin: 10px !important; 11 | } 12 | 13 | .p-4 { 14 | padding: 10px !important; 15 | } 16 | 17 | .mp-0 { 18 | margin: 0px !important; 19 | padding: 0px !important; 20 | } 21 | 22 | .card-root { 23 | width: 200px; 24 | height: 390px; 25 | display: block; 26 | border-radius: 5px; 27 | box-shadow: 0 14px 28px rgba(0, 0, 0, 0.25), 0 10px 10px rgba(0, 0, 0, 0.22); 28 | margin: 30px; 29 | transition: all 0.3s cubic-bezier(.25, .8, .25, 1); 30 | position: relative; 31 | } 32 | 33 | .card-root:hover { 34 | box-shadow: 0 3px 6px rgba(0, 0, 0, 0.16), 0 3px 6px rgba(0, 0, 0, 0.23); 35 | } 36 | 37 | .card-image { 38 | width: 200px; 39 | height: 200px; 40 | border-top-left-radius: 5px; 41 | border-top-right-radius: 5px; 42 | object-fit: cover; 43 | } 44 | 45 | .button-row { 46 | display: flex; 47 | width: 99vw; 48 | justify-content: space-around; 49 | } 50 | 51 | .btn { 52 | position: relative; 53 | display: block; 54 | margin: 30px auto; 55 | padding: 0; 56 | overflow: hidden; 57 | border-width: 0; 58 | outline: none; 59 | border-radius: 2px; 60 | box-shadow: 0 1px 4px rgba(0, 0, 0, .6); 61 | background-color: #2ecc71; 62 | color: #ecf0f1; 63 | transition: background-color .3s; 64 | } 65 | 66 | .btn:hover, .btn:focus { 67 | background-color: #27ae60; 68 | } 69 | 70 | .btn>* { 71 | position: relative; 72 | } 73 | 74 | .btn span { 75 | display: block; 76 | padding: 12px 24px; 77 | pointer-events: auto; 78 | cursor: pointer; 79 | } 80 | 81 | .btn:active:before { 82 | width: 120%; 83 | padding-top: 120%; 84 | transition: width .2s ease-out, padding-top .2s ease-out; 85 | } 86 | 87 | .btn.orange { 88 | background-color: #e67e22; 89 | } 90 | 91 | .btn.orange:hover, .btn.orange:focus { 92 | background-color: #d35400; 93 | } 94 | 95 | .btn.green { 96 | background-color: #66bd0e; 97 | } 98 | 99 | .btn.green:hover, .btn.green:focus { 100 | background-color: #08c908; 101 | } 102 | 103 | .card-delete-button::before { 104 | position: absolute; 105 | width: 10px; 106 | top: 2px; 107 | left: 28%; 108 | content: "X"; 109 | font-size: 13px; 110 | color: white; 111 | } 112 | 113 | .card-delete-button { 114 | border-radius: 50%; 115 | position: absolute; 116 | top: -7px; 117 | right: -7px; 118 | width: 20px; 119 | height: 20px; 120 | background-color: red; 121 | z-index: 10; 122 | box-shadow: 0 1px 4px rgba(0, 0, 0, .6); 123 | cursor: pointer; 124 | } 125 | 126 | .spacer { 127 | height: 60px; 128 | width: 0.125rem; 129 | border-radius: 3px; 130 | background-color: #a7a7a7; 131 | } 132 | 133 | .loader { 134 | border: 16px solid #f3f3f3; 135 | border-radius: 50%; 136 | border-top: 16px solid #3498db; 137 | width: 120px; 138 | height: 120px; 139 | -webkit-animation: spin 2s linear infinite; 140 | /* Safari */ 141 | animation: spin 2s linear infinite; 142 | } 143 | 144 | /* Safari */ 145 | 146 | @-webkit-keyframes spin { 147 | 0% { 148 | -webkit-transform: rotate(0deg); 149 | } 150 | 100% { 151 | -webkit-transform: rotate(360deg); 152 | } 153 | } 154 | 155 | @keyframes spin { 156 | 0% { 157 | transform: rotate(0deg); 158 | } 159 | 100% { 160 | transform: rotate(360deg); 161 | } 162 | } -------------------------------------------------------------------------------- /example/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "outDir": "dist", 4 | "module": "esnext", 5 | "lib": [ 6 | "dom", 7 | "esnext" 8 | ], 9 | "moduleResolution": "node", 10 | "jsx": "react-jsx", 11 | "sourceMap": true, 12 | "declaration": true, 13 | "esModuleInterop": true, 14 | "noImplicitReturns": true, 15 | "noImplicitThis": true, 16 | "noImplicitAny": true, 17 | "strictNullChecks": true, 18 | "suppressImplicitAnyIndexErrors": true, 19 | "noUnusedLocals": false, 20 | "noUnusedParameters": true, 21 | "allowSyntheticDefaultImports": true, 22 | "target": "es5", 23 | "allowJs": true, 24 | "skipLibCheck": true, 25 | "strict": true, 26 | "forceConsistentCasingInFileNames": true, 27 | "resolveJsonModule": true, 28 | "isolatedModules": true, 29 | "noEmit": true, 30 | "noFallthroughCasesInSwitch": true 31 | }, 32 | "include": [ 33 | "src" 34 | ], 35 | "exclude": [ 36 | "node_modules", 37 | "build" 38 | ] 39 | } 40 | -------------------------------------------------------------------------------- /native-example/.buckconfig: -------------------------------------------------------------------------------- 1 | 2 | [android] 3 | target = Google Inc.:Google APIs:23 4 | 5 | [maven_repositories] 6 | central = https://repo1.maven.org/maven2 7 | -------------------------------------------------------------------------------- /native-example/.gitattributes: -------------------------------------------------------------------------------- 1 | *.pbxproj -text 2 | -------------------------------------------------------------------------------- /native-example/.gitignore: -------------------------------------------------------------------------------- 1 | # OSX 2 | # 3 | .DS_Store 4 | 5 | # Xcode 6 | # 7 | build/ 8 | *.pbxuser 9 | !default.pbxuser 10 | *.mode1v3 11 | !default.mode1v3 12 | *.mode2v3 13 | !default.mode2v3 14 | *.perspectivev3 15 | !default.perspectivev3 16 | xcuserdata 17 | *.xccheckout 18 | *.moved-aside 19 | DerivedData 20 | *.hmap 21 | *.ipa 22 | *.xcuserstate 23 | project.xcworkspace 24 | 25 | # Android/IntelliJ 26 | # 27 | build/ 28 | .idea 29 | .gradle 30 | local.properties 31 | *.iml 32 | *.hprof 33 | 34 | # node.js 35 | # 36 | node_modules/ 37 | npm-debug.log 38 | yarn-error.log 39 | 40 | # BUCK 41 | buck-out/ 42 | \.buckd/ 43 | *.keystore 44 | !debug.keystore 45 | 46 | # Bundle artifacts 47 | *.jsbundle 48 | 49 | # CocoaPods 50 | /ios/Pods/ 51 | 52 | # Expo 53 | .expo/ 54 | web-build/ 55 | -------------------------------------------------------------------------------- /native-example/App.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable no-undef */ 2 | /* eslint-disable operator-linebreak */ 3 | import React from 'react'; 4 | import { StyleSheet, Text, View, Button } from 'react-native'; 5 | import { useEasybase, EasybaseProvider } from 'easybase-react'; 6 | import { NativeAuth } from 'easybase-react/native'; 7 | import ebconfig from './ebconfig'; 8 | 9 | const SignOutButton = () =>