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 // Percent reflects completed steps out of the total, so the bar only fills
48 // as steps are finished (e.g. on the last step it is not yet 100%).
49 total := OnboardingStepDone
50 percent := o.Step * 100 / total
51 if percent > 100 {
52 percent = 100
53 }
54 return OnboardingProgress{
55 Active: true,
56 Step: o.Step,
57 Total: total,
58 Percent: percent,
59 }
60}