Skip to content

Commit 919b9e1

Browse files
committed
Add snippet manual popup
1 parent 58b6721 commit 919b9e1

File tree

9 files changed

+168
-24
lines changed

9 files changed

+168
-24
lines changed

SnippetsLibrary.xcodeproj/project.pbxproj

+29-6
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@
129129
B8F95B0926EEAF4D00335D77 /* SnippetImportViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = B8F95B0826EEAF4D00335D77 /* SnippetImportViewModel.swift */; };
130130
B8F9CA982700F7F40041CE3E /* DisabledCommandGroupButtonType.swift in Sources */ = {isa = PBXBuildFile; fileRef = B8F9CA972700F7F40041CE3E /* DisabledCommandGroupButtonType.swift */; };
131131
B8F9CA9A2700F80E0041CE3E /* UploadingStatus.swift in Sources */ = {isa = PBXBuildFile; fileRef = B8F9CA992700F80E0041CE3E /* UploadingStatus.swift */; };
132+
B8FC70E327335DF80090292C /* PopupView in Frameworks */ = {isa = PBXBuildFile; productRef = B8FC70E227335DF80090292C /* PopupView */; };
133+
B8FC70E5273361BD0090292C /* SnippetCreationManualView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B8FC70E4273361BD0090292C /* SnippetCreationManualView.swift */; };
132134
/* End PBXBuildFile section */
133135

134136
/* Begin PBXContainerItemProxy section */
@@ -284,6 +286,7 @@
284286
B8F95B0826EEAF4D00335D77 /* SnippetImportViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SnippetImportViewModel.swift; sourceTree = "<group>"; };
285287
B8F9CA972700F7F40041CE3E /* DisabledCommandGroupButtonType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DisabledCommandGroupButtonType.swift; sourceTree = "<group>"; };
286288
B8F9CA992700F80E0041CE3E /* UploadingStatus.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UploadingStatus.swift; sourceTree = "<group>"; };
289+
B8FC70E4273361BD0090292C /* SnippetCreationManualView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SnippetCreationManualView.swift; sourceTree = "<group>"; };
287290
/* End PBXFileReference section */
288291

