Skip to content

Commit 4b47ccc

Browse files
author
Alan Shaw
committed
Merge branch 'main' of github.com:ipfs-shipyard/nft.storage
2 parents 79889fb + 6733512 commit 4b47ccc

18 files changed

Lines changed: 366 additions & 23 deletions

File tree

packages/api/src/utils/auth-v1.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,15 @@ export async function loginOrRegister(event, data) {
9393
github: parsed.github,
9494
})
9595

96-
if (upsert.data === null) {
97-
throw new Error('Could not retrieve user from db.')
98-
}
99-
10096
if (upsert.error) {
10197
// @ts-ignore
10298
throw new Error(`DB error: ${JSON.stringify(upsert.error)}`)
10399
}
100+
101+
if (upsert.data === null) {
102+
throw new Error('Could not retrieve user from db.')
103+
}
104+
104105
const user = upsert.data[0]
105106

106107
return { user, tokenName: 'session' }

packages/api/wrangler.toml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,3 +165,31 @@ CLUSTER_API_URL = "https://nft.storage.ipfscluster.io/api/"
165165
CLUSTER_IPFS_PROXY_API_URL = ""
166166
CLUSTER_ADDRS = ""
167167
DATABASE_URL = "http://localhost:8000"
168+
169+
[env.ze]
170+
type = "webpack"
171+
name = "nft-storage-ze"
172+
account_id = "9357c50891f315d3c8a84e87ee47f740"
173+
workers_dev = true
174+
usage_model = ""
175+
route = ""
176+
zone_id = ""
177+
kv_namespaces = [
178+
{ binding = "USERS", preview_id = "ae5de1d8a7b24a7380bcf152d0a34405", id = "ae5de1d8a7b24a7380bcf152d0a34405" },
179+
{ binding = "NFTS", preview_id = "e151334b3ca14ba381a5eec9c0143e94", id = "e151334b3ca14ba381a5eec9c0143e94" },
180+
{ binding = "NFTS_IDX", preview_id = "8eb6bf97cfa243ab9bebe5dcb61233dc", id = "8eb6bf97cfa243ab9bebe5dcb61233dc" },
181+
{ binding = "DEALS", preview_id = "653d8a2c419843f18b9092fb2cc090dd", id = "653d8a2c419843f18b9092fb2cc090dd" },
182+
{ binding = "METRICS", preview_id = "dae53a615e7741d2a5d89a601e5b4c8d", id = "dae53a615e7741d2a5d89a601e5b4c8d" },
183+
{ binding = "PINS", preview_id = "a2fe6ea3f15d42deb208d482be50cc01", id = "a2fe6ea3f15d42deb208d482be50cc01" },
184+
{ binding = "FOLLOWUPS", preview_id = "6b8fd71bbbd241428585a91fb540519d", id = "6b8fd71bbbd241428585a91fb540519d" },
185+
{ binding = "PINATA_QUEUE", preview_id = "fba21c792337417e85296320a0ae58e4", id = "fba21c792337417e85296320a0ae58e4" }
186+
]
187+
188+
189+
[env.ze.vars]
190+
ENV = "dev"
191+
DEBUG = "*"
192+
CLUSTER_API_URL = "https://ze-cluster-api-nft-storage.loca.lt"
193+
CLUSTER_IPFS_PROXY_API_URL = "https://ze-ipfs-proxy-api-nft-storage.loca.lt"
194+
CLUSTER_ADDRS = ""
195+
DATABASE_URL = "http://localhost:8000"

packages/website/components/button.js

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
1-
import React from 'react'
1+
import React, { useCallback } from 'react'
22
import Link from 'next/link'
33
import clsx from 'clsx'
44

