mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-16 13:05:14 +03:00
feat(app): wait an hour after first launch before the first tip (#63760)
This commit is contained in:
@@ -7,7 +7,7 @@ import { Persist, persisted } from "@/runtime/persistence/storage"
|
||||
import { usePlatform } from "@/runtime/platform/platform"
|
||||
import { ServerConnection, useServers } from "@/runtime/server/registry"
|
||||
import { useGlobal } from "@/runtime/server/runtime"
|
||||
import { selectTip, TIP_INTERVAL_MS, type Tip } from "./queue"
|
||||
import { FIRST_TIP_DELAY_MS, selectTip, TIP_INTERVAL_MS, type Tip } from "./queue"
|
||||
|
||||
const STARTUP_DELAY = 2 * 60 * 1000
|
||||
|
||||
@@ -16,6 +16,7 @@ const History = Persistence.struct({
|
||||
shownAt: Schema.Finite,
|
||||
dismissed: Persistence.array(Schema.String),
|
||||
dismissedAt: Schema.Finite,
|
||||
firstSeen: Persistence.fallback(Schema.Finite, () => 0),
|
||||
})
|
||||
|
||||
export function createTipToasts() {
|
||||
@@ -79,6 +80,11 @@ export function createTipToasts() {
|
||||
shownAt: 0,
|
||||
dismissed: [],
|
||||
dismissedAt: 0,
|
||||
firstSeen: 0,
|
||||
})
|
||||
|
||||
createEffect(() => {
|
||||
if (loaded() && !history.firstSeen) setHistory("firstSeen", Date.now())
|
||||
})
|
||||
|
||||
const [tick, setTick] = createSignal(0)
|
||||
@@ -90,6 +96,7 @@ export function createTipToasts() {
|
||||
|
||||
const times = [
|
||||
Math.max(history.shownAt, history.dismissedAt) + TIP_INTERVAL_MS,
|
||||
history.firstSeen + FIRST_TIP_DELAY_MS,
|
||||
...tips.flatMap((tip) => [tip.start ?? 0, tip.end ?? 0]),
|
||||
]
|
||||
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
import { expect, test } from "bun:test"
|
||||
import { selectTip, type Tip } from "./queue"
|
||||
|
||||
const fresh = { current: "", shownAt: 0, dismissed: [], dismissedAt: 0 }
|
||||
const hours = 60 * 60 * 1000
|
||||
|
||||
// Installed an hour before time 0, so the first-tip delay has already passed.
|
||||
const fresh = { current: "", shownAt: 0, dismissed: [], dismissedAt: 0, firstSeen: -hours }
|
||||
|
||||
const first: Tip = { id: "first", title: "tips.browse.title", description: "tips.browse.description" }
|
||||
|
||||
@@ -9,7 +12,13 @@ const second: Tip = { ...first, id: "second" }
|
||||
|
||||
const tips = [first, second]
|
||||
|
||||
const hours = 60 * 60 * 1000
|
||||
test("the first tip waits an hour after the app first ran", () => {
|
||||
const installed = { ...fresh, firstSeen: 10 * hours }
|
||||
expect(selectTip(tips, installed, 11 * hours - 1)).toBeUndefined()
|
||||
expect(selectTip(tips, installed, 11 * hours)).toBe(first)
|
||||
expect(selectTip(tips, { ...fresh, firstSeen: 0 }, 5 * hours)).toBeUndefined()
|
||||
expect(selectTip(tips, { ...installed, dismissed: [first.id], dismissedAt: 1 }, 25 * hours)).toBe(second)
|
||||
})
|
||||
|
||||
test("first eligible tip wins until it is handled or stops being eligible", () => {
|
||||
expect(selectTip(tips, fresh, 1)).toBe(first)
|
||||
|
||||
@@ -2,6 +2,8 @@ import type { useLanguage } from "@/runtime/i18n/language"
|
||||
|
||||
export const TIP_INTERVAL_MS = 24 * 60 * 60 * 1000
|
||||
|
||||
export const FIRST_TIP_DELAY_MS = 60 * 60 * 1000
|
||||
|
||||
type Text = Parameters<ReturnType<typeof useLanguage>["t"]>[0]
|
||||
|
||||
export type Tip = {
|
||||
@@ -19,6 +21,7 @@ export type TipHistory = {
|
||||
shownAt: number
|
||||
dismissed: readonly string[]
|
||||
dismissedAt: number
|
||||
firstSeen: number
|
||||
}
|
||||
|
||||
/** Array order is priority. Dates are epoch milliseconds; the end is exclusive. */
|
||||
@@ -37,5 +40,7 @@ export function selectTip(tips: readonly Tip[], history: TipHistory, now: number
|
||||
|
||||
if (last && now < last + TIP_INTERVAL_MS) return
|
||||
|
||||
if (!last && now < (history.firstSeen || now) + FIRST_TIP_DELAY_MS) return
|
||||
|
||||
return tips.find(eligible)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user