Files
heicode/_all-in-one-upload/cc-haha/src/hooks/useUpdateNotification.ts
T
gongzhiyong 0c84dde85b docs: Heicode 愿景范式、瀑布/敏捷子 Agnet 角色与规模
- 新增 docs/vision-heicode-full-stack-agentic-dev.md(完整范式与 W1-W9 / A1-A8 角色)
- 新增根 README.md 与 .gitignore(排除 node_modules、target 等)

Made-with: Cursor
2026-04-30 00:33:20 +08:00

35 lines
982 B
TypeScript

import { useState } from 'react'
import { major, minor, patch } from 'semver'
export function getSemverPart(version: string): string {
return `${major(version, { loose: true })}.${minor(version, { loose: true })}.${patch(version, { loose: true })}`
}
export function shouldShowUpdateNotification(
updatedVersion: string,
lastNotifiedSemver: string | null,
): boolean {
const updatedSemver = getSemverPart(updatedVersion)
return updatedSemver !== lastNotifiedSemver
}
export function useUpdateNotification(
updatedVersion: string | null | undefined,
initialVersion: string = MACRO.VERSION,
): string | null {
const [lastNotifiedSemver, setLastNotifiedSemver] = useState<string | null>(
() => getSemverPart(initialVersion),
)
if (!updatedVersion) {
return null
}
const updatedSemver = getSemverPart(updatedVersion)
if (updatedSemver !== lastNotifiedSemver) {
setLastNotifiedSemver(updatedSemver)
return updatedSemver
}
return null
}