Skip to content

Improve code snippets uploading #29

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

Merged
merged 1 commit into from
Jan 15, 2022
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
74 changes: 49 additions & 25 deletions SnippetsLibrary.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@
B80D24B2270A72ED0057582F /* SnippetsLibraryWidgetView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B80D24B0270A72CC0057582F /* SnippetsLibraryWidgetView.swift */; };
B80D24B6270A734E0057582F /* WidgetEntry.swift in Sources */ = {isa = PBXBuildFile; fileRef = B80D24B4270A73490057582F /* WidgetEntry.swift */; };
B80D24B8270A739F0057582F /* Provider.swift in Sources */ = {isa = PBXBuildFile; fileRef = B80D24B7270A739F0057582F /* Provider.swift */; };
B816C71A275817EA00680174 /* FirebaseAnalytics in Frameworks */ = {isa = PBXBuildFile; productRef = B816C719275817EA00680174 /* FirebaseAnalytics */; };
B816C71C275817EA00680174 /* FirebaseCrashlytics in Frameworks */ = {isa = PBXBuildFile; productRef = B816C71B275817EA00680174 /* FirebaseCrashlytics */; };
B816C71E275817EA00680174 /* FirebaseDatabase in Frameworks */ = {isa = PBXBuildFile; productRef = B816C71D275817EA00680174 /* FirebaseDatabase */; };
B816C720275817EA00680174 /* FirebaseRemoteConfig in Frameworks */ = {isa = PBXBuildFile; productRef = B816C71F275817EA00680174 /* FirebaseRemoteConfig */; };
B816C722275817EA00680174 /* FirebaseStorage in Frameworks */ = {isa = PBXBuildFile; productRef = B816C721275817EA00680174 /* FirebaseStorage */; };
B8190DF826FA388500E3994C /* SnippetType.swift in Sources */ = {isa = PBXBuildFile; fileRef = B8190DF726FA388500E3994C /* SnippetType.swift */; };
B81B0877270232B600E59F86 /* NSNotification+Name.swift in Sources */ = {isa = PBXBuildFile; fileRef = B81B0876270232B600E59F86 /* NSNotification+Name.swift */; };
B81B0879270245CE00E59F86 /* AppMenu+HideWindow.swift in Sources */ = {isa = PBXBuildFile; fileRef = B81B0878270245CE00E59F86 /* AppMenu+HideWindow.swift */; };
Expand Down Expand Up @@ -100,8 +105,6 @@
B8BEF5AD26FFEB600098A778 /* EmptySnippetsListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B8BEF5AC26FFEB600098A778 /* EmptySnippetsListView.swift */; };
B8C1F6C0270E13BA0088E5B5 /* Sourceful in Frameworks */ = {isa = PBXBuildFile; productRef = B8C1F6BF270E13BA0088E5B5 /* Sourceful */; };
B8C1F6C3270E13C30088E5B5 /* SwiftUISkeleton in Frameworks */ = {isa = PBXBuildFile; productRef = B8C1F6C2270E13C30088E5B5 /* SwiftUISkeleton */; };
B8C1F6C6270E13E60088E5B5 /* FirebaseCrashlytics in Frameworks */ = {isa = PBXBuildFile; productRef = B8C1F6C5270E13E60088E5B5 /* FirebaseCrashlytics */; };
B8C1F6C8270E13E60088E5B5 /* FirebaseDatabase in Frameworks */ = {isa = PBXBuildFile; productRef = B8C1F6C7270E13E60088E5B5 /* FirebaseDatabase */; };
B8C549BA26FF9C0800720E62 /* NetworkObserver.swift in Sources */ = {isa = PBXBuildFile; fileRef = B8C549B926FF9C0800720E62 /* NetworkObserver.swift */; };
B8C549BC26FFA71300720E62 /* AppView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B8C549BB26FFA71300720E62 /* AppView.swift */; };
B8C549C426FFBA8600720E62 /* View+Skeletonable.swift in Sources */ = {isa = PBXBuildFile; fileRef = B8C549C326FFBA8600720E62 /* View+Skeletonable.swift */; };
Expand Down Expand Up @@ -303,10 +306,13 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
B8C1F6C6270E13E60088E5B5 /* FirebaseCrashlytics in Frameworks */,
B816C71E275817EA00680174 /* FirebaseDatabase in Frameworks */,
B8C1F6C0270E13BA0088E5B5 /* Sourceful in Frameworks */,
B8FC70E327335DF80090292C /* PopupView in Frameworks */,
B8C1F6C8270E13E60088E5B5 /* FirebaseDatabase in Frameworks */,
B816C720275817EA00680174 /* FirebaseRemoteConfig in Frameworks */,
B816C71C275817EA00680174 /* FirebaseCrashlytics in Frameworks */,
B816C722275817EA00680174 /* FirebaseStorage in Frameworks */,
B816C71A275817EA00680174 /* FirebaseAnalytics in Frameworks */,
B8C1F6C3270E13C30088E5B5 /* SwiftUISkeleton in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -824,9 +830,12 @@
packageProductDependencies = (
B8C1F6BF270E13BA0088E5B5 /* Sourceful */,
B8C1F6C2270E13C30088E5B5 /* SwiftUISkeleton */,
B8C1F6C5270E13E60088E5B5 /* FirebaseCrashlytics */,
B8C1F6C7270E13E60088E5B5 /* FirebaseDatabase */,
B8FC70E227335DF80090292C /* PopupView */,
B816C719275817EA00680174 /* FirebaseAnalytics */,
B816C71B275817EA00680174 /* FirebaseCrashlytics */,
B816C71D275817EA00680174 /* FirebaseDatabase */,
B816C71F275817EA00680174 /* FirebaseRemoteConfig */,
B816C721275817EA00680174 /* FirebaseStorage */,
);
productName = SnippetsLibrary;
productReference = B82561B026E81D570040A67E /* Snippets Library.app */;
Expand Down Expand Up @@ -905,8 +914,8 @@
packageReferences = (
B8C1F6BE270E13BA0088E5B5 /* XCRemoteSwiftPackageReference "Sourceful" */,
B8C1F6C1270E13C30088E5B5 /* XCRemoteSwiftPackageReference "SwiftUISkeleton" */,
B8C1F6C4270E13E60088E5B5 /* XCRemoteSwiftPackageReference "firebase-ios-sdk" */,
B8FC70E127335DF80090292C /* XCRemoteSwiftPackageReference "PopupView" */,
B816C718275817EA00680174 /* XCRemoteSwiftPackageReference "firebase-ios-sdk" */,
);
productRefGroup = B82561B126E81D570040A67E /* Products */;
projectDirPath = "";
Expand Down Expand Up @@ -1513,25 +1522,25 @@
/* End XCConfigurationList section */

