1
0
Fork 0
mirror of https://github.com/anyproto/anytype-heart.git synced 2025-06-08 05:47:07 +09:00

GO-5174 Add page widget to usecases

This commit is contained in:
kirillston 2025-02-28 17:13:26 +03:00 committed by Roman Khafizianov
parent 15c88aa939
commit 12949a14c6
No known key found for this signature in database
GPG key ID: F07A7D55A2684852

View file

@ -32,6 +32,7 @@ import (
"github.com/anyproto/anytype-heart/pb"
"github.com/anyproto/anytype-heart/pkg/lib/bundle"
"github.com/anyproto/anytype-heart/pkg/lib/core"
coresb "github.com/anyproto/anytype-heart/pkg/lib/core/smartblock"
"github.com/anyproto/anytype-heart/pkg/lib/database"
"github.com/anyproto/anytype-heart/pkg/lib/localstore/objectstore"
"github.com/anyproto/anytype-heart/pkg/lib/logging"
@ -77,19 +78,6 @@ var (
pb.RpcObjectImportUseCaseRequest_GET_STARTED: getStartedZip,
pb.RpcObjectImportUseCaseRequest_EMPTY: emptyZip,
}
// TODO: GO-2009 Now we need to create widgets by hands, widget import is not implemented yet
widgetParams = map[pb.RpcObjectImportUseCaseRequestUseCase][]widgetParameters{
pb.RpcObjectImportUseCaseRequest_EMPTY: {
{model.BlockContentWidget_Link, "bafyreic75ulgm2yz426hjwdjkzqw3kafniknki7qkhufqgrspmxzdppixa", "", true},
},
pb.RpcObjectImportUseCaseRequest_GET_STARTED: {
{model.BlockContentWidget_Link, "bafyreiccjf5vbijsmr55ypsnnzltmcvl4n63g73twwxqnfkn5usoq2iqyi", "", true},
{model.BlockContentWidget_View, "bafyreigigitlypzxjf2trrguj7ict7y6xu2r3qi6hc5eycp47pz66ghlpy", "all", true},
{model.BlockContentWidget_View, "bafyreihruv47l2cm3fh5rl7gou2s3re2dtd6iofjahogp7nockgsaomg5m", "all", true},
{model.BlockContentWidget_CompactList, widget.DefaultWidgetRecentOpen, "", false},
},
}
)
type BuiltinObjects interface {
@ -376,37 +364,28 @@ func (b *builtinObjects) createWidgets(ctx session.Context, spaceId string, useC
widgetObjectID := spc.DerivedIDs().Widgets
if err = cache.DoStateCtx(b.objectGetter, ctx, widgetObjectID, func(s *state.State, w widget.Widget) error {
for _, param := range widgetParams[useCase] {
objectID := param.objectID
if param.isObjectIDChanged {
objectID, err = b.getNewObjectID(spc.Id(), objectID)
if err != nil {
log.Errorf("Skipping creation of widget block as failed to get new object id using old one '%s': %v", objectID, err)
continue
}
}
request := &pb.RpcBlockCreateWidgetRequest{
ContextId: widgetObjectID,
Position: model.Block_Bottom,
WidgetLayout: param.layout,
Block: &model.Block{
Content: &model.BlockContentOfLink{
Link: &model.BlockContentLink{
TargetBlockId: objectID,
Style: model.BlockContentLink_Page,
IconSize: model.BlockContentLink_SizeNone,
CardStyle: model.BlockContentLink_Inline,
Description: model.BlockContentLink_None,
},
objectID, e := spc.DeriveObjectID(nil, domain.MustUniqueKey(coresb.SmartBlockTypeObjectType, bundle.TypeKeyPage.String()))
if e != nil {
return fmt.Errorf("failed to derive page type object id: %w", err)
}
request := &pb.RpcBlockCreateWidgetRequest{
ContextId: widgetObjectID,
Position: model.Block_Bottom,
WidgetLayout: model.BlockContentWidget_View,
Block: &model.Block{
Content: &model.BlockContentOfLink{
Link: &model.BlockContentLink{
TargetBlockId: objectID,
Style: model.BlockContentLink_Page,
IconSize: model.BlockContentLink_SizeNone,
CardStyle: model.BlockContentLink_Inline,
Description: model.BlockContentLink_None,
},
},
}
if param.viewID != "" {
request.ViewId = param.viewID
}
if _, err = w.CreateBlock(s, request); err != nil {
log.Errorf("Failed to make Widget blocks: %v", err)
}
},
}
if _, e = w.CreateBlock(s, request); err != nil {
return fmt.Errorf("failed to make Widget block: %v", e)
}
return nil
}); err != nil {