tz / kkndme /frontend /src /components /TextVersion.tsx
Ethscriptions's picture
Add kkndme 论房价 project source (in kkndme/)
95ab2cb verified
Raw History Blame Contribute Delete
13.4 kB
import { useMemo, useState } from 'react'
import { Copy, Check, Download } from 'lucide-react'
import { STATUS_META } from './status'
import { OUTLOOK_CAVEAT, OUTLOOK_CONCLUSION, OUTLOOK_DISCLAIMER, OUTLOOK_POINTS, OUTLOOK_QUESTIONS, outlookText } from '../data/outlook'
import { CHECK_DATE, buildText, predText, predTopics, stats, theoryGroups, theoryText } from '../lib/kkText'
import type { Prediction, Theory } from '../data/types'
const BASE = import.meta.env.BASE_URL
async function copyText(s: string) {
try {
await navigator.clipboard.writeText(s)
return true
} catch {
const ta = document.createElement('textarea')
ta.value = s
ta.style.position = 'fixed'
ta.style.opacity = '0'
document.body.appendChild(ta)
ta.select()
const ok = document.execCommand('copy')
ta.remove()
return ok
}
}
function CopyBtn({ text, label = '复制', strong }: { text: string; label?: string; strong?: boolean }) {
const [done, setDone] = useState(false)
return (
<button
onClick={() =>
copyText(text).then((ok) => {
if (!ok) return
setDone(true)
setTimeout(() => setDone(false), 1500)
})
}
className={
strong
? 'inline-flex items-center gap-1.5 rounded-lg bg-primary px-3 py-2 text-sm font-bold text-primary-foreground'
: 'inline-flex shrink-0 items-center gap-1 rounded-md border border-border px-2 py-1 text-xs text-muted-foreground hover:text-foreground'
}
>
{done ? <Check size={strong ? 15 : 12} /> : <Copy size={strong ? 15 : 12} />}
{done ? '已复制' : label}
</button>
)
}
function Row({ k, children }: { k: string; children: React.ReactNode }) {
return (
<p className="mt-1.5 text-sm leading-relaxed">
<span className="mr-1 font-semibold text-foreground">{k}:</span>
<span className="text-foreground/85">{children}</span>
</p>
)
}
function TheoryBlock({ t }: { t: Theory }) {
return (
<article id={`tx-${t.id}`} className="scroll-mt-24 border-b border-border/60 py-4 last:border-b-0">
<div className="flex items-start justify-between gap-3">
<h4 className="text-[15px] font-bold leading-snug">
<span className="mr-1.5 font-mono text-xs text-muted-foreground">{t.id}</span>
{t.title}
</h4>
<CopyBtn text={theoryText(t, false)} />
</div>
<Row k="观点">{t.summary}</Row>
<Row k="原话">
{t.quote}
<span className="text-muted-foreground">({t.ref})</span>
</Row>
{t.hindsight && <Row k="15 年后回头看">{t.hindsight}</Row>}
</article>
)
}
function PredBlock({ p }: { p: Prediction }) {
const m = STATUS_META[p.status]
return (
<article id={`tx-${p.id}`} className="scroll-mt-24 border-b border-border/60 py-4 last:border-b-0">
<div className="flex items-start justify-between gap-3">
<h4 className="text-[15px] font-bold leading-snug">
<span className="mr-1.5 font-mono text-xs text-muted-foreground">{p.id}</span>
{p.title}
<span className="ml-2 inline-block whitespace-nowrap rounded-full px-2 py-0.5 align-middle text-[11px] font-semibold" style={{ color: m.color, border: `1px solid ${m.color}66` }}>
{m.label}
</span>
</h4>
<CopyBtn text={predText(p, false)} />
</div>
<Row k="原话">{p.quote}</Row>
<Row k="意思">{p.claim}</Row>
<Row k="出处">
{p.ref};发帖 {p.posted};预测期限 {p.horizon}
</Row>
<Row k="核对结论">{p.verdict}</Row>
{p.evidence.length > 0 && (
<div className="mt-1.5 text-sm leading-relaxed">
<span className="font-semibold">依据:</span>
<ol className="mt-0.5 list-decimal space-y-0.5 pl-5 text-foreground/80">
{p.evidence.map((e, i) => (
<li key={i}>
{e.text}
<span className="text-muted-foreground">({e.source})</span>
</li>
))}
</ol>
</div>
)}
</article>
)
}
export default function TextVersion() {
const [part, setPart] = useState<'all' | 'theory' | 'pred' | 'ai'>('all')
const s = stats()
const full = useMemo(() => buildText(false), [])
const theoryAll = useMemo(() => theoryGroups.flatMap((g) => g.items.map((t) => theoryText(t, false))).join('\n\n'), [])
const predAll = useMemo(() => predTopics.flatMap((g) => g.items.map((p) => predText(p, false))).join('\n\n'), [])
const aiAll = useMemo(() => outlookText(false), [])
const chars = [...full].length
return (
<section className="mt-4">
<div className="rounded-xl border border-border bg-card/60 p-4">
<h3 className="text-base font-black">📝 文字版 · kkndme 的理论与预测</h3>
<p className="mt-1 text-sm leading-relaxed text-muted-foreground">
把 {theoryGroups.reduce((n, g) => n + g.items.length, 0)} 条理论和 {s.n} 条预测全部写成文字:每条理论有观点、原话、15 年后回头看;每条预测有原话、意思、出处、核对结论和依据;最后附 AI 按他的理论框架对未来房价的推演。核对截至 {CHECK_DATE},全文约 {(chars / 10000).toFixed(1)} 万字,可以整份复制、下载,也可以单条复制。
</p>
<div className="mt-3 flex flex-wrap gap-2">
<CopyBtn text={full} label="复制全文" strong />
<a href={`${BASE}dl/kkndme-text.txt`} download="kkndme理论与预测-文字版.txt" className="inline-flex items-center gap-1.5 rounded-lg border border-border px-3 py-2 text-sm font-bold">
<Download size={15} />
下载 TXT
</a>
<a href={`${BASE}dl/kkndme-text.md`} download="kkndme理论与预测-文字版.md" className="inline-flex items-center gap-1.5 rounded-lg border border-border px-3 py-2 text-sm font-bold">
<Download size={15} />
下载 Markdown
</a>
<CopyBtn text={theoryAll} label="只复制理论" />
<CopyBtn text={predAll} label="只复制预测" />
<CopyBtn text={aiAll} label="只复制 AI 推演" />
</div>
<p className="mt-3 rounded-lg bg-muted/40 px-3 py-2 text-sm leading-relaxed">
<b>总账:</b>
{s.n} 条预测中,已到期 {s.due} 条——说中 <b style={{ color: STATUS_META.correct.color }}>{s.correct}</b> 条、没说中{' '}
<b style={{ color: STATUS_META.wrong.color }}>{s.wrong}</b> 条、存疑 <b style={{ color: STATUS_META.disputed.color }}>{s.disputed}</b> 条;还没到时间 {s.pending} 条。命中率:只算能分对错的是 {s.hit}%,存疑算半分约 {s.half}%,存疑一律当错(最严格)约 {s.strict}%。
</p>
</div>
<div className="sticky top-0 z-10 -mx-4 mt-4 flex gap-1 overflow-x-auto bg-background/95 px-4 py-2 backdrop-blur">
{(
[
['all', '全部'],
['theory', `理论框架 ${theoryGroups.reduce((n, g) => n + g.items.length, 0)}`],
['pred', `预测与核对 ${s.n}`],
['ai', 'AI 推演'],
] as const
).map(([k, label]) => (
<button
key={k}
onClick={() => setPart(k)}
className={`shrink-0 rounded-full border px-3 py-1 text-xs font-semibold ${part === k ? 'border-foreground bg-foreground text-background' : 'border-border text-muted-foreground'}`}
>
{label}
</button>
))}
<span className="mx-1 w-px shrink-0 bg-border" />
{([] as [string, string, string][])
.concat(part === 'all' || part === 'theory' ? theoryGroups.map((g): [string, string, string] => ['th', g.name, g.items[0].id]) : [])
.concat(part === 'all' || part === 'pred' ? predTopics.map((g): [string, string, string] => ['pd', g.name, g.items[0].id]) : [])
.map(([kind, name, id]) => (
<button
key={kind + name}
onClick={() => document.getElementById(`tx-${id}`)?.scrollIntoView({ behavior: 'smooth', block: 'start' })}
className="shrink-0 whitespace-nowrap rounded-full px-2.5 py-1 text-xs text-muted-foreground hover:bg-muted/50 hover:text-foreground"
>
{kind === 'th' ? '理论·' : '预测·'}
{name}
</button>
))}
</div>
{(part === 'all' || part === 'theory') && (
<div className="mt-4">
<h3 className="text-lg font-black">第一部分 · 理论框架</h3>
{theoryGroups.map((g, gi) => (
<div key={g.name} className="mt-4 rounded-xl border border-border bg-card/40 px-4">
<div className="border-b border-border py-2.5 text-sm font-bold">
{gi + 1}. {g.name}
<span className="ml-1.5 font-normal text-muted-foreground">{g.items.length} 条</span>
</div>
{g.items.map((t) => (
<TheoryBlock key={t.id} t={t} />
))}
</div>
))}
</div>
)}
{(part === 'all' || part === 'pred') && (
<div className="mt-8">
<h3 className="text-lg font-black">第二部分 · 预测与核对</h3>
{predTopics.map((g, gi) => {
const ok = g.items.filter((p) => p.status === 'correct').length
const no = g.items.filter((p) => p.status === 'wrong').length
return (
<div key={g.name} className="mt-4 rounded-xl border border-border bg-card/40 px-4">
<div className="border-b border-border py-2.5 text-sm font-bold">
{gi + 1}. {g.name}
<span className="ml-1.5 font-normal text-muted-foreground">
{g.items.length} 条 · 说中 {ok} · 没说中 {no}
</span>
</div>
{g.items.map((p) => (
<PredBlock key={p.id} p={p} />
))}
</div>
)
})}
</div>
)}
{(part === 'all' || part === 'ai') && <AiOutlook />}
<p className="mt-6 text-xs text-muted-foreground">说明:前两部分仅做历史言论的事实核对;第三部分为 AI 推演。全部内容均不构成任何买房或投资建议。</p>
</section>
)
}
const TONE = { up: '#34d399', down: '#f87171', flat: '#fbbf24' } as const
function AiOutlook() {
return (
<div className="mt-8" id="tx-ai">
<div className="flex flex-wrap items-center gap-2">
<h3 className="text-lg font-black">第三部分 · AI 推演:按理论框架看未来房价</h3>
<span className="rounded-full border border-amber-400/60 bg-amber-400/10 px-2 py-0.5 text-xs font-bold text-amber-300">不构成投资建议</span>
</div>
<p className="mt-2 rounded-lg border border-amber-400/30 bg-amber-400/5 px-3 py-2 text-sm leading-relaxed text-muted-foreground">{OUTLOOK_DISCLAIMER}</p>
<div className="mt-4 rounded-xl border border-border bg-card/40 p-4">
<div className="text-sm font-bold">理论框架回答的三个根本问题</div>
<div className="mt-3 grid gap-2 sm:grid-cols-3">
{OUTLOOK_QUESTIONS.map((x, i) => (
<div key={x.q} className="rounded-lg bg-muted/40 px-3 py-2.5">
<div className="text-xs text-muted-foreground">问题 {i + 1}</div>
<div className="mt-0.5 font-black">{x.q}</div>
<div className="mt-1 text-xs leading-relaxed text-muted-foreground">
{x.basis}({x.refs.join('、')})
</div>
</div>
))}
</div>
</div>
<div className="mt-4 grid gap-3">
{OUTLOOK_POINTS.map((pt) => (
<div key={pt.no} className="rounded-xl border border-border bg-card/40 p-4" style={{ borderLeft: `3px solid ${TONE[pt.tone]}` }}>
<div className="flex flex-wrap items-baseline gap-2">
<span className="font-mono text-sm font-bold" style={{ color: TONE[pt.tone] }}>
{pt.no}
</span>
<span className="text-base font-black">{pt.title}</span>
<span className="text-sm font-bold">{pt.short}</span>
</div>
<div className="mt-1.5 text-xs text-muted-foreground">
依据:{pt.basis}({pt.refs.join('、')})
</div>
<p className="mt-2 text-sm leading-relaxed">{pt.detail}</p>
</div>
))}
</div>
<div className="mt-4 rounded-xl border border-border bg-card/40 p-4">
<div className="text-sm font-bold">要打折扣的地方:{OUTLOOK_CAVEAT.title}</div>
<div className="mt-3 flex flex-wrap gap-3">
{OUTLOOK_CAVEAT.stats.map((x) => (
<div key={x.l} className="rounded-lg bg-muted/40 px-3 py-2">
<div className="text-xs text-muted-foreground">{x.l}</div>
<div className="font-mono text-xl font-black">{x.v}</div>
</div>
))}
</div>
<p className="mt-3 text-sm leading-relaxed text-muted-foreground">{OUTLOOK_CAVEAT.text}</p>
</div>
<p className="mt-4 rounded-xl bg-muted/40 px-4 py-3 text-sm font-bold leading-relaxed">结论:{OUTLOOK_CONCLUSION}</p>
</div>
)
}