/* Begin XCRemoteSwiftPackageReference section */
B8C1F6BE270E13BA0088E5B5 /* XCRemoteSwiftPackageReference "Sourceful" */ = {
B816C718275817EA00680174 /* XCRemoteSwiftPackageReference "firebase-ios-sdk" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/twostraws/Sourceful.git";
repositoryURL = "https://github.com/firebase/firebase-ios-sdk.git";
requirement = {
branch = main;
branch = master;
kind = branch;
};
};
B8C1F6C1270E13C30088E5B5 /* XCRemoteSwiftPackageReference "SwiftUISkeleton" */ = {
B8C1F6BE270E13BA0088E5B5 /* XCRemoteSwiftPackageReference "Sourceful" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/serbats/SwiftUISkeleton.git";
repositoryURL = "https://github.com/twostraws/Sourceful.git";
requirement = {
branch = master;
branch = main;
kind = branch;
};
};
B8C1F6C4270E13E60088E5B5 /* XCRemoteSwiftPackageReference "firebase-ios-sdk" */ = {
B8C1F6C1270E13C30088E5B5 /* XCRemoteSwiftPackageReference "SwiftUISkeleton" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/firebase/firebase-ios-sdk.git";
repositoryURL = "https://github.com/serbats/SwiftUISkeleton.git";
requirement = {
branch = master;
kind = branch;
Expand All @@ -1548,6 +1557,31 @@
/* End XCRemoteSwiftPackageReference section */

/* Begin XCSwiftPackageProductDependency section */
B816C719275817EA00680174 /* FirebaseAnalytics */ = {
isa = XCSwiftPackageProductDependency;
package = B816C718275817EA00680174 /* XCRemoteSwiftPackageReference "firebase-ios-sdk" */;
productName = FirebaseAnalytics;
};
B816C71B275817EA00680174 /* FirebaseCrashlytics */ = {
isa = XCSwiftPackageProductDependency;
package = B816C718275817EA00680174 /* XCRemoteSwiftPackageReference "firebase-ios-sdk" */;
productName = FirebaseCrashlytics;
};
B816C71D275817EA00680174 /* FirebaseDatabase */ = {
isa = XCSwiftPackageProductDependency;
package = B816C718275817EA00680174 /* XCRemoteSwiftPackageReference "firebase-ios-sdk" */;
productName = FirebaseDatabase;
};
B816C71F275817EA00680174 /* FirebaseRemoteConfig */ = {
isa = XCSwiftPackageProductDependency;
package = B816C718275817EA00680174 /* XCRemoteSwiftPackageReference "firebase-ios-sdk" */;
productName = FirebaseRemoteConfig;
};
B816C721275817EA00680174 /* FirebaseStorage */ = {
isa = XCSwiftPackageProductDependency;
package = B816C718275817EA00680174 /* XCRemoteSwiftPackageReference "firebase-ios-sdk" */;
productName = FirebaseStorage;
};
B8C1F6BF270E13BA0088E5B5 /* Sourceful */ = {
isa = XCSwiftPackageProductDependency;
package = B8C1F6BE270E13BA0088E5B5 /* XCRemoteSwiftPackageReference "Sourceful" */;
Expand All @@ -1558,16 +1592,6 @@
package = B8C1F6C1270E13C30088E5B5 /* XCRemoteSwiftPackageReference "SwiftUISkeleton" */;
productName = SwiftUISkeleton;
};
B8C1F6C5270E13E60088E5B5 /* FirebaseCrashlytics */ = {
isa = XCSwiftPackageProductDependency;
package = B8C1F6C4270E13E60088E5B5 /* XCRemoteSwiftPackageReference "firebase-ios-sdk" */;
productName = FirebaseCrashlytics;
};
B8C1F6C7270E13E60088E5B5 /* FirebaseDatabase */ = {
isa = XCSwiftPackageProductDependency;
package = B8C1F6C4270E13E60088E5B5 /* XCRemoteSwiftPackageReference "firebase-ios-sdk" */;
productName = FirebaseDatabase;
};
B8FC70E227335DF80090292C /* PopupView */ = {
isa = XCSwiftPackageProductDependency;
package = B8FC70E127335DF80090292C /* XCRemoteSwiftPackageReference "PopupView" */;
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,18 @@ struct SnippetDetailsView: View {
// MARK: - Views

var body: some View {
VStack(alignment: .leading, spacing: .zero) {
VStack(
alignment: .leading,
spacing: .zero
) {
TextField(
"Snippet title",
text: $viewModel.snippet.title
)
.modifier(TextFieldStyleModifier(type: viewModel.type))
.font(.system(size: 15, weight: .bold))
.foregroundColor(Color.primary)
.help("Provide the title in a common format for all snippets, e.g. Basic Service.")

TextField(
"Snippet summary",
Expand All @@ -46,6 +50,7 @@ struct SnippetDetailsView: View {
.modifier(TextFieldStyleModifier(type: viewModel.type))
.font(.system(size: 11, weight: .regular))
.foregroundColor(Color.primary)
.help("Describe your snippet in a few words.")
.padding(.top, Layout.smallPadding / 2)

GeometryReader { geometry in
Expand All @@ -64,6 +69,7 @@ struct SnippetDetailsView: View {
width: geometry.frame(in: .global).width,
height: geometry.frame(in: .global).height
)
.help("Remember, that the provided code snippet should be ready to use.")
}
.padding(.horizontal, Constants.codeEditorHorizontalPadding)
.padding(.vertical, Constants.codeEditorVerticlaPadding)
Expand Down Expand Up @@ -100,6 +106,7 @@ struct SnippetDetailsView: View {
viewModel.snippet.platform = viewModel.platforms[index]
}
}
.help("Supported platform by code snippet.")

HStack {
Text("Completion")
Expand All @@ -123,6 +130,7 @@ struct SnippetDetailsView: View {
)
.padding(.leading, Layout.smallPadding)
}
.help("Completion should be unique to this snippet and easy to remember.")
.padding(.top, Constants.lineTopPadding)

HStack {
Expand Down Expand Up @@ -150,6 +158,7 @@ struct SnippetDetailsView: View {
viewModel.snippet.availability = viewModel.availabilities[index]
}
}
.help("Scope for this code snippet.")
.padding(.top, Constants.lineTopPadding)

HStack {
Expand Down Expand Up @@ -184,6 +193,7 @@ struct SnippetDetailsView: View {
.padding(.leading, Layout.smallPadding)
}
}
.help("Author of this code snippet.")
.padding(.top, Constants.lineTopPadding)

Spacer()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@ final class SnippetDetailsViewModel: ObservableObject {

// MARK: - Stored Properties

@Published internal var snippet: Snippet
@Binding internal var activeAppView: ActiveAppView?
@Published var snippet: Snippet
@Binding private(set) var activeAppView: ActiveAppView?

internal let type: SnippetDetailsViewType
let type: SnippetDetailsViewType
private var lastSavedSnippet: Snippet? = nil

@Published internal var platformSelectionIndex: Int = 0
internal var platforms = SnippetPlatform.allCases
@Published var platformSelectionIndex = 0
let platforms = SnippetPlatform.allCases

@Published internal var availabilitySelectionIndex: Int = 0
internal var availabilities = SnippetAvailability.allCases
@Published var availabilitySelectionIndex = 0
let availabilities = SnippetAvailability.allCases

@Published private(set) var shouldDismissView = false
@Published internal var shouldShowErrorAlert = false
@Published var shouldShowErrorAlert = false

private let snippetsParserService: SnippetsParserService
private let databaseService: DatabaseService
Expand All @@ -34,8 +34,10 @@ final class SnippetDetailsViewModel: ObservableObject {

// MARK: - Computed Properties

internal var hasChanges: Bool {
lastSavedSnippet != snippet
var hasChanges: Bool {
lastSavedSnippet != snippet && !snippet.title.isEmpty &&
!snippet.summary.isEmpty && !snippet.content.isEmpty &&
!snippet.completion.isEmpty
}

// MARK: - Initialization
Expand All @@ -58,7 +60,7 @@ final class SnippetDetailsViewModel: ObservableObject {

// MARK: - Methods

internal func performChanges() {
func performChanges() {
guard hasChanges else { return }

if type == .create {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ final class SnippetsLibraryViewModel: ObservableObject {
}

internal func fetchSnippets() {
databaseService.fetchSnippets()
databaseService.snippets
.receive(on: DispatchQueue.main)
.sink { [weak self] completion in
switch completion {
Expand Down
Loading