Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sign Up Prompts #1356

Merged
merged 4 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Mlem.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@
03531EF12C2DA298004A3464 /* SearchResultsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03531EF02C2DA298004A3464 /* SearchResultsView.swift */; };
03531EF52C2DA610004A3464 /* NavigationSearchType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03531EF42C2DA610004A3464 /* NavigationSearchType.swift */; };
035394862C9CDC1100795AA5 /* SubscriptionListNavigationButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 035394852C9CDC1100795AA5 /* SubscriptionListNavigationButton.swift */; };
0353948B2CA076D000795AA5 /* InboxView+Views.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0353948A2CA076D000795AA5 /* InboxView+Views.swift */; };
0353948D2CA080EB00795AA5 /* FeedWelcomeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0353948C2CA080EB00795AA5 /* FeedWelcomeView.swift */; };
0353948F2CA088E600795AA5 /* DeveloperSettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0353948E2CA088E600795AA5 /* DeveloperSettingsView.swift */; };
0355F9462C150B2300605248 /* ExternalApiInfoView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0355F9452C150B2300605248 /* ExternalApiInfoView.swift */; };
0355F9492C16406E00605248 /* Line.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0355F9482C16406E00605248 /* Line.swift */; };
035BE0872BDD8DA000F77D73 /* NavigationRootView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 035BE0862BDD8DA000F77D73 /* NavigationRootView.swift */; };
Expand Down Expand Up @@ -455,6 +458,9 @@
03531EF02C2DA298004A3464 /* SearchResultsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchResultsView.swift; sourceTree = "<group>"; };
03531EF42C2DA610004A3464 /* NavigationSearchType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NavigationSearchType.swift; sourceTree = "<group>"; };
035394852C9CDC1100795AA5 /* SubscriptionListNavigationButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SubscriptionListNavigationButton.swift; sourceTree = "<group>"; };
0353948A2CA076D000795AA5 /* InboxView+Views.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "InboxView+Views.swift"; sourceTree = "<group>"; };
0353948C2CA080EB00795AA5 /* FeedWelcomeView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FeedWelcomeView.swift; sourceTree = "<group>"; };
0353948E2CA088E600795AA5 /* DeveloperSettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeveloperSettingsView.swift; sourceTree = "<group>"; };
0355F9452C150B2300605248 /* ExternalApiInfoView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExternalApiInfoView.swift; sourceTree = "<group>"; };
0355F9482C16406E00605248 /* Line.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Line.swift; sourceTree = "<group>"; };
035BE0862BDD8DA000F77D73 /* NavigationRootView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NavigationRootView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -775,6 +781,7 @@
031E2D5C2BEFCC630003BC45 /* SettingsView.swift */,
039F58892C7B54FE00C61658 /* GeneralSettingsView.swift */,
039F588B2C7B574E00C61658 /* AdvancedSettingsView.swift */,
0353948E2CA088E600795AA5 /* DeveloperSettingsView.swift */,
039F58962C7B68F100C61658 /* AboutMlemView.swift */,
0397D46B2C67E583002C6CDC /* SortingSettingsView.swift */,
03267D832BED49CE009D6268 /* AccountSettingsView.swift */,
Expand Down Expand Up @@ -935,6 +942,7 @@
isa = PBXGroup;
children = (
0369B3552BFA6824001EFEDF /* InboxView.swift */,
0353948A2CA076D000795AA5 /* InboxView+Views.swift */,
03B431BD2C455F1B001A1EB5 /* InboxView+Logic.swift */,
);
path = Inbox;
Expand Down Expand Up @@ -1517,6 +1525,7 @@
isa = PBXGroup;
children = (
CD7928222C73CBA400FA712D /* TileScoreView.swift */,
0353948C2CA080EB00795AA5 /* FeedWelcomeView.swift */,
);
path = Components;
sourceTree = "<group>";
Expand Down Expand Up @@ -1952,6 +1961,7 @@
0389DDCF2C39CB0E0005B808 /* SearchView.swift in Sources */,
0397D4742C680FFC002C6CDC /* ImageLoader.swift in Sources */,
03FE14042BF93FDD00A8377F /* ErrorDetails.swift in Sources */,
0353948B2CA076D000795AA5 /* InboxView+Views.swift in Sources */,
0389DDD12C39E1030005B808 /* InstanceListRowBody.swift in Sources */,
033FCAF42C59843E007B7CD1 /* CommunityView.swift in Sources */,
CD7928262C73E73400FA712D /* PersonView+Logic.swift in Sources */,
Expand Down Expand Up @@ -2088,6 +2098,7 @@
03D3A1F32BB9D49B009DE55E /* ActionGroup.swift in Sources */,
03049A222C650B2C00FF6889 /* CommunityDetailsView.swift in Sources */,
CD7882A92BFFDFC7002E1A30 /* PostTag.swift in Sources */,
0353948F2CA088E600795AA5 /* DeveloperSettingsView.swift in Sources */,
CD7882AB2C013005002E1A30 /* EllipsisMenu.swift in Sources */,
039D75672C4FC5A3004F24C2 /* LargeImageView.swift in Sources */,
CDBFCB6A2C04EFFE008CD468 /* PostSettingsView.swift in Sources */,
Expand Down Expand Up @@ -2193,6 +2204,7 @@
03A82FA32C0D1F2400D01A5C /* View+ExternalApiWarning.swift in Sources */,
033F84C32C2B12AA002E3EDF /* InstanceSummary.swift in Sources */,
0369B3532BFA514B001EFEDF /* ToastLocation.swift in Sources */,
0353948D2CA080EB00795AA5 /* FeedWelcomeView.swift in Sources */,
03049A202C650A8100FF6889 /* FormReadout.swift in Sources */,
0397D49A2C6EA6EE002C6CDC /* InteractionBarEditorView.swift in Sources */,
0300309D2C4163C9009A65FF /* CommentTreeTracker.swift in Sources */,
Expand Down
2 changes: 2 additions & 0 deletions Mlem/App/Configuration/User Settings/Settings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ class Settings: ObservableObject {

@AppStorage("status.bypassImageProxyShown") var bypassImageProxyShown: Bool = false

@AppStorage("tip.feedWelcomePrompt") var showFeedWelcomePrompt: Bool = true

var codable: CodableSettings { .init(from: self) }

@MainActor
Expand Down
2 changes: 2 additions & 0 deletions Mlem/App/Globals/Definitions/AccountsTracker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ class AccountsTracker {
try! (guestAccounts.first ?? .getGuestAccount(url: URL(string: "https://lemmy.world/")!))
}

var isEmpty: Bool { userAccounts.isEmpty && guestAccounts.isEmpty }

private var cancellables = Set<AnyCancellable>()

private init() {
Expand Down
61 changes: 61 additions & 0 deletions Mlem/App/Views/Root/Tabs/Feeds/Components/FeedWelcomeView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
//
// FeedWelcomeView.swift
// Mlem
//
// Created by Sjmarf on 22/09/2024.
//

import SwiftUI

struct FeedWelcomeView: View {
@Environment(AppState.self) var appState
@Environment(Palette.self) var palette
@Environment(NavigationLayer.self) var navigation

@Setting(\.showFeedWelcomePrompt) var showWelcomePrompt

var body: some View {
VStack(spacing: Constants.main.standardSpacing) {
HStack(spacing: Constants.main.standardSpacing) {
VStack(alignment: .leading) {
Text("Welcome to Lemmy!")
.fontWeight(.semibold)
Text(
// swiftlint:disable:next line_length
"You are browsing \(appState.firstApi.host ?? "") as a guest. If you'd like to vote or reply, you'll need to log in or sign up."
)
.font(.footnote)
}
}
.foregroundStyle(palette.accent)
HStack(spacing: Constants.main.standardSpacing) {
Button {
navigation.openSheet(.logIn(.pickInstance))
} label: {
Text("Log In")
.frame(maxWidth: 400)
.padding(.vertical, 4)
}
Button {
navigation.openSheet(.signUp())
} label: {
Text("Sign Up")
.frame(maxWidth: 400)
.padding(.vertical, 4)
}
}
.buttonStyle(.borderedProminent)
}
.padding(Constants.main.standardSpacing)
.background(palette.accent.opacity(0.2), in: .rect(cornerRadius: Constants.main.standardSpacing))
.overlay(alignment: .topTrailing) {
Button("Dismiss", systemImage: Icons.closeCircleFill) {
showWelcomePrompt = false
}
.symbolRenderingMode(.hierarchical)
.labelStyle(.iconOnly)
.fontWeight(.semibold)
.padding(4)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,22 @@ struct FeedDescription {
iconScaleFactor: 0.6
)

static var local: FeedDescription = .init(
label: "Local",
subtitle: "Posts from \(AppState.main.firstApi.host ?? "your instance's") communities",
color: { $0.localFeed },
iconName: Icons.instanceFeed,
iconNameFill: Icons.instanceFeedFill,
iconScaleFactor: 0.55
)
static var local: FeedDescription {
let subtitle: LocalizedStringResource
if let host = AppState.main.firstApi.host {
subtitle = "Posts from \(host) communities"
} else {
subtitle = "Posts from your instance's communities"
}
return .init(
label: "Local",
subtitle: subtitle,
color: { $0.localFeed },
iconName: Icons.instanceFeed,
iconNameFill: Icons.instanceFeedFill,
iconScaleFactor: 0.55
)
}

static var subscribed: FeedDescription = .init(
label: "Subscribed",
Expand Down
5 changes: 5 additions & 0 deletions Mlem/App/Views/Root/Tabs/Feeds/FeedsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import SwiftUI
struct FeedsView: View {
@Setting(\.postSize) var postSize
@Setting(\.showReadInFeed) var showRead
@Setting(\.showFeedWelcomePrompt) var showWelcomePrompt

@Environment(AppState.self) var appState
@Environment(Palette.self) var palette
Expand Down Expand Up @@ -147,6 +148,10 @@ struct FeedsView: View {
var content: some View {
FancyScrollView(scrollToTopTrigger: $scrollToTopTrigger) {
Section {
if AccountsTracker.main.isEmpty, showWelcomePrompt {
FeedWelcomeView()
.padding([.horizontal, .bottom], Constants.main.standardSpacing)
}
if let savedFeedLoader, feedSelection == .saved {
PersonContentGridView(feedLoader: savedFeedLoader, contentType: .constant(.all))
} else if let postFeedLoader {
Expand Down
71 changes: 64 additions & 7 deletions Mlem/App/Views/Root/Tabs/Feeds/SubscriptionListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ struct SubscriptionListView: View {

@ViewBuilder
var content: some View {
let subscriptions = (appState.firstSession as? UserSession)?.subscriptions
let sections = subscriptions?.visibleSections(sort: sort) ?? []

ScrollViewReader { proxy in
Expand All @@ -47,15 +46,32 @@ struct SubscriptionListView: View {
ForEach(feedOptions, id: \.hashValue) { feedOption in
SubscriptionListNavigationButton(.feeds(feedOption)) {
HStack(spacing: 15) {
FeedIconView(feedDescription: feedOption.description, size: 28)
Text(feedOption.description.label)
FeedIconView(
feedDescription: feedOption.description,
size: appState.firstSession is GuestSession ? 36 : 28
)
VStack(alignment: .leading) {
Text(feedOption.description.label)
if appState.firstSession is GuestSession {
Text(feedOption.description.subtitle)
.font(.footnote)
.foregroundStyle(palette.secondary)
}
}
}
.frame(maxWidth: .infinity, alignment: .leading)
.contentShape(.rect)
}
}
}

if AccountsTracker.main.isEmpty {
Section {
signedOutInfoView
.listRowBackground(Color.clear)
}
}

ForEach(sections) { section in
SubscriptionListSectionView(section: section, sectionIndicesShown: sectionIndicesShown)
.id(section.label)
Expand All @@ -73,9 +89,11 @@ struct SubscriptionListView: View {
}
}
.toolbar {
Picker("Sort", selection: $sort) {
ForEach(SubscriptionListSort.allCases, id: \.self) { item in
Label(item.label, systemImage: item.systemImage)
if !(subscriptions?.communities.isEmpty ?? true) {
Picker("Sort", selection: $sort) {
ForEach(SubscriptionListSort.allCases, id: \.self) { item in
Label(item.label, systemImage: item.systemImage)
}
}
}
}
Expand All @@ -100,8 +118,47 @@ struct SubscriptionListView: View {
}
}

@ViewBuilder
var signedOutInfoView: some View {
VStack {
Image(systemName: "list.bullet")
.resizable()
.aspectRatio(contentMode: .fit)
.frame(height: 50)
.foregroundStyle(palette.tertiary)
.padding(.bottom, 5)
Text("Your subscriptions live here.")
.font(.title2)
.fontWeight(.semibold)
Text("Log in or sign up to view your subscriptions.")
HStack {
Button {
navigation.openSheet(.logIn(.pickInstance))
} label: {
Text("Log In")
.frame(minWidth: 80)
}
Button {
navigation.openSheet(.signUp())
} label: {
Text("Sign Up")
.frame(minWidth: 80)
}
}
.tint(palette.secondary)
.buttonStyle(.bordered)
}
.multilineTextAlignment(.center)
.frame(maxWidth: .infinity)
.foregroundColor(palette.secondary)
}

var subscriptions: SubscriptionList? {
(appState.firstSession as? UserSession)?.subscriptions
}

var sectionIndicesShown: Bool {
!UIDevice.isPad && sort == .alphabetical
!UIDevice.isPad && sort == .alphabetical && (subscriptions?.communities.count ?? 0) > 10
}
}

Expand Down
Loading
Loading