Skip to content

Commit d8e910a

Browse files
authored
chore: cleanup notification onboarding animations (#679)
1 parent 0a6a5f9 commit d8e910a

7 files changed

Lines changed: 59 additions & 197 deletions

File tree

Splajompy/Onboarding/OnboardingSheetViewModifier.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import SwiftUI
44
struct OnboardingSheetViewModifier: ViewModifier {
55
@AppStorage("image_layout_preference") private var imageLayoutPreference: ImageLayoutPreference =
66
.undecided
7+
@State private var stagedImageLayoutPreference: ImageLayoutPreference = .undecided
78

89
@AppStorage("hasCompletedPushNotificationOnboarding") private
910
var hasCompletedPushNotificationOnboarding: Bool = false
@@ -33,17 +34,21 @@ struct OnboardingSheetViewModifier: ViewModifier {
3334
onComplete: {
3435
if shouldShowNotificationsOnboarding {
3536
isNavigationToPushNotificationOnboarding = true
37+
} else {
38+
imageLayoutPreference = stagedImageLayoutPreference
3639
}
3740
},
38-
preference: $imageLayoutPreference
41+
preference: $stagedImageLayoutPreference
3942
)
4043
.postHogScreenView()
44+
.toolbar(.hidden, for: .navigationBar)
4145
.navigationDestination(
4246
isPresented: $isNavigationToPushNotificationOnboarding
4347
) {
4448
PushNotificationsOnboardingView(
4549
onComplete: {
4650
hasCompletedPushNotificationOnboarding = true
51+
imageLayoutPreference = stagedImageLayoutPreference
4752
}
4853
)
4954
.postHogScreenView()

Splajompy/Onboarding/PushNotificationsOnboardingView.swift

Lines changed: 51 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -28,64 +28,66 @@ struct PushNotificationsOnboardingView: View {
2828
.multilineTextAlignment(.center)
2929
.padding()
3030

31-
if !isPushNotificationsEnabled {
32-
Button {
33-
UNUserNotificationCenter.current().requestAuthorization(options: [
34-
.alert, .badge,
35-
]) {
36-
granted,
37-
error in
31+
VStack {
32+
if !isPushNotificationsEnabled {
33+
Button {
34+
UNUserNotificationCenter.current().requestAuthorization(options: [
35+
.alert, .badge,
36+
]) {
37+
granted,
38+
error in
3839

39-
if granted {
40-
Task { @MainActor in
41-
isPushNotificationsEnabled = true
42-
RemoteNotificationUtilities.registerForRemoteNotifications()
40+
if granted {
41+
Task { @MainActor in
42+
isPushNotificationsEnabled = true
43+
RemoteNotificationUtilities.registerForRemoteNotifications()
44+
}
45+
PostHogSDK.shared.register([
46+
"push_notifications_enabled": true
47+
])
48+
} else {
49+
PostHogSDK.shared.capture(
50+
"push_notifications_failed_registration"
51+
)
52+
Task { @MainActor in
53+
onComplete()
54+
}
4355
}
44-
PostHogSDK.shared.register([
45-
"push_notifications_enabled": true
46-
])
56+
}
57+
} label: {
58+
Text("Allow Notifications")
59+
.fontWeight(.semibold)
60+
}
61+
.controlSize(.large)
62+
.modify {
63+
if #available(iOS 26, *) {
64+
$0.buttonStyle(.glass)
4765
} else {
48-
PostHogSDK.shared.capture(
49-
"push_notifications_failed_registration"
50-
)
51-
Task { @MainActor in
52-
onComplete()
53-
}
66+
$0.buttonStyle(.bordered)
5467
}
5568
}
56-
} label: {
57-
Text("Allow Notifications")
58-
.fontWeight(.semibold)
59-
}
60-
.controlSize(.large)
61-
.modify {
62-
if #available(iOS 26, *) {
63-
$0.buttonStyle(.glass)
64-
} else {
65-
$0.buttonStyle(.bordered)
69+
.transition(.opacity)
70+
} else {
71+
VStack {
72+
Toggle("Mentions", isOn: $mentions)
73+
.onChange(of: mentions) {
74+
RemoteNotificationUtilities.registerForRemoteNotifications()
75+
}
76+
Toggle("Comments", isOn: $comments)
77+
.onChange(of: comments) {
78+
RemoteNotificationUtilities.registerForRemoteNotifications()
79+
}
80+
Toggle("Follows", isOn: $follows)
81+
.onChange(of: follows) {
82+
RemoteNotificationUtilities.registerForRemoteNotifications()
83+
}
6684
}
85+
.padding()
86+
.transition(.opacity)
6787
}
68-
.transition(.opacity)
69-
} else {
70-
Group {
71-
Toggle("Mentions", isOn: $mentions)
72-
.onChange(of: mentions) {
73-
RemoteNotificationUtilities.registerForRemoteNotifications()
74-
}
75-
Toggle("Comments", isOn: $comments)
76-
.onChange(of: comments) {
77-
RemoteNotificationUtilities.registerForRemoteNotifications()
78-
}
79-
Toggle("Follows", isOn: $follows)
80-
.onChange(of: follows) {
81-
RemoteNotificationUtilities.registerForRemoteNotifications()
82-
}
83-
}
84-
.padding()
85-
.transition(.opacity)
8688
}
89+
.animation(.default, value: isPushNotificationsEnabled)
8790
}
88-
.animation(.default, value: isPushNotificationsEnabled)
8991
.padding()
9092
}
9193
.safeAreaInset(edge: .bottom) {

Splajompy/Profile/ProfileRepository.swift

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,6 @@ protocol ProfileServiceProtocol: Sendable {
3030
>
3131
func requestFeature(text: String) async -> AsyncResult<EmptyResponse>
3232

33-
// func getFollowers(userId: Int, offset: Int, limit: Int) async -> AsyncResult<
34-
// [DetailedUser]
35-
// >
36-
3733
/// Fetch users that the given user is following.
3834
func getFollowing(userId: Int, limit: Int, before: Date?) async
3935
-> AsyncResult<PaginatedUserList>
@@ -152,19 +148,6 @@ struct ProfileService: ProfileServiceProtocol {
152148
)
153149
}
154150

155-
func getFollowers(userId: Int, offset: Int, limit: Int) async -> AsyncResult<
156-
[DetailedUser]
157-
> {
158-
let queryItems = [
159-
URLQueryItem(name: "offset", value: "\(offset)"),
160-
URLQueryItem(name: "limit", value: "\(limit)"),
161-
]
162-
return await APIService.performRequest(
163-
endpoint: "user/\(userId)/followers",
164-
queryItems: queryItems
165-
)
166-
}
167-
168151
func getFollowing(userId: Int, limit: Int, before: Date?) async
169152
-> AsyncResult<PaginatedUserList>
170153
{

api/internal/middleware/AppVersion.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"splajompy.com/api/v2/internal/utilities"
1010
)
1111

12-
const MinimumAppVersion = "v1.3.0"
12+
const MinimumAppVersion = "v1.7.0"
1313

1414
func AppVersion(next http.Handler) http.Handler {
1515
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {

api/internal/user/handler.go

Lines changed: 1 addition & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"encoding/json"
55
"errors"
66
"net/http"
7-
"strconv"
87

98
"splajompy.com/api/v2/internal/models"
109
"splajompy.com/api/v2/internal/utilities"
@@ -29,9 +28,8 @@ func (h *Handler) RegisterRoutes(_, withAuth func(string, func(http.ResponseWrit
2928

3029
// users
3130
withAuth("GET /user/{id}", h.GetUserById)
32-
withAuth("GET /user/{id}/followers", h.GetFollowersByUserId)
3331
withAuth("GET /v2/user/{id}/following", h.GetFollowingByUserId)
34-
withAuth("GET /v3/user/{id}/following", h.GetFollowingByUserIdV3)
32+
withAuth("GET /v3/user/{id}/following", h.GetFollowingByUserId)
3533
withAuth("GET /v2/user/{id}/mutuals", h.GetMutualsByUserId)
3634
withAuth("GET /v3/user/{id}/mutuals", h.GetMutualsByUserIdV3)
3735
withAuth("GET /users/notification/{id}", h.ListNotificationActors)
@@ -258,31 +256,6 @@ func (h *Handler) GetFollowingByUserId(w http.ResponseWriter, r *http.Request) {
258256
utilities.HandleSuccess(w, result.Users)
259257
}
260258

261-
// GetFollowingByUserIdV3 returns a paginated list of users the given user follows, with a cursor for the next page.
262-
func (h *Handler) GetFollowingByUserIdV3(w http.ResponseWriter, r *http.Request) {
263-
currentUser := utilities.GetAuthenticatedUser(r)
264-
265-
userId, err := utilities.GetIntPathParam(r, "id")
266-
if err != nil {
267-
utilities.HandleError(w, http.StatusBadRequest, "Missing user ID parameter")
268-
return
269-
}
270-
271-
limit, before, err := utilities.ParseTimeBasedPagination(r)
272-
if err != nil {
273-
utilities.HandleError(w, http.StatusBadRequest, "Unable to parse pagination parameters ('limit' and 'before'")
274-
return
275-
}
276-
277-
result, err := h.svc.GetFollowingByUserId(r.Context(), *currentUser, userId, limit, before)
278-
if err != nil {
279-
utilities.HandleError(w, http.StatusInternalServerError, "Something went wrong")
280-
return
281-
}
282-
283-
utilities.HandleSuccess(w, result)
284-
}
285-
286259
func (h *Handler) GetMutualsByUserId(w http.ResponseWriter, r *http.Request) {
287260
user := utilities.GetAuthenticatedUser(r)
288261

@@ -331,33 +304,6 @@ func (h *Handler) GetMutualsByUserIdV3(w http.ResponseWriter, r *http.Request) {
331304
utilities.HandleSuccess(w, result)
332305
}
333306

334-
// GetFollowersByUserId returns a list of users following the given user (offset-based pagination).
335-
func (h *Handler) GetFollowersByUserId(w http.ResponseWriter, r *http.Request) {
336-
currentUser := utilities.GetAuthenticatedUser(r)
337-
338-
userId, err := utilities.GetIntPathParam(r, "id")
339-
if err != nil {
340-
utilities.HandleError(w, http.StatusBadRequest, "Missing user ID parameter")
341-
return
342-
}
343-
344-
limit, offset := 10, 0
345-
if l, err := strconv.Atoi(r.URL.Query().Get("limit")); err == nil && l > 0 {
346-
limit = l
347-
}
348-
if o, err := strconv.Atoi(r.URL.Query().Get("offset")); err == nil && o >= 0 {
349-
offset = o
350-
}
351-
352-
followers, err := h.svc.GetFollowersByUserId_old(r.Context(), *currentUser, userId, offset, limit)
353-
if err != nil {
354-
utilities.HandleError(w, http.StatusInternalServerError, "Something went wrong")
355-
return
356-
}
357-
358-
utilities.HandleSuccess(w, followers)
359-
}
360-
361307
type RequestFeaturePayload struct {
362308
Text string
363309
}

api/internal/user/service.go

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -198,22 +198,6 @@ func (s *Service) RequestFeature(ctx context.Context, user models.PublicUser, te
198198
return err
199199
}
200200

201-
// GetFollowersByUserId_old retrieves users that are following the specified user.
202-
// Deprecated in favor of updated cursor based pagination in
203-
func (s *Service) GetFollowersByUserId_old(ctx context.Context, currentUser models.PublicUser, userId int, offset int, limit int) ([]models.DetailedUser, error) {
204-
followers, err := s.store.GetFollowersByUserId_old(ctx, userId, limit, offset)
205-
if err != nil {
206-
return nil, err
207-
}
208-
209-
userIDs := make([]int, len(followers))
210-
for i, follower := range followers {
211-
userIDs[i] = follower.UserID
212-
}
213-
214-
return s.fetchDetailedUsersFromIDs(ctx, currentUser.UserID, userIDs)
215-
}
216-
217201
func (s *Service) GetFollowingByUserId(ctx context.Context, user models.PublicUser, targetUserId int, limit int, before *time.Time) (*models.PaginatedUserList, error) {
218202
userIDs, cursor, err := s.store.GetFollowingUserIds(ctx, targetUserId, limit, before)
219203
if err != nil {
@@ -228,39 +212,6 @@ func (s *Service) GetFollowingByUserId(ctx context.Context, user models.PublicUs
228212
return &models.PaginatedUserList{Users: users, NextCursor: cursor}, nil
229213
}
230214

231-
// GetFollowingByUserId retrieves users that the specified user is following.
232-
// Deprecated Use GetFollowingByUserId instead
233-
func (s *Service) GetFollowingByUserId_old(ctx context.Context, currentUser models.PublicUser, userId int, offset int, limit int) ([]models.DetailedUser, error) {
234-
following, err := s.store.GetFollowingByUserId_old(ctx, userId, limit, offset)
235-
if err != nil {
236-
return nil, err
237-
}
238-
239-
userIDs := make([]int, len(following))
240-
for i, follow := range following {
241-
userIDs[i] = follow.UserID
242-
}
243-
244-
return s.fetchDetailedUsersFromIDs(ctx, currentUser.UserID, userIDs)
245-
}
246-
247-
// GetMutualsByUserId_old retrieves users that both the current user and the target user follow.
248-
//
249-
// Deprecated: prefer GetMutualsByUserId
250-
func (s *Service) GetMutualsByUserId_old(ctx context.Context, currentUser models.PublicUser, userId int, offset int, limit int) ([]models.DetailedUser, error) {
251-
mutuals, err := s.store.GetMutualsByUserId_old(ctx, currentUser.UserID, userId, limit, offset)
252-
if err != nil {
253-
return nil, err
254-
}
255-
256-
userIDs := make([]int, len(mutuals))
257-
for i, mutual := range mutuals {
258-
userIDs[i] = mutual.UserID
259-
}
260-
261-
return s.fetchDetailedUsersFromIDs(ctx, currentUser.UserID, userIDs)
262-
}
263-
264215
// GetMutualsByUserId returns users who are 'mutuals' with the current user and target user. That is, who follow both the current user and target user.
265216
func (s *Service) GetMutualsByUserId(ctx context.Context, user models.PublicUser, targetUserId int, limit int, before *time.Time) (*models.PaginatedUserList, error) {
266217
userIDs, cursor, err := s.store.GetMutualUserIds(ctx, user.UserID, targetUserId, limit, before)

api/internal/user/store.go

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -269,31 +269,6 @@ func (r Store) GetMutualConnectionsForUser(ctx context.Context, currentUserId in
269269
})
270270
}
271271

272-
func (r Store) GetFollowersByUserId_old(ctx context.Context, userId int, limit int, offset int) ([]queries.GetFollowersByUserIdRow, error) {
273-
return r.querier.GetFollowersByUserId(ctx, queries.GetFollowersByUserIdParams{
274-
FollowingID: userId,
275-
Limit: limit,
276-
Offset: offset,
277-
})
278-
}
279-
280-
func (r Store) GetFollowingByUserId_old(ctx context.Context, userId int, limit int, offset int) ([]queries.GetFollowingByUserIdRow, error) {
281-
return r.querier.GetFollowingByUserId(ctx, queries.GetFollowingByUserIdParams{
282-
FollowerID: userId,
283-
Limit: limit,
284-
Offset: offset,
285-
})
286-
}
287-
288-
func (r Store) GetMutualsByUserId_old(ctx context.Context, currentUserId int, targetUserId int, limit int, offset int) ([]queries.GetMutualsByUserIdRow, error) {
289-
return r.querier.GetMutualsByUserId(ctx, queries.GetMutualsByUserIdParams{
290-
FollowerID: currentUserId,
291-
FollowerID_2: targetUserId,
292-
Limit: limit,
293-
Offset: offset,
294-
})
295-
}
296-
297272
func (r Store) GetFollowingUserIds(ctx context.Context, userId int, limit int, before *time.Time) ([]int, *time.Time, error) {
298273
rows, err := r.querier.GetFollowingUserIds(ctx, queries.GetFollowingUserIdsParams{
299274
UserID: userId,

0 commit comments

Comments
 (0)