Files
o2o-weather/frontend/src/b/installBanner.tsx
T

132 lines
6.3 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { useEffect, useState, type ReactNode } from 'react'
import { track } from '../lib/analytics'
import { cx } from '../lib/utils'
import { dismiss, dismissed, platform, promptInstall, useCanPrompt, useInstall, useInstallable } from './install'
import { TAP44 } from './ui'
const SITE = 'https://weather.o2o.kr'
/** 오늘 탭의 작은 설치 카드. 오늘의 각까지 본 뒤 자리에 놓고, 설치할 수 있는 곳(휴대폰, PC Chrome·Edge)에서만 보인다. 닫으면 2주 숨긴다 */
export function InstallBanner() {
const install = useInstall()
const installable = useInstallable()
const [closed, setClosed] = useState(dismissed)
const hidden = !installable || closed
useEffect(() => {
if (!hidden) track('install_banner_view', {})
}, [hidden])
if (hidden) return null
return (
<aside aria-label="홈 화면에 추가" className="mt-3.5 flex items-center gap-2.5 border-y border-(--line) bg-white py-2.5 pr-1.5 pl-3">
<img src="/app/icon-192.png" alt="" className="size-10 shrink-0 rounded-[11px]" />
<div className="min-w-0 flex-1">
<p className="m-0 font-jua text-[15px] leading-snug">내일도 우산각·빨래각, 바로 확인하세요</p>
<p className="m-0 text-xs leading-snug font-semibold text-(--ink2)">홈 화면에서 바로 열어 보세요.</p>
</div>
<button type="button" onClick={() => install('banner')} className="shrink-0 cursor-pointer rounded-full bg-(--orange) px-3.5 py-1.5 text-[13px] font-extrabold text-white">
추가
</button>
<button
type="button"
onClick={() => {
dismiss()
setClosed(true)
}}
aria-label="닫기"
className={cx('relative grid size-[30px] shrink-0 cursor-pointer place-items-center text-xl text-(--ink3)', TAP44)}
>
×
</button>
</aside>
)
}
function Steps({ items }: { items: ReactNode[] }) {
return (
<ol className="m-0 flex list-none flex-col gap-2 p-0">
{items.map((t, i) => (
<li key={i} className="flex items-start gap-2.5 rounded-2xl bg-[#f3f6fb] px-3.5 py-3 text-[14.5px] font-bold">
<b className="grid size-6 shrink-0 place-items-center rounded-full bg-(--orange) font-jua text-[14px] font-normal text-white">{i + 1}</b>
<span>{t}</span>
</li>
))}
</ol>
)
}
// 사파리 아래 가운데 공유 버튼과 공유 목록의 '홈 화면에 추가' 모양 그대로
const ShareGlyph = () => (
<svg viewBox="0 0 24 24" className="mx-0.5 inline size-[22px] -translate-y-0.5 fill-none stroke-[#2f7cf6] stroke-2 [stroke-linecap:round] [stroke-linejoin:round]" aria-label="공유 버튼">
<path d="M12 3v12M8 7l4-4 4 4M6 11H5v10h14V11h-1" />
</svg>
)
const AddGlyph = () => (
<svg viewBox="0 0 24 24" className="mx-0.5 inline size-[22px] -translate-y-0.5 fill-none stroke-(--ink) stroke-2 [stroke-linecap:round]" aria-hidden="true">
<rect x="4" y="4" width="16" height="16" rx="4" />
<path d="M12 8v8M8 12h8" />
</svg>
)
/** 설치창을 띄울 수 없는 기기의 안내. 안드로이드는 열어 둔 사이 크롬이 설치를 허락하면 바로 설치 버튼으로 바뀐다 */
export function InstallSheet() {
const p = platform()
const canPrompt = useCanPrompt()
const [copied, setCopied] = useState(false)
const copy = () =>
navigator.clipboard.writeText(SITE).then(
() => setCopied(true),
(e: unknown) => console.error('[install] copy', e),
)
return (
<div className="flex-1 overflow-auto overscroll-contain px-4 pt-3.5 pb-[18px]">
{p === 'standalone' && <p className="m-0 text-[15px] font-bold">이미 홈 화면에서 열었어요. 다음에도 아이콘을 눌러 바로 여세요.</p>}
{p === 'ios' && (
<>
<p className="m-0 mb-3 text-[14px] font-semibold text-(--ink2)">아이폰은 Safari에서 이렇게 추가해요.</p>
<Steps
items={[
<>화면 아래 <ShareGlyph /> 공유 버튼을 눌러요. 안 보이면 오른쪽 아래 ··· 를 누른 뒤 공유</>,
<>목록을 올려 <AddGlyph /> 홈 화면에 추가를 눌러요</>,
"오른쪽 위 '추가'를 누르면 끝이에요",
]}
/>
</>
)}
{p === 'android' && canPrompt && (
<button type="button" onClick={() => void promptInstall()} className="w-full cursor-pointer rounded-full bg-(--orange) py-3 font-jua text-[17px] text-white">
📲 지금 설치하기
</button>
)}
{p === 'android' && !canPrompt && (
<>
<p className="m-0 mb-3 text-[14px] font-semibold text-(--ink2)">지금 브라우저에선 설치창을 바로 띄울 수 없어요. 메뉴에서 추가해 주세요.</p>
<Steps items={['오른쪽 위 ⋮ 메뉴를 눌러요', "'홈 화면에 추가' 또는 '앱 설치'를 눌러요", "'추가' 또는 '설치'를 누르면 끝이에요"]} />
</>
)}
{p === 'inapp' && (
<>
<p className="m-0 mb-3 text-[14px] font-semibold text-(--ink2)">카카오톡 같은 앱 안에서는 홈 화면에 추가할 수 없어요. Safari나 Chrome에서 열어 주세요.</p>
<Steps items={["오른쪽 위 ⋮ 또는 공유 버튼에서 '다른 브라우저로 열기'를 눌러요", '안 보이면 아래 주소를 복사해 Safari·Chrome에 붙여 넣어요', "열린 화면에서 '홈 화면에 추가'를 눌러요"]} />
</>
)}
{p === 'other' && (
<>
<p className="m-0 mb-3 text-[14px] font-semibold text-(--ink2)">휴대폰에서 열면 홈 화면에 추가할 수 있어요.</p>
<Steps items={['휴대폰 Safari(아이폰)나 Chrome(갤럭시)에서 아래 주소를 열어요', "공유 버튼이나 ⋮ 메뉴에서 '홈 화면에 추가'를 눌러요"]} />
</>
)}
{(p === 'inapp' || p === 'other') && (
<div className="mt-3 flex items-center gap-2 rounded-2xl border border-(--line) px-3.5 py-2.5">
<span className="min-w-0 flex-1 truncate text-[14.5px] font-bold select-all">{SITE}</span>
<button type="button" onClick={copy} className="shrink-0 cursor-pointer rounded-full bg-(--ink) px-3 py-1.5 text-[12.5px] font-extrabold text-white">
{copied ? '복사함' : '주소 복사'}
</button>
</div>
)}
</div>
)
}