5+
import countly from '../lib/countly'
6+
57
/**
8+
* @typedef {Object} TrackingProp
9+
* @prop {string} ui UI section id. One of countly.ui.
10+
* @prop {string} [action] Action id. used to uniquely identify an action within a ui section.
11+
* @prop {string} [event] Custom event name to be used instead of the default CTA_LINK_CLICK.
12+
* @prop {Object} [data] Extra data to send to countly.
13+
*
614
* @typedef {Object} ButtonProps
715
* @prop {string} [id]
816
* @prop {string} [wrapperClassName]
@@ -13,6 +21,8 @@ import clsx from 'clsx'
1321
* @prop {React.ReactChildren | string | React.ReactElement} children
1422
* @prop {boolean} [disabled]
1523
* @prop {boolean} [small]
24+
* @prop {string} [id]
25+
* @prop {TrackingProp} [tracking] Tracking data to send to countly on button click
1626
*/
1727

1828
/**
@@ -30,7 +40,25 @@ export default function Button({
3040
children,
3141
disabled = false,
3242
small = false,
43+
tracking,
3344
}) {
45+
const onClickHandler = useCallback(
46+
(event) => {
47+
tracking &&
48+
countly.trackEvent(tracking.event || countly.events.CTA_LINK_CLICK, {
49+
ui: tracking.ui,
50+
action: tracking.action,
51+
link:
52+
typeof href === 'string'
53+
? href
54+
: (href?.pathname || '') + (href?.hash || ''),
55+
...(tracking.data || {}),
56+
})
57+
onClick && onClick(event)
58+
},
59+
[tracking, onClick, href]
60+
)
61+
3462
wrapperClassName = clsx(
3563
'dib',
3664
'bg-nsgray',
@@ -59,7 +87,7 @@ export default function Button({
5987
className
6088
)}
6189
style={btnStyle}
62-
onClick={onClick}
90+
onClick={onClickHandler}
6391
disabled={disabled}
6492
id={id}
6593
>

packages/website/components/footer.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
1+
import { useCallback } from 'react'
12
import Link from 'next/link'
3+
4+
import countly from '../lib/countly'
5+
26
export default function Footer() {
7+
const onLinkClick = useCallback((event) => {
8+
countly.trackCustomLinkClick(
9+
countly.events.LINK_CLICK_FOOTER,
10+
event.currentTarget
11+
)
12+
}, [])
13+
314
return (
415
<footer className="bg-black db db-m flex-ns items-center justify-between f7 white pv3 ph5">
516
<div>
@@ -8,6 +19,7 @@ export default function Footer() {
819
<a
920
href="https://protocol.ai/"
1021
className="nspink underline-hover no-underline"
22+
onClick={onLinkClick}
1123
>
1224
Protocol Labs
1325
</a>
@@ -20,14 +32,18 @@ export default function Footer() {
2032
className="nspink no-underline underline-hover v-mid"
2133
target="_blank"
2234
rel="noreferrer"
35+
onClick={onLinkClick}
2336
>
2437
Status
2538
</a>
2639
</span>
2740
<Dot />
2841
<span className="db db-m dib-ns mv3">
2942
<Link href="/terms">
30-
<a className="nspink no-underline underline-hover v-mid">
43+
<a
44+
className="nspink no-underline underline-hover v-mid"
45+
onClick={onLinkClick}
46+
>
3147
Terms of Service
3248
</a>
3349
</Link>
@@ -38,6 +54,7 @@ export default function Footer() {
3854
<a
3955
href="https://github.com/ipfs-shipyard/nft.storage/issues/new"
4056
className="nspink underline-hover no-underline"
57+
onClick={onLinkClick}
4158
>
4259
Open an Issue
4360
</a>

packages/website/components/hero.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import countly from '../lib/countly'
12
import Button from './button.js'
23

34
const crossStyle = {
@@ -73,6 +74,7 @@ export default function Hero() {
7374
<Button
7475
wrapperClassName="mh3 mb3"
7576
href="#getting-started"
77+
tracking={{ ui: countly.ui.HOME_HERO, action: 'Get Started' }}
7678
>
7779
Get Started
7880
</Button>

packages/website/components/navbar.js

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useMemo, useRef, useState } from 'react'
1+
import { useMemo, useRef, useState, useCallback } from 'react'
22
import Router, { useRouter } from 'next/router'
33
import clsx from 'clsx'
44
import Link from 'next/link'
@@ -8,6 +8,7 @@ import { useResizeObserver } from '../hooks/resize-observer'
88
import Button from './button.js'
99
import Cross from '../icons/cross'
1010
import Hamburger from '../icons/hamburger'
11+
import countly from '../lib/countly'
1112

1213
/**
1314
* Navbar Component
@@ -60,18 +61,30 @@ export default function Navbar({ bgColor = 'bg-nsorange', user }) {
6061
],
6162
[user, isSmallVariant, version]
6263
)
64+
const onLinkClick = useCallback((event) => {
65+
countly.trackCustomLinkClick(
66+
countly.events.LINK_CLICK_NAVBAR,
67+
event.currentTarget
68+
)
69+
}, [])
6370

64-
async function logout() {
65-
await getMagic().user.logout()
66-
await queryClient.invalidateQueries('magic-user')
67-
Router.push({ pathname: '/', query: version ? { version } : null })
68-
}
69-
70-
const toggleMenu = () => {
71+
const toggleMenu = useCallback(() => {
7172
isMenuOpen
7273
? document.body.classList.remove('overflow-hidden')
7374
: document.body.classList.add('overflow-hidden')
7475
setMenuOpen(!isMenuOpen)
76+
}, [isMenuOpen])
77+
78+
const onMobileLinkClick = useCallback((event) => {
79+
onLinkClick(event)
80+
81+
toggleMenu()
82+
}, [onLinkClick, toggleMenu])
83+
84+
async function logout() {
85+
await getMagic().user.logout()
86+
await queryClient.invalidateQueries('magic-user')
87+
Router.push({ pathname: '/', query: version ? { version } : null })
7588
}
7689

7790
return (
@@ -92,7 +105,7 @@ export default function Navbar({ bgColor = 'bg-nsorange', user }) {
92105
</div>
93106
)}
94107
<Link href={{ pathname: '/', query: version ? { version } : null }}>
95-
<a className="no-underline v-mid">
108+
<a className="no-underline v-mid" onClick={onLinkClick}>
96109
<img
97110
src="/images/logo-nft.storage-sm.png"
98111
width="160"
@@ -114,6 +127,7 @@ export default function Navbar({ bgColor = 'bg-nsorange', user }) {
114127
'f4 black no-underline underline-hover v-mid',
115128
item.spacing
116129
)}
130+
onClick={onLinkClick}
117131
>
118132
{item.name}
119133
</a>
@@ -125,7 +139,15 @@ export default function Navbar({ bgColor = 'bg-nsorange', user }) {
125139
))}
126140
<div className="mb1">
127141
{user ? (
128-
<Button onClick={logout} id="logout">
142+
<Button
143+
onClick={logout}
144+
id="logout"
145+
tracking={{
146+
event: countly.events.LOGOUT_CLICK,
147+
ui: countly.ui.NAVBAR,
148+
action: 'Logout',
149+
}}
150+
>
129151
Logout
130152
</Button>
131153
) : (
@@ -135,6 +157,10 @@ export default function Navbar({ bgColor = 'bg-nsorange', user }) {
135157
query: version ? { version } : null,
136158
}}
137159
id="login"
160+
tracking={{
161+
ui: countly.ui.NAVBAR,
162+
action: 'Login',
163+
}}
138164
>
139165
Login
140166
</Button>
@@ -177,15 +203,15 @@ export default function Navbar({ bgColor = 'bg-nsorange', user }) {
177203
item.spacing,
178204
bgColor === 'bg-nsgreen' ? 'black' : 'white'
179205
)}
180-
onClick={() => toggleMenu()}
206+
onClick={onMobileLinkClick}
181207
>
182208
{item.name}
183209
</a>
184210
</Link>
185211
))}
186212
</div>
187213
<div className="flex flex-column items-center mb4">
188-
<Button className="flex justify-center" onClick={() => toggleMenu()}>
214+
<Button className="flex justify-center" onClick={toggleMenu}>
189215
<Cross fill="currentColor" />
190216
</Button>
191217
</div>

0 commit comments

Comments
 (0)