Compare commits
6
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0bc8ca02a4 | ||
|
|
9af3407546 | ||
|
|
117de90c3e | ||
|
|
be60551f49 | ||
|
|
dcf2fe5a53 | ||
|
|
132301dc28 |
No files matched your search
+39
-20
@@ -34,7 +34,7 @@ import { ago, articleMeta, AVATAR_COLORS, cardBg, CHARACTERS, dateRange, loadOf,
|
||||
import { GoogleButton } from './googleLogin'
|
||||
import { useInstall, useInstallable } from './install'
|
||||
import { InstallSheet } from './installBanner'
|
||||
import { ARTICLE_CAT, SHEET_OPEN_MS } from './lib'
|
||||
import { ARTICLE_CAT, SHEET_CLOSE_MS, SHEET_OPEN_MS } from './lib'
|
||||
import { MixSheet } from './myGak'
|
||||
import { ownPage, useRegion } from './regionContext'
|
||||
import { WeatherWhySheet } from './weatherWhy'
|
||||
@@ -95,11 +95,25 @@ function SheetHost({ state, onClose }: { state: SheetState; onClose: () => void
|
||||
const [gakTitle, setGakTitle] = useState('')
|
||||
const [articleTitle, setArticleTitle] = useState('')
|
||||
|
||||
// 닫히는 동안에도 내려가는 창에 내용이 남아 있게, 마지막으로 연 창을 들고 있는다
|
||||
const [shown, setShown] = useState<SheetState>(state)
|
||||
if (state && state !== shown) setShown(state)
|
||||
const closing = !state && shown != null
|
||||
|
||||
useEffect(() => {
|
||||
const el = ref.current
|
||||
if (!el) return
|
||||
if (state && !el.open) el.showModal()
|
||||
if (!state && el.open) el.close()
|
||||
if (state) {
|
||||
if (!el.open) el.showModal()
|
||||
return
|
||||
}
|
||||
if (!el.open) return
|
||||
// 내려가는 애니메이션이 끝난 뒤에 실제로 닫는다
|
||||
const t = setTimeout(() => {
|
||||
el.close()
|
||||
setShown(null)
|
||||
}, SHEET_CLOSE_MS)
|
||||
return () => clearTimeout(t)
|
||||
}, [state])
|
||||
|
||||
// 창이 열려 있는 동안 뒤 페이지는 스크롤되지 않게 잠근다
|
||||
@@ -118,8 +132,8 @@ function SheetHost({ state, onClose }: { state: SheetState; onClose: () => void
|
||||
}
|
||||
}, [isOpen])
|
||||
|
||||
const then = state?.type === 'login' ? state.then : undefined
|
||||
const title = !state ? '' : state.type === 'gak' ? gakTitle : state.type === 'article' ? articleTitle || TITLES.article : state.type === 'mix' ? (state.shared ? '받은 각' : '내 각 만들기') : TITLES[state.type]
|
||||
const then = shown?.type === 'login' ? shown.then : undefined
|
||||
const title = !shown ? '' : shown.type === 'gak' ? gakTitle : shown.type === 'article' ? articleTitle || TITLES.article : shown.type === 'mix' ? (shown.shared ? '받은 각' : '내 각 만들기') : TITLES[shown.type]
|
||||
|
||||
return (
|
||||
<dialog
|
||||
@@ -127,12 +141,17 @@ function SheetHost({ state, onClose }: { state: SheetState; onClose: () => void
|
||||
aria-label={title}
|
||||
data-t={kind}
|
||||
onClose={onClose}
|
||||
// ESC 도 바로 닫지 않고 내려가며 닫히게
|
||||
onCancel={(e) => {
|
||||
e.preventDefault()
|
||||
onClose()
|
||||
}}
|
||||
onClick={(e) => {
|
||||
if (e.target === e.currentTarget) onClose()
|
||||
}}
|
||||
className="b-sheet-dialog b-app fixed inset-x-0 top-auto bottom-0 m-0 mx-auto max-h-[86dvh] w-full max-w-[440px] overflow-visible bg-transparent p-0 text-(--ink)"
|
||||
className={cx('b-sheet-dialog b-app fixed inset-x-0 top-auto bottom-0 m-0 mx-auto max-h-[86dvh] w-full max-w-[440px] overflow-visible bg-transparent p-0 text-(--ink)', closing && 'b-sheet-closing')}
|
||||
>
|
||||
{state && (
|
||||
{shown && (
|
||||
<div className="b-sheet flex max-h-[86dvh] flex-col rounded-t-[22px] bg-white pb-[env(safe-area-inset-bottom,0px)]">
|
||||
<div className="relative border-b border-(--line) px-4 pt-2 pb-2.5 text-center">
|
||||
<div className="mx-auto mb-2.5 h-1 w-10 rounded-full bg-(--line)" aria-hidden="true" />
|
||||
@@ -141,21 +160,21 @@ function SheetHost({ state, onClose }: { state: SheetState; onClose: () => void
|
||||
×
|
||||
</button>
|
||||
</div>
|
||||
{state.type === 'gak' && <GakSheet indexId={state.indexId} onTitle={setGakTitle} />}
|
||||
{state.type === 'article' && <ArticleSheet articleId={state.articleId} onTitle={setArticleTitle} />}
|
||||
{state.type === 'seasonWeek' && <SeasonWeekSheet />}
|
||||
{state.type === 'share' && <ShareSheet share={state.share} />}
|
||||
{state.type === 'comments' && <CommentsSheet postId={state.postId} draft={state.draft} />}
|
||||
{state.type === 'login' && <LoginSheet onDone={onClose} onLoggedIn={then ? () => open(then) : onClose} />}
|
||||
{state.type === 'me' && <MeSheet onDone={onClose} />}
|
||||
{state.type === 'region' && <RegionSheet onDone={onClose} />}
|
||||
{state.type === 'mix' && <MixSheet shared={state.shared} onDone={onClose} />}
|
||||
{state.type === 'install' && <InstallSheet />}
|
||||
{state.type === 'weatherWhy' && <WeatherWhySheet d={state.why} />}
|
||||
{state.type === 'talk' && <TalkSheet talk={state.talk} />}
|
||||
{shown.type === 'gak' && <GakSheet indexId={shown.indexId} onTitle={setGakTitle} />}
|
||||
{shown.type === 'article' && <ArticleSheet articleId={shown.articleId} onTitle={setArticleTitle} />}
|
||||
{shown.type === 'seasonWeek' && <SeasonWeekSheet />}
|
||||
{shown.type === 'share' && <ShareSheet share={shown.share} />}
|
||||
{shown.type === 'comments' && <CommentsSheet postId={shown.postId} draft={shown.draft} />}
|
||||
{shown.type === 'login' && <LoginSheet onDone={onClose} onLoggedIn={then ? () => open(then) : onClose} />}
|
||||
{shown.type === 'me' && <MeSheet onDone={onClose} />}
|
||||
{shown.type === 'region' && <RegionSheet onDone={onClose} />}
|
||||
{shown.type === 'mix' && <MixSheet shared={shown.shared} onDone={onClose} />}
|
||||
{shown.type === 'install' && <InstallSheet />}
|
||||
{shown.type === 'weatherWhy' && <WeatherWhySheet d={shown.why} />}
|
||||
{shown.type === 'talk' && <TalkSheet talk={shown.talk} />}
|
||||
</div>
|
||||
)}
|
||||
{!state && <RegionLinks />}
|
||||
{!shown && <RegionLinks />}
|
||||
</dialog>
|
||||
)
|
||||
}
|
||||
|
||||
+47
-5
@@ -120,13 +120,52 @@
|
||||
}
|
||||
}
|
||||
|
||||
/* 아래 창은 불투명한 채로 화면 아래에서 끝까지 올라오고, 닫힐 땐 다시 내려간다 (반투명으로 올라오면 뒤 탭 바가 비쳐 깜빡여 보였다) */
|
||||
.b-sheet {
|
||||
animation: b-up 0.26s cubic-bezier(0.2, 0.9, 0.3, 1);
|
||||
animation: b-up 0.28s cubic-bezier(0.2, 0.9, 0.3, 1);
|
||||
}
|
||||
.b-sheet-dialog[open]::backdrop {
|
||||
animation: b-fade-in 0.2s ease-out;
|
||||
}
|
||||
.b-sheet-closing .b-sheet {
|
||||
animation: b-down 0.2s ease-in forwards;
|
||||
}
|
||||
.b-sheet-closing::backdrop {
|
||||
animation: b-fade-out 0.2s ease-in forwards;
|
||||
}
|
||||
@keyframes b-up {
|
||||
from {
|
||||
transform: translateY(40px);
|
||||
opacity: 0.4;
|
||||
transform: translateY(100%);
|
||||
}
|
||||
}
|
||||
@keyframes b-down {
|
||||
to {
|
||||
transform: translateY(100%);
|
||||
}
|
||||
}
|
||||
@keyframes b-fade-in {
|
||||
from {
|
||||
opacity: 0;
|
||||
}
|
||||
}
|
||||
@keyframes b-fade-out {
|
||||
to {
|
||||
opacity: 0;
|
||||
}
|
||||
}
|
||||
/* 로그인 창을 한 번 닫은 뒤 쓰기 버튼을 누르면 '로그인하면 쓸 수 있어요'를 살짝 흔든다 */
|
||||
.b-nudge {
|
||||
display: inline-block;
|
||||
animation: b-nudge 0.4s ease-in-out;
|
||||
}
|
||||
@keyframes b-nudge {
|
||||
20%,
|
||||
60% {
|
||||
transform: translateX(-3px);
|
||||
}
|
||||
40%,
|
||||
80% {
|
||||
transform: translateX(3px);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -150,11 +189,14 @@
|
||||
.b-fall,
|
||||
.b-heart-pop,
|
||||
.b-like-bit,
|
||||
.b-sheet {
|
||||
.b-sheet,
|
||||
.b-sheet-dialog[open]::backdrop,
|
||||
.b-nudge {
|
||||
animation: none !important;
|
||||
}
|
||||
.b-heart-pop,
|
||||
.b-like-bit {
|
||||
.b-like-bit,
|
||||
.b-sheet-closing .b-sheet {
|
||||
opacity: 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,3 +17,5 @@ export const ARTICLE_CAT: Record<number, [string, string]> = { 1: [ARTICLE_LABEL
|
||||
|
||||
/** 아래 창이 다 올라오는 시간(.b-sheet 0.26s). 무거운 일은 이 뒤로 미뤄 올라오는 동안 버벅이지 않게 */
|
||||
export const SHEET_OPEN_MS = 280
|
||||
/** 아래 창이 내려가며 닫히는 시간(.b-sheet-closing 0.2s). 이 뒤에 실제로 닫는다 */
|
||||
export const SHEET_CLOSE_MS = 200
|
||||
+37
-8
@@ -36,6 +36,15 @@ const WRITE_ERRORS: Record<string, string> = {
|
||||
const GROUP_MIN = 3
|
||||
const COMPOSE_ID = 'talk-compose'
|
||||
|
||||
// 쓰기 버튼(쓰기 칸·사진·올리기·첫 이야기 카드)은 로그인 창을 이번 방문에 한 번만 띄운다. 닫은 뒤엔 쓰기 상자의 '로그인하면 쓸 수 있어요'만 깜빡인다
|
||||
let writeLoginShown = false
|
||||
const nudgeListeners = new Set<() => void>()
|
||||
function askWriteLogin(open: ReturnType<typeof useSheet>['open']) {
|
||||
if (writeLoginShown) return nudgeListeners.forEach((f) => f())
|
||||
writeLoginShown = true
|
||||
open({ type: 'login' })
|
||||
}
|
||||
|
||||
const REASONS = [
|
||||
[TalkReport.ABUSE, '욕설·비하'],
|
||||
[TalkReport.SPAM, '광고·도배'],
|
||||
@@ -58,6 +67,14 @@ function Composer({ onDone }: { onDone?: (t: TalkData) => void }) {
|
||||
const { region } = useRegion()
|
||||
const { loggedIn, me } = useAuth()
|
||||
const { open } = useSheet()
|
||||
const [nudge, setNudge] = useState(0)
|
||||
useEffect(() => {
|
||||
const f = () => setNudge((n) => n + 1)
|
||||
nudgeListeners.add(f)
|
||||
return () => {
|
||||
nudgeListeners.delete(f)
|
||||
}
|
||||
}, [])
|
||||
const refresh = useRefreshTalks()
|
||||
const add = useMutation(addTalkMutation())
|
||||
const [text, setText] = useState('')
|
||||
@@ -97,7 +114,7 @@ function Composer({ onDone }: { onDone?: (t: TalkData) => void }) {
|
||||
|
||||
const submit = (e: FormEvent) => {
|
||||
e.preventDefault()
|
||||
if (!loggedIn) return open({ type: 'login' })
|
||||
if (!loggedIn) return askWriteLogin(open)
|
||||
const body = text.trim()
|
||||
if (!body || busy) return
|
||||
setError(null)
|
||||
@@ -130,13 +147,19 @@ function Composer({ onDone }: { onDone?: (t: TalkData) => void }) {
|
||||
id={COMPOSE_ID}
|
||||
value={text}
|
||||
onChange={(e) => setText(e.target.value)}
|
||||
onFocus={(e) => {
|
||||
// 로그인 전엔 읽기 전용이라 눌러도 키보드가 안 올라온다 (키보드가 떴다 내려가며 로그인 창이 버벅이던 것). 누르거나 Enter 면 로그인 창
|
||||
onClick={(e) => {
|
||||
if (loggedIn) return
|
||||
// 로그인 창(<dialog>)은 닫힐 때 포커스를 이 칸으로 돌려놓아 다시 열리므로, 열기 전에 포커스를 뺀다
|
||||
// 창이 닫힐 때 포커스가 이 칸으로 돌아와 테두리가 번쩍이지 않게
|
||||
e.currentTarget.blur()
|
||||
open({ type: 'login' })
|
||||
askWriteLogin(open)
|
||||
}}
|
||||
readOnly={busy}
|
||||
onKeyDown={(e) => {
|
||||
if (loggedIn || (e.key !== 'Enter' && e.key !== ' ')) return
|
||||
e.preventDefault()
|
||||
askWriteLogin(open)
|
||||
}}
|
||||
readOnly={busy || !loggedIn}
|
||||
maxLength={BODY_MAX}
|
||||
rows={2}
|
||||
placeholder={`지금 ${region.name.split(' ').at(-1)} 날씨 어때요?`}
|
||||
@@ -167,10 +190,12 @@ function Composer({ onDone }: { onDone?: (t: TalkData) => void }) {
|
||||
</div>
|
||||
<input ref={fileRef} type="file" accept="image/*" onChange={pick} hidden />
|
||||
<div className="mt-1.5 flex items-center gap-2 text-xs font-bold text-(--ink3)">
|
||||
<button type="button" onClick={() => (loggedIn ? fileRef.current?.click() : open({ type: 'login' }))} disabled={busy} className="shrink-0 cursor-pointer rounded-full bg-[#eef4fc] px-3 py-1.5 text-[13px] font-extrabold text-(--ink2) disabled:opacity-40">
|
||||
<button type="button" onClick={() => (loggedIn ? fileRef.current?.click() : askWriteLogin(open))} disabled={busy} className="shrink-0 cursor-pointer rounded-full bg-[#eef4fc] px-3 py-1.5 text-[13px] font-extrabold text-(--ink2) disabled:opacity-40">
|
||||
사진
|
||||
</button>
|
||||
<span className="min-w-0 truncate">{me ? `${me.nickname} · ${region.name.split(' ').at(-1)} · 지금 날씨가 함께 올라가요` : '로그인하면 쓸 수 있어요'}</span>
|
||||
<span key={nudge} className={cx('min-w-0 truncate', !me && nudge > 0 && 'b-nudge text-(--orange-deep)')}>
|
||||
{me ? `${me.nickname} · ${region.name.split(' ').at(-1)} · 지금 날씨가 함께 올라가요` : '로그인하면 쓸 수 있어요'}
|
||||
</span>
|
||||
<span className="ml-auto tabular-nums">
|
||||
{text.length}/{BODY_MAX}
|
||||
</span>
|
||||
@@ -360,10 +385,14 @@ export function TalkGroup({ title, topic, talks }: { title: string; topic?: numb
|
||||
export function FirstTalkCard() {
|
||||
const { region } = useRegion()
|
||||
const place = region.name.split(' ').at(-1)
|
||||
const { loggedIn } = useAuth()
|
||||
const { open } = useSheet()
|
||||
const go = () => {
|
||||
if (!loggedIn && !writeLoginShown) return askWriteLogin(open)
|
||||
const el = document.getElementById(COMPOSE_ID)
|
||||
el?.scrollIntoView({ behavior: 'smooth', block: 'center' })
|
||||
el?.focus({ preventScroll: true })
|
||||
if (loggedIn) el?.focus({ preventScroll: true })
|
||||
else askWriteLogin(open)
|
||||
}
|
||||
return (
|
||||
<button type="button" onClick={go} className="mx-3 mt-3.5 flex w-[calc(100%-1.5rem)] cursor-pointer items-center gap-3 rounded-[22px] bg-white p-3.5 text-left shadow-[inset_0_-5px_0_var(--shade)]">
|
||||
|
||||
Reference in new issue
Block a user