Skip to content

Commit f74c8ab

Browse files
committed
サンプルをblogsに
1 parent ea7ad38 commit f74c8ab

File tree

1 file changed

+16
-23
lines changed

1 file changed

+16
-23
lines changed

src/App.js

+16-23
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,18 @@ import firebase from "./firebase";
33

44
export default () => {
55
const [sampleData, setSampleData] = useState("{}");
6-
const [inputContains, setInputContains] = useState("A");
7-
const [inputContainsAny, setInputContainsAny] = useState("A,B");
8-
const [inputWhereIn, setInputWhereIn] = useState("andC,andB");
6+
const [inputContains, setInputContains] = useState("game");
7+
const [inputContainsAny, setInputContainsAny] = useState("game,tech");
8+
const [inputWhereIn, setInputWhereIn] = useState("tweet,podcast");
99
const [resultContains, setResultContains] = useState("");
1010
const [resultContainsAny, setResultContainsAny] = useState("");
1111
const [resultWhereIn, setResultWhereIn] = useState("");
12+
const collectionRef = firebase.firestore().collection("blogs");
1213

1314
const onArrayContain = async () => {
1415
setResultContains("Loading...");
15-
const hitData = await firebase
16-
.firestore()
17-
.collection("test")
18-
.where("array", "array-contains", inputContains)
16+
const hitData = await collectionRef
17+
.where("tags", "array-contains", inputContains)
1918
.get()
2019
.then(res => res.docs.map(doc => doc.id));
2120
console.log(hitData);
@@ -26,10 +25,8 @@ export default () => {
2625
setResultContainsAny("Loading...");
2726
const where = inputContainsAny.split(",");
2827
console.log("array-contains-any", where);
29-
const hitData = await firebase
30-
.firestore()
31-
.collection("test")
32-
.where("array", "array-contains-any", where)
28+
const hitData = await collectionRef
29+
.where("tags", "array-contains-any", where)
3330
.get()
3431
.then(res => res.docs.map(doc => doc.id));
3532
console.log(hitData);
@@ -40,10 +37,8 @@ export default () => {
4037
setResultWhereIn("Loading...");
4138
const where = inputWhereIn.split(",");
4239
console.log("in", where);
43-
const hitData = await firebase
44-
.firestore()
45-
.collection("test")
46-
.where("name", "in", where)
40+
const hitData = await collectionRef
41+
.where("type", "in", where)
4742
.get()
4843
.then(res => res.docs.map(doc => doc.id));
4944
console.log(hitData);
@@ -52,17 +47,15 @@ export default () => {
5247

5348
const fetchSampleData = async () => {
5449
const tmpSampleData = {};
55-
await firebase
56-
.firestore()
57-
.collection("test")
50+
await collectionRef
5851
.get()
5952
.then(res => res.docs.map(doc => (tmpSampleData[doc.id] = doc.data())));
6053
setSampleData(JSON.stringify(tmpSampleData, null, 2));
6154
};
6255

6356
useEffect(() => {
6457
fetchSampleData();
65-
}, []);
58+
});
6659

6760
return (
6861
<div className="section is-space py-6">
@@ -83,8 +76,8 @@ export default () => {
8376
<h1 className="heading is-xl is-strong mb-3">Queries</h1>
8477
<div className="mb-6">
8578
<h1 className="heading is-md is-strong mb-3">Array Contains</h1>
86-
<p class="">
87-
firebase.firestore().collection("test").where("array",
79+
<p>
80+
firebase.firestore().collection("blogs").where("tags",
8881
"array-contains", "{inputContains}")
8982
</p>
9083
<input
@@ -113,7 +106,7 @@ export default () => {
113106
<div className="mb-6">
114107
<h1 className="heading is-md is-strong mb-3">Array Contain Any</h1>
115108
<p>
116-
firebase.firestore().collection("test").where("array",
109+
firebase.firestore().collection("blogs").where("tags",
117110
"array-contains-any", [
118111
{inputContainsAny
119112
.split(",")
@@ -146,7 +139,7 @@ export default () => {
146139
<div className="mb-6">
147140
<h1 className="heading is-md is-strong mb-3">WhereIn</h1>
148141
<p>
149-
firebase.firestore().collection("test").where("name", "in", [
142+
firebase.firestore().collection("blogs").where("type", "in", [
150143
{inputWhereIn
151144
.split(",")
152145
.map(t => `"${t}"`)

0 commit comments

Comments
 (0)