Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revamp #99

Draft
wants to merge 22 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
d3a33b0
fix: enable use workspaces in lerna.json
HassanBahati Aug 7, 2024
6e088ce
chore: upgrade packages
HassanBahati Aug 7, 2024
745e403
chore: remove deprecated useWorkspaces option
HassanBahati Aug 7, 2024
910d0eb
fix: rename rollup.config.js => rollup.config.mjs
HassanBahati Aug 7, 2024
821bc5a
chore: add @tanstack/react-query
HassanBahati Aug 7, 2024
aa0f95c
refactor(auth): upgrade useUserAuth
HassanBahati Aug 8, 2024
bff31ad
style(examples): remove unused styles
HassanBahati Aug 8, 2024
5b912eb
docs(examples): add run command for example auth usage
HassanBahati Aug 8, 2024
7f91ab4
chore(examples): ignore lock files
HassanBahati Aug 8, 2024
69bc5bc
chore(examples): ignore lock files
HassanBahati Aug 8, 2024
2f60045
docs(examples): add getting started and example environmental variables
HassanBahati Aug 8, 2024
ec253b3
chore: format
HassanBahati Aug 8, 2024
575d372
refactor(auth): refactor useAuthIdToken to use @tansack/react-query
HassanBahati Aug 8, 2024
0bc03a9
fix: query key type
HassanBahati Aug 12, 2024
135edc4
refactor(tests): remove deprecated setLogger
HassanBahati Aug 12, 2024
3fb7305
reactor(tests): useAuthUser test suit
HassanBahati Aug 12, 2024
f711efa
refactor(tests): set verbose to false
HassanBahati Aug 12, 2024
707dab4
refactor(auth): upgrade useAuthFetchSignInMethodsForEmail to @tanstac…
HassanBahati Aug 13, 2024
54ade51
refactor(auth): upgrade useAuthGetRedirectResult to @tanstack/react-q…
HassanBahati Aug 13, 2024
979f984
refactor(auth): add a mutationFn for all hooks utilising useMutation
HassanBahati Aug 13, 2024
a321048
refactor(database): add mutationFn for hooks utilising useMutation
HassanBahati Aug 13, 2024
ef3761d
ci: upgrade from node 16 to 20
HassanBahati Aug 13, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/testing.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: Setup node
uses: actions/setup-node@v1
with:
node-version: 16
node-version: 20
- name: Yarn install
run: yarn
- name: ESLint
Expand All @@ -31,7 +31,7 @@ jobs:
- name: Setup node
uses: actions/setup-node@v1
with:
node-version: 16
node-version: 20
- name: Yarn install
run: yarn
- name: Yarn install (functions)
Expand Down
4 changes: 2 additions & 2 deletions docs/database/querying.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function ProductsList() {
// Iterate the values in order and add an element to the array
snapshot.forEach((childSnapshot) => {
children.push(
<div key={childSnapshot.key}>Product: {childSnapshot.val().name}</div>
<div key={childSnapshot.key}>Product: {childSnapshot.val().name}</div>,
);
});

Expand Down Expand Up @@ -210,7 +210,7 @@ const products = useDatabaseSnapshot(
onError(error) {
toast.error("Woops, something went wrong!");
},
}
},
);

if (query.isError) {
Expand Down
2 changes: 1 addition & 1 deletion docs/firestore/data-mutation.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,6 @@ mutation.mutate(
onMutate() {
toast.info("Adding document...");
},
}
},
);
```
12 changes: 6 additions & 6 deletions docs/firestore/querying-collections.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import { firestore } from "./firebase";
const ref = query(
collection(firestore, "products"),
limit(10),
where("state", "==", "active")
where("state", "==", "active"),
);
```

Expand Down Expand Up @@ -226,7 +226,7 @@ function Products() {
const query = useFirestoreQuery(
["products"],
firestore,
namedQuery(firestore, "products")
namedQuery(firestore, "products"),
);
}
```
Expand Down Expand Up @@ -303,7 +303,7 @@ const query = useFirestoreQuery(
select(snapshot) {
return snapshot.docs.map((docSnapshot) => docSnapshot.id);
},
}
},
);

const data = query.data; // ['id1', 'id2', ...]
Expand All @@ -317,7 +317,7 @@ const findActiveSubscription = query(
collection(firestore, "subscriptions"),
where("uid", "==", "123"),
where("status", "==", "active"),
limit(1)
limit(1),
);

// Override the return type generic:
Expand All @@ -335,7 +335,7 @@ const query = useFirestoreQuery(

return snapshot.docs[0];
},
}
},
);

// Data will contain a single document or null.
Expand Down Expand Up @@ -390,7 +390,7 @@ const query = useFirestoreQuery(
onError(error) {
toast.error("Woops, something went wrong!");
},
}
},
);

if (query.isError) {
Expand Down
4 changes: 2 additions & 2 deletions docs/firestore/querying-documents.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ const query = useFirestoreDocument(
select(snapshot) {
return snapshot.exists() ? snapshot.data().name : null;
},
}
},
);

const data = query.data; // string | null
Expand Down Expand Up @@ -214,7 +214,7 @@ const query = useFirestoreDocument(
onError(error) {
toast.error("Woops, something went wrong!");
},
}
},
);

if (query.isError) {
Expand Down
2 changes: 1 addition & 1 deletion docs/functions/calling.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,6 @@ const mutation = useFunctionsCall(
onMutate(variables) {
console.log("Updating product with variables", variables);
},
}
},
);
```
4 changes: 2 additions & 2 deletions docs/functions/querying.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const query = useFunctionsQuery(
},
{
timeout: 10000,
}
},
);
```

Expand All @@ -76,6 +76,6 @@ const query = useFunctionsQuery(
onError(error) {
console.error("Error fetching the product!", error);
},
}
},
);
```
6 changes: 3 additions & 3 deletions docs/functions/typescript.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const query = useFunctionsQuery<RequestData, ResponseData>(
// RequestData
{
id,
}
},
);

