Repository: Automattic/pocket-casts-ios
File: podcasts/New Creation/New Playlist/NewPlaylistViewController.swift (Swift)

Code before:

            Analytics.track(.filterCreated)
            Analytics.track(.filterCreateAsManualPlaylistTapped)

            if Settings.firstTimePlaylistCreated {
                Settings.shouldShowDragAndDropTip = true
            }

            // Dismiss all presented view controllers and show snackbar with navigation action
            if let rootVC = SceneHelper.rootViewController(includeTopMost: false) {
                rootVC.dismiss(animated: true) {
                    Toast.show(L10n.playlistEpisodesAddedToSinglePlaylist(playlist.playlistName), actions: [
                        .init(title: L10n.bookmarkAddedButtonTitle) {
                            NavigationManager.sharedManager.navigateTo(
                                NavigationManager.filterPageKey,
                                data: [
                                    NavigationManager.filterUuidKey: playlist.uuid
                                ]
                            )
                        }
                    ])
                }
            }
            return
        } else if case let .addEpisodes(episodes) = creationType {
            if episodes.count > 1000 {
                Toast.show(L10n.playlistManualAddTooManyEpisodesToast)
                return
            }
            let didAdd = DataManager.sharedManager.add(episodes: episodes, to: playlist)
            guard didAdd else {
                let theme: any ToastTheme = ToastIconTheme(iconName: "option-alert", iconColor: Theme.sharedTheme.primaryIcon01)
                Toast.show(L10n.playlistManualCreateErrorMessage, theme: theme)
                return
            }

            Analytics.track(.addToPlaylistsCreateNewPlaylistTapped, properties: ["source": analyticsSource ?? "unknown"])

            NotificationCenter.postOnMainThread(notification: Constants.Notifications.playlistChanged, object: playlist)

            Analytics.track(.filterCreated)
            Analytics.track(.filterCreateAsManualPlaylistTapped)

            if Settings.firstTimePlaylistCreated {
                Settings.shouldShowDragAndDropTip = true
            }

            // Dismiss all presented view controllers and show snackbar with navigation action
            if let rootVC = SceneHelper.rootViewController(includeTopMost: false) {
                rootVC.dismiss(animated: true) {
                    Toast.show(L10n.playlistEpisodesAddedToSinglePlaylist(playlist.playlistName), actions: [

Review comment (suggestion):
The `1000` should be a constant defined in the system that we could refer when checking for this limit.

Code after:

            Analytics.track(.filterCreated)
            Analytics.track(.filterCreateAsManualPlaylistTapped)

            if Settings.firstTimePlaylistCreated {
                Settings.shouldShowDragAndDropTip = true
            }

            // Dismiss all presented view controllers and show snackbar with navigation action
            if let rootVC = SceneHelper.rootViewController(includeTopMost: false) {
                rootVC.dismiss(animated: true) {
                    Toast.show(L10n.playlistEpisodesAddedToSinglePlaylist(playlist.playlistName), actions: [
                        .init(title: L10n.bookmarkAddedButtonTitle) {
                            NavigationManager.sharedManager.navigateTo(
                                NavigationManager.filterPageKey,
                                data: [
                                    NavigationManager.filterUuidKey: playlist.uuid
                                ]
                            )
                        }
                    ])
                }
            }
            return
        } else if case let .addEpisodes(episodes) = creationType {
            let maxPlaylistItems = Constants.Limits.maxFilterItems
            if episodes.count > maxPlaylistItems {
                Toast.show(L10n.playlistManualAddTooManyEpisodesToast(maxPlaylistItems.localized(.decimal)))
                return
            }
            let didAdd = DataManager.sharedManager.add(episodes: episodes, to: playlist)
            guard didAdd else {
                let theme: any ToastTheme = ToastIconTheme(iconName: "option-alert", iconColor: Theme.sharedTheme.primaryIcon01)
                Toast.show(L10n.playlistManualCreateErrorMessage, theme: theme)
                return
            }

            Analytics.track(.addToPlaylistsCreateNewPlaylistTapped, properties: ["source": analyticsSource ?? "unknown"])

            NotificationCenter.postOnMainThread(notification: Constants.Notifications.playlistChanged, object: playlist)

            Analytics.track(.filterCreated)
            Analytics.track(.filterCreateAsManualPlaylistTapped)

            if Settings.firstTimePlaylistCreated {
                Settings.shouldShowDragAndDropTip = true
            }

            // Dismiss all presented view controllers and show snackbar with navigation action
            if let rootVC = SceneHelper.rootViewController(includeTopMost: false) {
                rootVC.dismiss(animated: true) {