package web import "context" // FolderOption is a flattened, indented folder choice for . func (a *App) folderOptions(ctx context.Context) ([]FolderOption, error) { all, err := a.Folders.All(ctx) if err != nil { return nil, err } byParent := map[int64][]struct { ID int64 Name string }{} var top []struct { ID int64 Name string } for _, f := range all { item := struct { ID int64 Name string }{f.ID, f.Name} if f.ParentID == nil { top = append(top, item) } else { byParent[*f.ParentID] = append(byParent[*f.ParentID], item) } } var out []FolderOption var walk func(id int64, name, prefix string, depth int) walk = func(id int64, name, prefix string, depth int) { path := name if prefix != "" { path = prefix + " / " + name } out = append(out, FolderOption{ID: id, Path: path, Depth: depth}) for _, child := range byParent[id] { walk(child.ID, child.Name, path, depth+1) } } for _, t := range top { walk(t.ID, t.Name, "", 0) } return out, nil }