Skip to content

Commit cf9861e

Browse files
committed
feat: destinations
1 parent 4755999 commit cf9861e

File tree

5 files changed

+77
-45
lines changed

5 files changed

+77
-45
lines changed

lib/components/Destination.tsx

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ export const Destination = ({ platform, value, onChange }: DestinationProps) =>
2727
<PlatformIcon />
2828
</Box>
2929

30-
3130
{platform === "web" && <Web value={value} onChange={onChange} />}
31+
{platform === "ios" && <IOSDestination value={value} onChange={onChange} />}
32+
{platform === "android" && <AndroidDestination value={value} onChange={onChange} />}
3233
</Box>
3334
)
3435
}
@@ -45,3 +46,27 @@ const Web = ({ value, onChange }: { value: string, onChange: (value: string) =>
4546
/>
4647
)
4748
}
49+
50+
const IOSDestination = ({ value, onChange }: { value: string, onChange: (value: string) => void }) => {
51+
return (
52+
<TextField
53+
label="Destination"
54+
value={value}
55+
type="text"
56+
helperText="Please provider the iOS Universal Link you would like to redirect to?"
57+
onChange={(e) => onChange(e.target.value)}
58+
/>
59+
)
60+
}
61+
62+
const AndroidDestination = ({ value, onChange }: { value: string, onChange: (value: string) => void }) => {
63+
return (
64+
<TextField
65+
label="Destination"
66+
value={value}
67+
type="text"
68+
helperText="Please provider the Android App Link you would like to redirect to?"
69+
onChange={(e) => onChange(e.target.value)}
70+
/>
71+
)
72+
}

lib/components/LinkConfig/EditModal.tsx

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
CircularProgress,
1313
Box,
1414
} from "@mui/material"
15-
import { Close } from "@mui/icons-material"
15+
import { Android, Close, PhoneIphone, Public } from "@mui/icons-material"
1616

1717
import { LinkConfig } from "@/lib/services/linkConfig"
1818
import { ConfirmButton } from "../ConfirmButton"
@@ -30,7 +30,9 @@ const EditModal = ({ open, onClose, config }: EditModalProps): JSX.Element => {
3030
const [seoTitle, setSeoTitle] = useState(config?.seo?.title || "")
3131
const [seoDescription, setSeoDescription] = useState(config?.seo?.description || "")
3232
const [seoMedia, setSeoMedia] = useState(config?.seo?.media || "")
33-
const [destinationValue, setDestinationValue] = useState(config?.destinations?.[0]?.value || "")
33+
const [webDestValue, setWebDestValue] = useState(config?.destinations?.find(dest => dest.platform === "web")?.value || "")
34+
const [iosDestValue, setIosDestValue] = useState(config?.destinations?.find(dest => dest.platform === "ios")?.value || "")
35+
const [androidDestValue, setAndroidDestValue] = useState(config?.destinations?.find(dest => dest.platform === "android")?.value || "")
3436

3537
const [error, setError] = useState("")
3638
const [isLoading, setIsLoading] = useState(false)
@@ -42,6 +44,29 @@ const EditModal = ({ open, onClose, config }: EditModalProps): JSX.Element => {
4244
onClose && onClose()
4345
}
4446

47+
const buildDestinations = () => {
48+
const destinations = []
49+
if (webDestValue) {
50+
destinations.push({
51+
platform: "web",
52+
value: webDestValue,
53+
})
54+
}
55+
if (iosDestValue) {
56+
destinations.push({
57+
platform: "ios",
58+
value: iosDestValue,
59+
})
60+
}
61+
if (androidDestValue) {
62+
destinations.push({
63+
platform: "android",
64+
value: androidDestValue,
65+
})
66+
}
67+
return destinations
68+
}
69+
4570
const createNewConfig = async (): Promise<string | undefined> => {
4671
try {
4772
const res = await fetch("/api/linkConfigs", {
@@ -58,10 +83,7 @@ const EditModal = ({ open, onClose, config }: EditModalProps): JSX.Element => {
5883
description: seoDescription || "",
5984
media: seoMedia || "",
6085
},
61-
destinations: [{
62-
platform: "web",
63-
value: destinationValue,
64-
}],
86+
destinations: buildDestinations(),
6587
}),
6688
})
6789

@@ -102,7 +124,6 @@ const EditModal = ({ open, onClose, config }: EditModalProps): JSX.Element => {
102124
setIsLoading(false)
103125
}
104126

105-
106127
return (
107128
<Dialog open={open} onClose={handleClose} fullWidth>
108129
<AppBar sx={{ position: "relative" }} color="transparent" elevation={0}>
@@ -131,8 +152,14 @@ const EditModal = ({ open, onClose, config }: EditModalProps): JSX.Element => {
131152

132153
<Box my={2}>
133154
<Typography variant="subtitle1">Destinations</Typography>
134-
{/* <Repeater onAdd, onRemove, items={config.destinations}, renderChild /> */}
135-
<Destination platform="web" value={destinationValue} onChange={val => setDestinationValue(val)} />
155+
{/* todo: better check here */}
156+
{!webDestValue && <IconButton onClick={() => setWebDestValue("https://")}><Public color="primary" /></IconButton>}
157+
{!iosDestValue && <IconButton onClick={() => setIosDestValue("https://")}><PhoneIphone color="primary" /></IconButton>}
158+
{!androidDestValue && <IconButton onClick={() => setAndroidDestValue("https://")}><Android color="primary" /></IconButton>}
159+
160+
{webDestValue && <Destination platform="web" value={webDestValue} onChange={val => setWebDestValue(val)} />}
161+
{iosDestValue && <Destination platform="ios" value={iosDestValue} onChange={val => setIosDestValue(val)} />}
162+
{androidDestValue && <Destination platform="android" value={androidDestValue} onChange={val => setAndroidDestValue(val)} />}
136163

137164
</Box>
138165

lib/components/PlatformRedirect.tsx

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,25 @@ export interface PlatformRedirectProps {
44
}
55

66
const PlatformRedirect = ({ destinations }: PlatformRedirectProps) => {
7+
if (navigator && /iPad|iPhone|iPod/i.test(navigator.userAgent)) {
8+
console.log("on iOS")
9+
const dest = destinations.find(dest => dest.platform === "ios")
10+
window.location.href = dest?.value || "#"
11+
return
12+
}
13+
14+
if (navigator && /Android/i.test(navigator.userAgent)) {
15+
console.log("on Android")
16+
const dest = destinations.find(dest => dest.platform === "android")
17+
window.location.href = dest?.value || "#"
18+
return
19+
}
720

821
if (window && Array.isArray(destinations)) {
22+
console.log("on web")
923
const web = destinations.find(dest => dest.platform === "web")
1024
if (web && web.value) {
11-
window.location.href = web.value
25+
window.location.href = web.value || "#"
1226
return null
1327
}
1428
}

lib/components/Repeater/index.tsx

Lines changed: 0 additions & 33 deletions
This file was deleted.

pages/index.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ export default function Home({
3030

3131
const handleCopy = (docId: string) => {
3232
if (navigator.clipboard) {
33-
// todo: fix copy url
3433
navigator.clipboard.writeText(
3534
`${window.location.host}/link/${userId}/${docId}`
3635
)

0 commit comments

Comments
 (0)