if (query.isSuccess) {
Expand Down Expand Up @@ -68,7 +68,7 @@ const query = useFunctionsQuery<RequestData, ResponseData, string>(
select(response: ResponseData): string {
return response.data.name;
},
}
},
);

if (query.isSuccess) {
Expand All @@ -95,7 +95,7 @@ type ResponseData = {

const mutation = useFunctionsCall<RequestData, ResponseData>(
functions,
"updateProduct"
"updateProduct",
);

// mutate call is now typed to RequestData
Expand Down
1 change: 0 additions & 1 deletion examples/auth-basic/.env

This file was deleted.

6 changes: 6 additions & 0 deletions examples/auth-basic/.env.local.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
VITE_FIREBASE_API_KEY="YOUR_FIREBASE_API_KEY"
VITE_FIREBASE_AUTH_DOMAIN="YOUR_FIREBASE_AUTH_DOMAIN"
VITE_FIREBASE_PROJECT_ID="YOUR_FIREBASE_PROJECT_ID"
VITE_FIREBASE_STORAGE_BUCKET="YOUR_FIREBASE_STORAGE_BUCKET"
VITE_FIREBASE_MESSAGING_SENDER_ID="YOUR_FIREBASE_MESSAGING_SENDER_ID"
VITE_FIREBASE_APP_ID="YOUR_FIREBASE_APP_ID"
29 changes: 29 additions & 0 deletions examples/auth-basic/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
.env
yarn.lock
package-lock.json
pnpm-lock.yaml
.env.local
32 changes: 29 additions & 3 deletions examples/auth-basic/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,32 @@
# Example
# React Query Firebase Example

To run this example:
This is an example usage of the `react-query-firebase` library.

_See also: [the React Query Firebase documentation](https://react-query-firebase.invertase.dev/)_


## Getting Started
Below is a guide on how to get started with running this example;

### 1. Add environment variables

- Create a `.env` or `.env.local` file.
- Add your Firebase environment variables to the you created.

The environment variables to add include;

```bash
VITE_FIREBASE_API_KEY="YOUR_FIREBASE_API_KEY"
VITE_FIREBASE_AUTH_DOMAIN="YOUR_FIREBASE_AUTH_DOMAIN"
VITE_FIREBASE_PROJECT_ID="YOUR_FIREBASE_PROJECT_ID"
VITE_FIREBASE_STORAGE_BUCKET="YOUR_FIREBASE_STORAGE_BUCKET"
VITE_FIREBASE_MESSAGING_SENDER_ID="YOUR_FIREBASE_MESSAGING_SENDER_ID"
VITE_FIREBASE_APP_ID="YOUR_FIREBASE_APP_ID"
```

## 2. Running the app

Execute the commands below;

- `npm install` or `yarn`
- `npm run start` or `yarn start`
- `npm run dev` or `yarn dev`
26 changes: 26 additions & 0 deletions examples/auth-basic/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import js from '@eslint/js'
import globals from 'globals'
import reactHooks from 'eslint-plugin-react-hooks'
import reactRefresh from 'eslint-plugin-react-refresh'
import tseslint from 'typescript-eslint'

export default tseslint.config({
extends: [js.configs.recommended, ...tseslint.configs.recommended],
files: ['**/*.{ts,tsx}'],
ignores: ['dist'],
languageOptions: {
ecmaVersion: 2020,
globals: globals.browser,
},
plugins: {
'react-hooks': reactHooks,
'react-refresh': reactRefresh,
},
rules: {
...reactHooks.configs.recommended.rules,
'react-refresh/only-export-components': [
'warn',
{ allowConstantExport: true },
],
},
})
13 changes: 13 additions & 0 deletions examples/auth-basic/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + React + TS</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
51 changes: 25 additions & 26 deletions examples/auth-basic/package.json
Original file line number Diff line number Diff line change
@@ -1,33 +1,32 @@
{
"name": "auth-basic",
"private": true,
"version": "1.0.0",
"description": "",
"keywords": [],
"main": "src/index.tsx",
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "tsc -b && vite build",
"lint": "eslint .",
"preview": "vite preview"
},
"dependencies": {
"@react-query-firebase/auth": "*",
"firebase": "^9.1.1",
"react": "17.0.2",
"react-dom": "17.0.2",
"react-query": "^3.23.2",
"react-scripts": "5.0.0"
"@tanstack/react-query": "^5.51.21",
"@tanstack/react-query-devtools": "^5.51.21",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"@react-query-firebase/auth": "*"
},
"devDependencies": {
"@types/react": "17.0.0",
"@types/react-dom": "17.0.0",
"typescript": "4.1.3"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
},
"browserslist": [
">0.2%",
"not dead",
"not ie <= 11",
"not op_mini all"
]
"@eslint/js": "^9.8.0",
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
"@vitejs/plugin-react": "^4.3.1",
"eslint": "^9.8.0",
"eslint-plugin-react-hooks": "^5.1.0-rc.0",
"eslint-plugin-react-refresh": "^0.4.9",
"globals": "^15.9.0",
"typescript": "^5.5.3",
"typescript-eslint": "^8.0.0",
"vite": "^5.4.0"
}
}
42 changes: 0 additions & 42 deletions examples/auth-basic/public/index.html

This file was deleted.

1 change: 1 addition & 0 deletions examples/auth-basic/public/vite.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading