Skip to content

Commit a50859f

Browse files
authored
Merge pull request #2908 from anyproto/ios-4049-update-lastuseddate-for-types-and-relations
IOS-4049 Support lastUsedDate sort for types in type picker
2 parents 4edab86 + b791d92 commit a50859f

File tree

6 files changed

+51
-26
lines changed

6 files changed

+51
-26
lines changed

Anytype/Sources/Models/Extensions/ObjectType+Extensions.swift

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ extension ObjectType {
2525
recommendedRelations: [],
2626
recommendedFeaturedRelations: [],
2727
recommendedHiddenRelations: [],
28-
recommendedLayout: nil
28+
recommendedLayout: nil,
29+
lastUsedDate: .distantPast
2930
)
3031

3132
var setIsTemplatesAvailable: Bool {

Anytype/Sources/PresentationLayer/Modules/HomeNavigationContainer/Panel/HomeBottomNavigationPanelViewModel.swift

+7-1
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ final class HomeBottomNavigationPanelViewModel: ObservableObject {
129129

130130
AnytypeAnalytics.instance().logCreateObject(objectType: details.analyticsType, spaceId: details.spaceId, route: .navigation)
131131

132+
try? await objectActionsService.updateBundledDetails(contextID: type.id, details: [ .lastUsedDate(Date.now)])
133+
132134
output?.onCreateObjectSelected(screenData: details.screenData())
133135
}
134136
}
@@ -153,7 +155,11 @@ final class HomeBottomNavigationPanelViewModel: ObservableObject {
153155
.filter { Constants.favoriteTypesUniqueKeys.contains($0.uniqueKey) }
154156
.reordered(by: Constants.favoriteTypesUniqueKeys.map(\.value), transform: \.uniqueKey.value)
155157

156-
otherObjectTypes = types.filter { !Constants.favoriteTypesUniqueKeys.contains($0.uniqueKey) }
158+
otherObjectTypes = types
159+
.filter { !Constants.favoriteTypesUniqueKeys.contains($0.uniqueKey) }
160+
.sorted {
161+
$0.lastUsedDate ?? .distantPast > $1.lastUsedDate ?? .distantPast
162+
}
157163
}
158164
}
159165

Anytype/Sources/ServiceLayer/Object/TypeProvider/ObjectTypeProvider.swift

+2-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ final class ObjectTypeProvider: ObjectTypeProviderProtocol, Sendable {
116116
recommendedRelations: [],
117117
recommendedFeaturedRelations: [],
118118
recommendedHiddenRelations: [],
119-
recommendedLayout: nil
119+
recommendedLayout: nil,
120+
lastUsedDate: .distantPast
120121
)
121122
}
122123

Modules/AnytypeCore/AnytypeCore/Extensions/ProtobufExtensions.swift

+7
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ public extension Bool {
2525
}
2626
}
2727

