Skip to content

Commit

Permalink
Added updated time display (#678)
Browse files Browse the repository at this point in the history
  • Loading branch information
EricBAndrews authored Sep 30, 2023
1 parent 238dac3 commit b0c0d41
Show file tree
Hide file tree
Showing 18 changed files with 91 additions and 39 deletions.
16 changes: 10 additions & 6 deletions Mlem.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
03A1B3F72A84000400AB0DE0 /* APIContentAggregatesProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03A1B3F62A84000400AB0DE0 /* APIContentAggregatesProtocol.swift */; };
03A1B3F92A8400DD00AB0DE0 /* APIContentViewProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03A1B3F82A8400DD00AB0DE0 /* APIContentViewProtocol.swift */; };
03B643572A6864CD00F65700 /* TabBarSettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03B643562A6864CD00F65700 /* TabBarSettingsView.swift */; };
03BAA23A2A57DC1400D48252 /* TimestampView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03BAA2392A57DC1400D48252 /* TimestampView.swift */; };
03BAA23A2A57DC1400D48252 /* PublishedTimestampView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03BAA2392A57DC1400D48252 /* PublishedTimestampView.swift */; };
03CB329E2A6D8E910021EF27 /* PostDetailEditorView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03CB329D2A6D8E910021EF27 /* PostDetailEditorView.swift */; };
03E0B9C82A61F0F400FED265 /* AdvancedSettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03E0B9C72A61F0F400FED265 /* AdvancedSettingsView.swift */; };
03E0B9CA2A62B4A400FED265 /* ContributorsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03E0B9C92A62B4A400FED265 /* ContributorsView.swift */; };
Expand Down Expand Up @@ -300,6 +300,7 @@
CD18DC6B2A5202D4002C56BC /* MarkPersonMentionAsReadRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD18DC6A2A5202D4002C56BC /* MarkPersonMentionAsReadRequest.swift */; };
CD18DC6F2A5209C3002C56BC /* MarkPrivateMessageAsReadRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD18DC6E2A5209C3002C56BC /* MarkPrivateMessageAsReadRequest.swift */; };
CD18DC732A522A7C002C56BC /* CreatePrivateMessageRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD18DC722A522A7C002C56BC /* CreatePrivateMessageRequest.swift */; };
CD2053102AC878B50000AA38 /* UpdatedTimestampView.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD20530F2AC878B50000AA38 /* UpdatedTimestampView.swift */; };
CD2BD6782A79F55800ECFF89 /* ImageSize.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD2BD6772A79F55800ECFF89 /* ImageSize.swift */; };
CD2E182B2A3B708500224F8A /* Settings Options.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD2E182A2A3B708500224F8A /* Settings Options.swift */; };
CD309C462A93FBD300988F95 /* Logo View.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD309C452A93FBD300988F95 /* Logo View.swift */; };
Expand Down Expand Up @@ -436,8 +437,8 @@
E4D4DBA22A7F233200C4F3DE /* FancyTabNavigationSelectionHashValueEnvironmentKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = E4D4DBA12A7F233200C4F3DE /* FancyTabNavigationSelectionHashValueEnvironmentKey.swift */; };
E4DDB4322A81819300B3A7E0 /* Double.swift in Sources */ = {isa = PBXBuildFile; fileRef = E4DDB4312A81819300B3A7E0 /* Double.swift */; };
E4DDB4342A819C8000B3A7E0 /* QuickLookView.swift in Sources */ = {isa = PBXBuildFile; fileRef = E4DDB4332A819C8000B3A7E0 /* QuickLookView.swift */; };
E4F0B5722AC2581800BC3E4A /* RoutableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = E4F0B5712AC2581800BC3E4A /* RoutableTests.swift */; };
E4F0B56F2ABD00A000BC3E4A /* PresentationBackgroundInteraction.swift in Sources */ = {isa = PBXBuildFile; fileRef = E4F0B56E2ABD00A000BC3E4A /* PresentationBackgroundInteraction.swift */; };
E4F0B5722AC2581800BC3E4A /* RoutableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = E4F0B5712AC2581800BC3E4A /* RoutableTests.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -481,7 +482,7 @@
03A1B3F62A84000400AB0DE0 /* APIContentAggregatesProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = APIContentAggregatesProtocol.swift; sourceTree = "<group>"; };
03A1B3F82A8400DD00AB0DE0 /* APIContentViewProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = APIContentViewProtocol.swift; sourceTree = "<group>"; };
03B643562A6864CD00F65700 /* TabBarSettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TabBarSettingsView.swift; sourceTree = "<group>"; };
03BAA2392A57DC1400D48252 /* TimestampView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TimestampView.swift; sourceTree = "<group>"; };
03BAA2392A57DC1400D48252 /* PublishedTimestampView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PublishedTimestampView.swift; sourceTree = "<group>"; };
03CB329D2A6D8E910021EF27 /* PostDetailEditorView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PostDetailEditorView.swift; sourceTree = "<group>"; };
03E0B9C72A61F0F400FED265 /* AdvancedSettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AdvancedSettingsView.swift; sourceTree = "<group>"; };
03E0B9C92A62B4A400FED265 /* ContributorsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContributorsView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -749,6 +750,7 @@
CD18DC6A2A5202D4002C56BC /* MarkPersonMentionAsReadRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MarkPersonMentionAsReadRequest.swift; sourceTree = "<group>"; };
CD18DC6E2A5209C3002C56BC /* MarkPrivateMessageAsReadRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MarkPrivateMessageAsReadRequest.swift; sourceTree = "<group>"; };
CD18DC722A522A7C002C56BC /* CreatePrivateMessageRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CreatePrivateMessageRequest.swift; sourceTree = "<group>"; };
CD20530F2AC878B50000AA38 /* UpdatedTimestampView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UpdatedTimestampView.swift; sourceTree = "<group>"; };
CD2BD6772A79F55800ECFF89 /* ImageSize.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageSize.swift; sourceTree = "<group>"; };
CD2E182A2A3B708500224F8A /* Settings Options.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Settings Options.swift"; sourceTree = "<group>"; };
CD309C452A93FBD300988F95 /* Logo View.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Logo View.swift"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -885,8 +887,8 @@
E4D4DBA12A7F233200C4F3DE /* FancyTabNavigationSelectionHashValueEnvironmentKey.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FancyTabNavigationSelectionHashValueEnvironmentKey.swift; sourceTree = "<group>"; };
E4DDB4312A81819300B3A7E0 /* Double.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Double.swift; sourceTree = "<group>"; };
E4DDB4332A819C8000B3A7E0 /* QuickLookView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QuickLookView.swift; sourceTree = "<group>"; };
E4F0B5712AC2581800BC3E4A /* RoutableTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RoutableTests.swift; sourceTree = "<group>"; };
E4F0B56E2ABD00A000BC3E4A /* PresentationBackgroundInteraction.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PresentationBackgroundInteraction.swift; sourceTree = "<group>"; };
E4F0B5712AC2581800BC3E4A /* RoutableTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RoutableTests.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -1791,11 +1793,12 @@
6322A5CA27F77A4D00135D4F /* Loading View.swift */,
6386E03F2A045723006B3C1D /* Website Icon Complex.swift */,
63D24EDD2A169F2A005CCA81 /* Markdown View.swift */,
03BAA2392A57DC1400D48252 /* TimestampView.swift */,
03BAA2392A57DC1400D48252 /* PublishedTimestampView.swift */,
6374570F2A18CB6600B69C03 /* Custom Text Field.swift */,
B11D72822A49FAA7009DC22F /* Cached Image.swift */,
50F2851B2A5C5C1500CF8865 /* TokenRefreshView.swift */,
CD863FBB2A6B026400A31ED9 /* DocumentView.swift */,
CD20530F2AC878B50000AA38 /* UpdatedTimestampView.swift */,
);
path = Shared;
sourceTree = "<group>";
Expand Down Expand Up @@ -2595,6 +2598,7 @@
CDF1EF142A6B6D6E003594B6 /* Feed View Logic.swift in Sources */,
6DFF50432A48DED3001E648D /* Inbox View.swift in Sources */,
CDF8426F2A4A385A00723DA0 /* Inbox Item Type.swift in Sources */,
CD2053102AC878B50000AA38 /* UpdatedTimestampView.swift in Sources */,
CD1446232A5B336900610EF1 /* LicensesView.swift in Sources */,
CDDCF6432A66343D003DA3AC /* FancyTabBar.swift in Sources */,
505240E52A86E32700EA4558 /* CommunityListModel.swift in Sources */,
Expand Down Expand Up @@ -2727,7 +2731,7 @@
CD9DD8852A62302A0044EA8E /* ConcreteEditorModel.swift in Sources */,
CD4E98A32A69BEDC0026C4D9 /* IconSettingsView.swift in Sources */,
637218692A3A2AAD008C4816 /* CreateCommentLike.swift in Sources */,
03BAA23A2A57DC1400D48252 /* TimestampView.swift in Sources */,
03BAA23A2A57DC1400D48252 /* PublishedTimestampView.swift in Sources */,
B157E0C42A507B8000B02C8B /* Window.swift in Sources */,
6372185A2A3A2AAD008C4816 /* APISubscribedStatus.swift in Sources */,
CDDCF6452A66375E003DA3AC /* FancyTabItemViewModifier.swift in Sources */,
Expand Down
4 changes: 3 additions & 1 deletion Mlem/Icons.swift
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ struct Icons {
static let noContent: String = "binoculars"
static let noPosts: String = "text.bubble"
static let time: String = "clock"
static let updated: String = "clock.arrow.2.circlepath"
static let favorite: String = "star"
static let favoriteFill: String = "star.fill"

Expand All @@ -136,6 +137,8 @@ struct Icons {
static let filterFill: String = "line.3.horizontal.decrease.circle.fill"
static let menu: String = "ellipsis"
static let importSymbol: String = "square.and.arrow.down" // Just "import" can't be used :(
static let edit: String = "pencil"
static let delete: String = "trash"

// settings
static let upvoteOnSave: String = "arrow.up.heart"
Expand Down Expand Up @@ -170,6 +173,5 @@ struct Icons {
static let emptySquare: String = "square"
static let dropdown: String = "chevron.down"
static let noFile: String = "questionmark.folder"
static let delete: String = "trash"
static let forward: String = "chevron.right"
}
6 changes: 5 additions & 1 deletion Mlem/Models/Content/Post Model.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ struct PostModel {
let saved: Bool
let read: Bool
let published: Date
let updated: Date?

var uid: ContentModelIdentifier { .init(contentType: .post, contentId: postId) }

Expand All @@ -34,6 +35,7 @@ struct PostModel {
self.saved = apiPostView.saved
self.read = apiPostView.read
self.published = apiPostView.published
self.updated = apiPostView.post.updated
}

/// Creates a PostModel from another PostModel. Any provided field values will override values in post.
Expand All @@ -58,7 +60,8 @@ struct PostModel {
numReplies: Int? = nil,
saved: Bool? = nil,
read: Bool? = nil,
published: Date? = nil
published: Date? = nil,
updated: Date? = nil
) {
self.postId = postId ?? other.postId
self.post = post ?? other.post
Expand All @@ -69,6 +72,7 @@ struct PostModel {
self.saved = saved ?? other.saved
self.read = read ?? other.read
self.published = published ?? other.published
self.updated = updated ?? other.updated
}

var postType: PostType {
Expand Down
2 changes: 1 addition & 1 deletion Mlem/Views/Shared/Accounts/Accounts Page.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ struct AccountsPage: View {
Button(role: .destructive) {
accountForDeletion = account
} label: {
Label("Delete Current Account", systemImage: "trash")
Label("Delete Current Account", systemImage: Icons.delete)
.foregroundColor(.red)
}
}
Expand Down
18 changes: 10 additions & 8 deletions Mlem/Views/Shared/Comments/Comment Item Logic.swift
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@ extension CommentItem {

// upvote
let (upvoteText, upvoteImg) = hierarchicalComment.commentView.myVote == .upvote ?
("Undo upvote", "arrow.up.square.fill") :
("Upvote", "arrow.up.square")
("Undo upvote", Icons.upvoteSquareFill) :
("Upvote", Icons.upvoteSquare)
ret.append(MenuFunction.standardMenuFunction(
text: upvoteText,
imageName: upvoteImg,
Expand All @@ -162,8 +162,8 @@ extension CommentItem {

// downvote
let (downvoteText, downvoteImg) = hierarchicalComment.commentView.myVote == .downvote ?
("Undo downvote", "arrow.down.square.fill") :
("Downvote", "arrow.down.square")
("Undo downvote", Icons.downvoteSquareFill) :
("Downvote", Icons.downvoteSquare)
ret.append(MenuFunction.standardMenuFunction(
text: downvoteText,
imageName: downvoteImg,
Expand All @@ -176,7 +176,9 @@ extension CommentItem {
})

// save
let (saveText, saveImg) = hierarchicalComment.commentView.saved ? ("Unsave", "bookmark.slash") : ("Save", "bookmark")
let (saveText, saveImg) = hierarchicalComment.commentView.saved ?
("Unsave", Icons.unsave) :
("Save", Icons.save)
ret.append(MenuFunction.standardMenuFunction(
text: saveText,
imageName: saveImg,
Expand All @@ -191,7 +193,7 @@ extension CommentItem {
// reply
ret.append(MenuFunction.standardMenuFunction(
text: "Reply",
imageName: "arrowshape.turn.up.left",
imageName: Icons.reply,
destructiveActionPrompt: nil,
enabled: true
) {
Expand All @@ -202,7 +204,7 @@ extension CommentItem {
if appState.isCurrentAccountId(hierarchicalComment.commentView.creator.id) {
ret.append(MenuFunction.standardMenuFunction(
text: "Edit",
imageName: "pencil",
imageName: Icons.edit,
destructiveActionPrompt: nil,
enabled: true
) {
Expand All @@ -214,7 +216,7 @@ extension CommentItem {
if appState.isCurrentAccountId(hierarchicalComment.commentView.creator.id) {
ret.append(MenuFunction.standardMenuFunction(
text: "Delete",
imageName: "trash",
imageName: Icons.delete,
destructiveActionPrompt: "Are you sure you want to delete this comment? This cannot be undone.",
enabled: !hierarchicalComment.commentView.comment.deleted
) {
Expand Down
1 change: 1 addition & 0 deletions Mlem/Views/Shared/Comments/Comment Item.swift
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ struct CommentItem: View {
InteractionBarView(
votes: VotesModel(from: hierarchicalComment.commentView.counts, myVote: hierarchicalComment.commentView.myVote),
published: hierarchicalComment.commentView.comment.published,
updated: hierarchicalComment.commentView.comment.updated,
numReplies: hierarchicalComment.commentView.counts.childCount,
saved: hierarchicalComment.commentView.saved,
accessibilityContext: "comment",
Expand Down
6 changes: 5 additions & 1 deletion Mlem/Views/Shared/Comments/Components/CommentBodyView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,11 @@ struct CommentBodyView: View {
func compactScoreDisplay() -> some View {
Group {
// time
TimestampView(date: commentView.comment.published)
if let updated = commentView.comment.updated {
UpdatedTimestampView(date: updated, spacing: AppConstants.iconToTextSpacing)
} else {
PublishedTimestampView(date: commentView.comment.published)
}

// votes
if showCommentDownvotesSeparately {
Expand Down
7 changes: 5 additions & 2 deletions Mlem/Views/Shared/Components/Components/InfoStackView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ struct DetailedVotes {
struct InfoStackView: View {
let votes: DetailedVotes?
let published: Date?
let updated: Date?
let commentCount: Int?
let saved: Bool?
let alignment: HorizontalAlignment
Expand All @@ -38,8 +39,10 @@ struct InfoStackView: View {
}
}

if let published {
TimestampView(date: published, spacing: AppConstants.iconToTextSpacing)
if let updated {
UpdatedTimestampView(date: updated, spacing: AppConstants.iconToTextSpacing)
} else if let published {
PublishedTimestampView(date: published, spacing: AppConstants.iconToTextSpacing)
}

if let saved {
Expand Down
2 changes: 2 additions & 0 deletions Mlem/Views/Shared/Components/InteractionBarView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ struct InteractionBarView: View {
// metadata
let votes: VotesModel
let published: Date
let updated: Date?
let numReplies: Int
let saved: Bool

Expand Down Expand Up @@ -109,6 +110,7 @@ struct InteractionBarView: View {
)
: nil,
published: shouldShowTime ? published : nil,
updated: shouldShowTime ? updated : nil,
commentCount: shouldShowReplies ? numReplies : nil,
saved: shouldShowSaved ? saved : nil,
alignment: infoStackAlignment(offset)
Expand Down
2 changes: 2 additions & 0 deletions Mlem/Views/Shared/Posts/Expanded Post.swift
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ struct ExpandedPost: View {
InteractionBarView(
votes: post.votes,
published: post.published,
updated: post.updated,
numReplies: post.numReplies,
saved: post.saved,
accessibilityContext: "post",
Expand Down Expand Up @@ -317,4 +318,5 @@ struct ExpandedPost: View {
}
}
}

// swiftlint:enable type_body_length
18 changes: 10 additions & 8 deletions Mlem/Views/Shared/Posts/ExpandedPostLogic.swift
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ extension ExpandedPost {

// upvote
let (upvoteText, upvoteImg) = post.votes.myVote == .upvote ?
("Undo upvote", "arrow.up.square.fill") :
("Upvote", "arrow.up.square")
("Undo upvote", Icons.upvoteSquareFill) :
("Upvote", Icons.upvoteSquare)
ret.append(MenuFunction.standardMenuFunction(
text: upvoteText,
imageName: upvoteImg,
Expand All @@ -111,8 +111,8 @@ extension ExpandedPost {

// downvote
let (downvoteText, downvoteImg) = post.votes.myVote == .downvote ?
("Undo downvote", "arrow.down.square.fill") :
("Downvote", "arrow.down.square")
("Undo downvote", Icons.downvoteSquareFill) :
("Downvote", Icons.downvoteSquare)
ret.append(MenuFunction.standardMenuFunction(
text: downvoteText,
imageName: downvoteImg,
Expand All @@ -125,7 +125,9 @@ extension ExpandedPost {
})

// save
let (saveText, saveImg) = post.saved ? ("Unsave", "bookmark.slash") : ("Save", "bookmark")
let (saveText, saveImg) = post.saved ?
("Unsave", Icons.unsave) :
("Save", Icons.save)
ret.append(MenuFunction.standardMenuFunction(
text: saveText,
imageName: saveImg,
Expand All @@ -140,7 +142,7 @@ extension ExpandedPost {
// reply
ret.append(MenuFunction.standardMenuFunction(
text: "Reply",
imageName: "arrowshape.turn.up.left",
imageName: Icons.reply,
destructiveActionPrompt: nil,
enabled: true
) {
Expand All @@ -151,7 +153,7 @@ extension ExpandedPost {
// edit
ret.append(MenuFunction.standardMenuFunction(
text: "Edit",
imageName: "pencil",
imageName: Icons.edit,
destructiveActionPrompt: nil,
enabled: true
) {
Expand All @@ -166,7 +168,7 @@ extension ExpandedPost {
// delete
ret.append(MenuFunction.standardMenuFunction(
text: "Delete",
imageName: "trash",
imageName: Icons.delete,
destructiveActionPrompt: "Are you sure you want to delete this post? This cannot be undone.",
enabled: !post.post.deleted
) {
Expand Down
Loading

0 comments on commit b0c0d41

Please sign in to comment.