This repository has no description
1package models
2
3import (
4 "time"
5)
6
7type OnboardingStatus string
8
9const (
10 OnboardingInProgress OnboardingStatus = "in_progress"
11 OnboardingCompleted OnboardingStatus = "completed"
12 OnboardingSkipped OnboardingStatus = "skipped"
13)
14
15// onboarding steps, in order. Done is a sentinel that marks completion.
16const (
17 OnboardingStepProfile = 0
18 OnboardingStepSocial = 1
19 OnboardingStepKeys = 2
20 OnboardingStepRepo = 3
21 OnboardingStepDone = 4
22)
23
24type Onboarding struct {
25 Did string
26 Step int
27 Status OnboardingStatus
28 Created time.Time
29 Updated time.Time
30}
31
32// OnboardingProgress feeds the "resume onboarding" banner/panel. Active is false
33// when there is nothing to resume (no in-progress onboarding).
34type OnboardingProgress struct {
35 Active bool
36 Step int
37 Total int
38 Percent int
39}
40
41// Progress derives display progress for the resume banner/panel. It is nil-safe,
42// so callers can pass the result of GetOnboarding directly.
43func (o *Onboarding) Progress() OnboardingProgress {
44 if o == nil || o.Status != OnboardingInProgress {
45 return OnboardingProgress{}
46 }
47 total := OnboardingStepDone
48 percent := min(o.Step*100/total, 100)
49 return OnboardingProgress{
50 Active: true,
51 Step: o.Step,
52 Total: total,
53 Percent: percent,
54 }
55}