28+
public extension Date {
29+
var protobufValue: Google_Protobuf_Value {
30+
// Cast to int to remove decimal part for middleware
31+
Google_Protobuf_Value(integerLiteral: Int64(timeIntervalSince1970))
32+
}
33+
}
34+
2835
public extension Array where Element == String {
2936
var protobufValue: Google_Protobuf_Value {
3037
Google_Protobuf_Value(

Modules/Services/Sources/Models/Details/BundledDetails.swift

+23-20
Original file line numberDiff line numberDiff line change
@@ -14,37 +14,40 @@ public enum BundledDetails: Sendable {
1414
case done(Bool)
1515
case description(String)
1616
case recommendedLayout(Int)
17+
case lastUsedDate(Date)
1718
}
1819

1920
extension BundledDetails {
2021

2122
var key: String {
2223
switch self {
23-
case .name: return BundledRelationKey.name.rawValue
24-
case .iconEmoji: return BundledRelationKey.iconEmoji.rawValue
25-
case .iconObjectId: return BundledRelationKey.iconImage.rawValue
26-
case .iconName: return BundledRelationKey.iconName.rawValue
27-
case .iconOption: return BundledRelationKey.iconOption.rawValue
28-
case .coverId: return BundledRelationKey.coverId.rawValue
29-
case .coverType: return BundledRelationKey.coverType.rawValue
30-
case .done: return BundledRelationKey.done.rawValue
31-
case .description: return BundledRelationKey.description.rawValue
32-
case .recommendedLayout: return BundledRelationKey.recommendedLayout.rawValue
24+
case .name: BundledRelationKey.name.rawValue
25+
case .iconEmoji: BundledRelationKey.iconEmoji.rawValue
26+
case .iconObjectId: BundledRelationKey.iconImage.rawValue
27+
case .iconName: BundledRelationKey.iconName.rawValue
28+
case .iconOption: BundledRelationKey.iconOption.rawValue
29+
case .coverId: BundledRelationKey.coverId.rawValue
30+
case .coverType: BundledRelationKey.coverType.rawValue
31+
case .done: BundledRelationKey.done.rawValue
32+
case .description: BundledRelationKey.description.rawValue
33+
case .recommendedLayout: BundledRelationKey.recommendedLayout.rawValue
34+
case .lastUsedDate: BundledRelationKey.lastUsedDate.rawValue
3335
}
3436
}
3537

3638
var value: Google_Protobuf_Value {
3739
switch self {
38-
case .name(let string): return string.protobufValue
39-
case .iconEmoji(let string): return string.protobufValue
40-
case .iconObjectId(let string): return string.protobufValue
41-
case .iconName(let string): return string.protobufValue
42-
case .iconOption(let int): return int.protobufValue
43-
case .coverId(let string): return string.protobufValue
44-
case .coverType(let coverType): return coverType.rawValue.protobufValue
45-
case .done(let bool): return bool.protobufValue
46-
case .description(let string): return string.protobufValue
47-
case .recommendedLayout(let layout): return layout.protobufValue
40+
case .name(let string): string.protobufValue
41+
case .iconEmoji(let string): string.protobufValue
42+
case .iconObjectId(let string): string.protobufValue
43+
case .iconName(let string): string.protobufValue
44+
case .iconOption(let int): int.protobufValue
45+
case .coverId(let string): string.protobufValue
46+
case .coverType(let coverType): coverType.rawValue.protobufValue
47+
case .done(let bool): bool.protobufValue
48+
case .description(let string): string.protobufValue
49+
case .recommendedLayout(let layout): layout.protobufValue
50+
case .lastUsedDate(let date): date.protobufValue
4851
}
4952
}
5053

Modules/Services/Sources/Models/ObjectType.swift

+10-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import ProtobufMessages
22
import AnytypeCore
3+
import Foundation
34

45

56
public struct ObjectType: Equatable, Hashable, Codable, Identifiable, Sendable {
@@ -24,6 +25,8 @@ public struct ObjectType: Equatable, Hashable, Codable, Identifiable, Sendable {
2425
public let recommendedHiddenRelations: [ObjectId]
2526
public let recommendedLayout: DetailsLayout?
2627

28+
public let lastUsedDate: Date?
29+
2730
public init(
2831
id: String,
2932
name: String,
@@ -42,7 +45,8 @@ public struct ObjectType: Equatable, Hashable, Codable, Identifiable, Sendable {
4245
recommendedRelations: [ObjectId],
4346
recommendedFeaturedRelations: [ObjectId],
4447
recommendedHiddenRelations: [ObjectId],
45-
recommendedLayout: DetailsLayout?
48+
recommendedLayout: DetailsLayout?,
49+
lastUsedDate: Date?
4650
) {
4751
self.id = id
4852
self.name = name
@@ -62,6 +66,7 @@ public struct ObjectType: Equatable, Hashable, Codable, Identifiable, Sendable {
6266
self.recommendedFeaturedRelations = recommendedFeaturedRelations
6367
self.recommendedHiddenRelations = recommendedHiddenRelations
6468
self.recommendedLayout = recommendedLayout
69+
self.lastUsedDate = lastUsedDate
6570
}
6671
}
6772

@@ -86,7 +91,8 @@ extension ObjectType: DetailsModel {
8691
recommendedRelations: details.recommendedRelations,
8792
recommendedFeaturedRelations: details.recommendedFeaturedRelations,
8893
recommendedHiddenRelations: details.recommendedHiddenRelations,
89-
recommendedLayout: details.recommendedLayoutValue
94+
recommendedLayout: details.recommendedLayoutValue,
95+
lastUsedDate: details.lastUsedDate
9096
)
9197
}
9298

@@ -114,7 +120,8 @@ extension ObjectType: DetailsModel {
114120
BundledRelationKey.defaultTemplateId,
115121
BundledRelationKey.restrictions,
116122
BundledRelationKey.resolvedLayout,
117-
BundledRelationKey.type
123+
BundledRelationKey.type,
124+
BundledRelationKey.lastUsedDate
118125
]
119126
}
120127

0 commit comments

Comments
 (0)