289292
/* Begin PBXFrameworksBuildPhase section */
@@ -302,6 +305,7 @@
302305
files = (
303306
B8C1F6C6270E13E60088E5B5 /* FirebaseCrashlytics in Frameworks */,
304307
B8C1F6C0270E13BA0088E5B5 /* Sourceful in Frameworks */,
308+
B8FC70E327335DF80090292C /* PopupView in Frameworks */,
305309
B8C1F6C8270E13E60088E5B5 /* FirebaseDatabase in Frameworks */,
306310
B8C1F6C3270E13C30088E5B5 /* SwiftUISkeleton in Frameworks */,
307311
);
@@ -508,6 +512,7 @@
508512
B8CE1CAA26FD4193004AD5D5 /* DisabledCommandGroupButton.swift */,
509513
B8BEF5A826FFBF7E0098A778 /* ToastView.swift */,
510514
B8BEF5AC26FFEB600098A778 /* EmptySnippetsListView.swift */,
515+
B8FC70E4273361BD0090292C /* SnippetCreationManualView.swift */,
511516
);
512517
path = Views;
513518
sourceTree = "<group>";
@@ -821,6 +826,7 @@
821826
B8C1F6C2270E13C30088E5B5 /* SwiftUISkeleton */,
822827
B8C1F6C5270E13E60088E5B5 /* FirebaseCrashlytics */,
823828
B8C1F6C7270E13E60088E5B5 /* FirebaseDatabase */,
829+
B8FC70E227335DF80090292C /* PopupView */,
824830
);
825831
productName = SnippetsLibrary;
826832
productReference = B82561B026E81D570040A67E /* Snippets Library.app */;
@@ -900,6 +906,7 @@
900906
B8C1F6BE270E13BA0088E5B5 /* XCRemoteSwiftPackageReference "Sourceful" */,
901907
B8C1F6C1270E13C30088E5B5 /* XCRemoteSwiftPackageReference "SwiftUISkeleton" */,
902908
B8C1F6C4270E13E60088E5B5 /* XCRemoteSwiftPackageReference "firebase-ios-sdk" */,
909+
B8FC70E127335DF80090292C /* XCRemoteSwiftPackageReference "PopupView" */,
903910
);
904911
productRefGroup = B82561B126E81D570040A67E /* Products */;
905912
projectDirPath = "";
@@ -1058,6 +1065,7 @@
10581065
B82561E926E8C7D60040A67E /* SnippetsLibraryView.swift in Sources */,
10591066
B85AC934270215ED00A008A6 /* StatusViewModel.swift in Sources */,
10601067
B85AC9302702158300A008A6 /* AppDelegate+NSMenuDelegate.swift in Sources */,
1068+
B8FC70E5273361BD0090292C /* SnippetCreationManualView.swift in Sources */,
10611069
B8546F3A270773FE0043A99F /* SnippetsLibraryListFilterView.swift in Sources */,
10621070
B8EB5ADF26F00A4A00BE3EF6 /* SnippetDetailsViewType.swift in Sources */,
10631071
B84BFEA926F57018007E5109 /* System.swift in Sources */,
@@ -1158,6 +1166,7 @@
11581166
MARKETING_VERSION = 1.0;
11591167
PRODUCT_BUNDLE_IDENTIFIER = com.cphlowiec.SnippetsLibrary.SnippetsLibraryWidget;
11601168
PRODUCT_NAME = "$(TARGET_NAME)";
1169+
PROVISIONING_PROFILE_SPECIFIER = "";
11611170
SKIP_INSTALL = YES;
11621171
SWIFT_EMIT_LOC_STRINGS = YES;
11631172
SWIFT_VERSION = 5.0;
@@ -1190,6 +1199,7 @@
11901199
MARKETING_VERSION = 1.0;
11911200
PRODUCT_BUNDLE_IDENTIFIER = com.cphlowiec.SnippetsLibrary.SnippetsLibraryWidget;
11921201
PRODUCT_NAME = "$(TARGET_NAME)";
1202+
PROVISIONING_PROFILE_SPECIFIER = "";
11931203
SKIP_INSTALL = YES;
11941204
SWIFT_EMIT_LOC_STRINGS = YES;
11951205
SWIFT_VERSION = 5.0;
@@ -1318,8 +1328,8 @@
13181328
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
13191329
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
13201330
CODE_SIGN_ENTITLEMENTS = SnippetsLibrary/SnippetsLibraryDebug.entitlements;
1321-
CODE_SIGN_IDENTITY = "Apple Development";
1322-
CODE_SIGN_STYLE = Automatic;
1331+
CODE_SIGN_IDENTITY = "Mac Developer";
1332+
CODE_SIGN_STYLE = Manual;
13231333
COMBINE_HIDPI_IMAGES = YES;
13241334
CURRENT_PROJECT_VERSION = 16;
13251335
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
@@ -1336,7 +1346,7 @@
13361346
MARKETING_VERSION = 1.0;
13371347
PRODUCT_BUNDLE_IDENTIFIER = com.cphlowiec.SnippetsLibrary;
13381348
PRODUCT_NAME = "Snippets Library";
1339-
PROVISIONING_PROFILE_SPECIFIER = "";
1349+
PROVISIONING_PROFILE_SPECIFIER = "SnippetsLibrary Development";
13401350
SWIFT_VERSION = 5.0;
13411351
};
13421352
name = Debug;
@@ -1348,8 +1358,8 @@
13481358
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
13491359
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
13501360
CODE_SIGN_ENTITLEMENTS = SnippetsLibrary/SnippetsLibrary.entitlements;
1351-
CODE_SIGN_IDENTITY = "Apple Development";
1352-
CODE_SIGN_STYLE = Automatic;
1361+
CODE_SIGN_IDENTITY = "Mac Developer";
1362+
CODE_SIGN_STYLE = Manual;
13531363
COMBINE_HIDPI_IMAGES = YES;
13541364
CURRENT_PROJECT_VERSION = 16;
13551365
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
@@ -1366,7 +1376,7 @@
13661376
MARKETING_VERSION = 1.0;
13671377
PRODUCT_BUNDLE_IDENTIFIER = com.cphlowiec.SnippetsLibrary;
13681378
PRODUCT_NAME = "Snippets Library";
1369-
PROVISIONING_PROFILE_SPECIFIER = "";
1379+
PROVISIONING_PROFILE_SPECIFIER = "SnippetsLibrary Development";
13701380
SWIFT_ACTIVE_COMPILATION_CONDITIONS = RELEASE;
13711381
SWIFT_VERSION = 5.0;
13721382
};
@@ -1527,6 +1537,14 @@
15271537
kind = branch;
15281538
};
15291539
};
1540+
B8FC70E127335DF80090292C /* XCRemoteSwiftPackageReference "PopupView" */ = {
1541+
isa = XCRemoteSwiftPackageReference;
1542+
repositoryURL = "https://github.com/exyte/PopupView.git";
1543+
requirement = {
1544+
kind = upToNextMajorVersion;
1545+
minimumVersion = 1.0.0;
1546+
};
1547+
};
15301548
/* End XCRemoteSwiftPackageReference section */
15311549

