Skip to content

Commit 385fd30

Browse files
committed
Merge branch 'develop'
2 parents 51d4589 + ad670fc commit 385fd30

2 files changed

Lines changed: 47 additions & 0 deletions

File tree

src/hooks/useAddress.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import { useQuery } from '@tanstack/react-query'
2+
import { savePhotonTime } from 'src/serverFunctions/photon'
23
import { Address } from 'types/address'
34

45
const layers = ['city', 'street', 'house']
56

67
export const searchAddress = async (search: string, limit?: number) => {
78
const axios = (await import('axios')).default
89

10+
const start = new Date().getTime()
911
return axios
1012
.get<{
1113
features?: Address[]
@@ -15,6 +17,9 @@ export const searchAddress = async (search: string, limit?: number) => {
1517
.join('&')}&lang=fr&lat=46.227638&lon=2.213749&zoom=7&location_bias_scale=0.9`
1618
)
1719
.then((res) => {
20+
const end = new Date().getTime()
21+
savePhotonTime({ search, time: end - start })
22+
1823
return res.data && res.data.features
1924
? res.data.features.sort((a, b) => {
2025
if (a.properties.country === 'France' && b.properties.country !== 'France') {

src/serverFunctions/photon.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
'use server'
2+
3+
import axios from 'axios'
4+
5+
export const savePhotonTime = async ({ search, time }: { search: string; time: number }) => {
6+
const dbId = process.env.NOTION_API_DB_PHOTON
7+
if (!dbId) {
8+
return false
9+
}
10+
11+
try {
12+
await axios.post(
13+
'https://api.notion.com/v1/pages',
14+
{
15+
parent: {
16+
type: 'database_id',
17+
database_id: dbId,
18+
},
19+
properties: {
20+
Search: {
21+
type: 'title',
22+
title: [{ type: 'text', text: { content: search } }],
23+
},
24+
Time: {
25+
type: 'number',
26+
number: time,
27+
},
28+
},
29+
},
30+
{
31+
headers: {
32+
Authorization: `Bearer ${process.env.NOTION_API_KEY}`,
33+
'Notion-Version': '2022-06-28',
34+
},
35+
}
36+
)
37+
return true
38+
} catch (error) {
39+
console.error(error.response)
40+
return false
41+
}
42+
}

0 commit comments

Comments
 (0)