15321550
/* Begin XCSwiftPackageProductDependency section */
@@ -1550,6 +1568,11 @@
15501568
package = B8C1F6C4270E13E60088E5B5 /* XCRemoteSwiftPackageReference "firebase-ios-sdk" */;
15511569
productName = FirebaseDatabase;
15521570
};
1571+
B8FC70E227335DF80090292C /* PopupView */ = {
1572+
isa = XCSwiftPackageProductDependency;
1573+
package = B8FC70E127335DF80090292C /* XCRemoteSwiftPackageReference "PopupView" */;
1574+
productName = PopupView;
1575+
};
15531576
/* End XCSwiftPackageProductDependency section */
15541577
};
15551578
rootObject = B82561A826E81D570040A67E /* Project object */;

SnippetsLibrary.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved

+9
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,15 @@
9191
"version": "2.30908.0"
9292
}
9393
},
94+
{
95+
"package": "PopupView",
96+
"repositoryURL": "https://github.com/exyte/PopupView.git",
97+
"state": {
98+
"branch": null,
99+
"revision": "0d37d6f94e0ec9b38ab43300213ad72d28af921f",
100+
"version": "1.0.2"
101+
}
102+
},
94103
{
95104
"package": "Promises",
96105
"repositoryURL": "https://github.com/google/promises.git",

SnippetsLibrary/Modules/SnippetsLibrary/SnippetsLibraryView.swift

+42-16
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
//
77

88
import SwiftUI
9+
import PopupView
910

1011
struct SnippetsLibraryView: View {
1112

@@ -15,29 +16,32 @@ struct SnippetsLibraryView: View {
1516

1617
@Binding internal var activeSheet: AppSheet?
1718
@State private var appAlert: AppAlert? = nil
19+
@State private var shouldShowSnippetManual = false
1820

1921
// MARK: - Views
2022

2123
var body: some View {
22-
HSplitView {
23-
SnippetsLibraryListView(
24-
viewModel: SnippetsLibraryListViewModel(
24+
ZStack {
25+
HSplitView {
26+
SnippetsLibraryListView(
27+
viewModel: SnippetsLibraryListViewModel(
28+
snippets: $viewModel.snippets,
29+
selectedSnippetId: $viewModel.selectedSnippetId
30+
) {
31+
viewModel.fetchSnippets()
32+
} onRemove: {
33+
viewModel.onRemove($0)
34+
}
35+
)
36+
37+
SnippetsLibraryPreviewView(
2538
snippets: $viewModel.snippets,
26-
selectedSnippetId: $viewModel.selectedSnippetId
39+
selectedSnippetId: $viewModel.selectedSnippetId,
40+
activeSheet: $activeSheet,
41+
appAlert: $appAlert
2742
) {
28-
viewModel.fetchSnippets()
29-
} onRemove: {
30-
viewModel.onRemove($0)
43+
viewModel.saveSnippetToRecentSnippets($0)
3144
}
32-
)
33-
34-
SnippetsLibraryPreviewView(
35-
snippets: $viewModel.snippets,
36-
selectedSnippetId: $viewModel.selectedSnippetId,
37-
activeSheet: $activeSheet,
38-
appAlert: $appAlert
39-
) {
40-
viewModel.saveSnippetToRecentSnippets($0)
4145
}
4246
}
4347
.frame(
@@ -83,6 +87,28 @@ struct SnippetsLibraryView: View {
8387
subtitle: "Requested operation couldn't be completed",
8488
state: .failure
8589
)
90+
.popup(
91+
isPresented: $shouldShowSnippetManual,
92+
type: .floater(verticalPadding: Layout.defaultWindowSize.height),
93+
position: .bottom,
94+
animation: .easeInOut,
95+
closeOnTapOutside: true,
96+
backgroundColor: Color.black.opacity(Layout.mediumOpacity)
97+
) {
98+
viewModel.markSnippetManualAsReaded()
99+
} view: {
100+
SnippetCreationManualView()
101+
}
102+
.onAppear {
103+
showSnippetManualIfNeeded()
104+
}
105+
}
106+
107+
// MARK: - Methods
108+
109+
private func showSnippetManualIfNeeded() {
110+
let userDefaultsService = DIContainer.userDefaultsService
111+
shouldShowSnippetManual = userDefaultsService.shouldShowSnippetManual()
86112
}
87113

88114
}

SnippetsLibrary/Modules/SnippetsLibrary/SnippetsLibraryViewModel.swift

+4
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ final class SnippetsLibraryViewModel: ObservableObject {
8888
}
8989
}
9090

91+
internal func markSnippetManualAsReaded() {
92+
userDefaultsService.markSnippetManualAsReaded()
93+
}
94+
9195
private func fetchLocalSnippets() {
9296
userDefaultsService.fetchSnippets(fetchingType: .local)
9397
.receive(on: DispatchQueue.main)

SnippetsLibrary/Services/UserDefaults/UserDefaultsService.swift

+18
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ protocol UserDefaultsService {
1414
func saveSnippetsLocally(_ snippets: [Snippet])
1515

1616
func fetchRecentSnippetsFromAppGroup() -> [Snippet]
17+
18+
func shouldShowSnippetManual() -> Bool
19+
func markSnippetManualAsReaded()
1720
}
1821

1922
final class UserDefaultsServiceImpl: UserDefaultsService {
@@ -22,6 +25,7 @@ final class UserDefaultsServiceImpl: UserDefaultsService {
2225
static let recentSnippetKey = "RecentSnippet"
2326
static let localSnippetKey = "LocalSnippet"
2427
static let appGroupName = "group.com.cphlowiec.SnippetsLibrary"
28+
static let snippetManualKey = "wasSnippetManualReaded"
2529
}
2630

2731
// MARK: - Stored Properties
@@ -122,4 +126,18 @@ final class UserDefaultsServiceImpl: UserDefaultsService {
122126
)
123127
}
124128

129+
// MARK: - Snippet Manual
130+
131+
internal func shouldShowSnippetManual() -> Bool {
132+
let wasSnippetsManualReaded = userDefaults.bool(forKey: Constants.snippetManualKey)
133+
return !wasSnippetsManualReaded
134+
}
135+
136+
internal func markSnippetManualAsReaded() {
137+
userDefaults.set(
138+
true,
139+
forKey: Constants.snippetManualKey
140+
)
141+
}
142+
125143
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
//
2+
// SnippetCreationManualView.swift
3+
// SnippetsLibrary
4+
//
5+
// Created by Krzysztof Łowiec on 03/11/2021.
6+
//
7+
8+
import SwiftUI
9+
10+
struct SnippetCreationManualView: View {
11+
12+
private enum Constants {
13+
static let imageHeight: CGFloat = 38.0
14+
static let lineSpacing: CGFloat = 5.0
15+
static let viewSize = CGSize(width: 350.0, height: 400.0)
16+
static let cornerRadius: CGFloat = 12.0
17+
}
18+
19+
// MARK: - Views
20+
21+
var body: some View {
22+
VStack {
23+
Image("icSnippetFileWhite")
24+
.resizable()
25+
.aspectRatio(contentMode: .fit)
26+
.frame(height: Constants.imageHeight)
27+
28+
Text("How to create a snippet?")
29+
.font(.system(size: 17, weight: .bold))
30+
.padding(.bottom, Layout.smallPadding)
31+
32+
Text("To maintain consistency and unify all code snippets in the Snippets Library, follow this two main rules:")
33+
.font(.system(size: 11, weight: .medium))
34+
.padding(.bottom)
35+
.opacity(Layout.mediumOpacity)
36+
.multilineTextAlignment(.center)
37+
38+
Text(
39+
"""
40+
✅ Make sure, that your snippet is helpful, complete and contains only the necessary lines required for use.
41+
42+
✅ Enter the title, summary, supported platforms and scopes and remember, that the completion should be self-explaining.
43+
"""
44+
)
45+
.lineSpacing(Constants.lineSpacing)
46+
.font(.system(size: 13))
47+
.multilineTextAlignment(.leading)
48+
}
49+
.padding(Layout.largePadding)
50+
.frame(
51+
width: Constants.viewSize.width,
52+
height: Constants.viewSize.height
53+
)
54+
.background(Color("defaultBackground"))
55+
.cornerRadius(Constants.cornerRadius)
56+
}
57+
58+
}
59+
60+
struct SnippetCreationManualView_Previews: PreviewProvider {
61+
static var previews: some View {
62+
SnippetCreationManualView()
63+
}
64+
}

SnippetsLibrary/Views/SnippetFileCard/SnippetFileCardView.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ struct SnippetFileCardView: View {
137137
.frame(height: Constants.bottomBarHeight)
138138
.background(
139139
RoundedRectangle(cornerRadius: Constants.bottomBarCornerRadius)
140-
.foregroundColor(Color("darkGrey"))
140+
.foregroundColor(Color("skeletonLight"))
141141
)
142142
.padding(.vertical, Layout.smallPadding)
143143
}

SnippetsLibraryWidget/Views/MediumWidget/MediumWidgetView.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ struct MediumWidgetView: View {
2727
Spacer()
2828

2929
Rectangle()
30-
.foregroundColor(Color("widgetBackground"))
30+
.foregroundColor(Color("defaultBackground"))
3131
.frame(width: geometry.size.width / 2)
3232
}
3333

0 commit comments

Comments
 (0)