Skip to content

Commit

Permalink
fix vendor svg not displaying after a reload
Browse files Browse the repository at this point in the history
  • Loading branch information
Baptouuuu committed Jan 14, 2023
1 parent da477d7 commit 698f132
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 16 deletions.
8 changes: 4 additions & 4 deletions Innmind.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 4;
CURRENT_PROJECT_VERSION = 5;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_ASSET_PATHS = "\"Innmind/Preview Content\"";
DEVELOPMENT_TEAM = 62A9CWW839;
Expand All @@ -543,7 +543,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 13.0;
MARKETING_VERSION = 1.2.0;
MARKETING_VERSION = 1.2.1;
PRODUCT_BUNDLE_IDENTIFIER = com.innmind.Innmind;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES;
Expand All @@ -562,7 +562,7 @@
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 4;
CURRENT_PROJECT_VERSION = 5;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_ASSET_PATHS = "\"Innmind/Preview Content\"";
DEVELOPMENT_TEAM = 62A9CWW839;
Expand All @@ -576,7 +576,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 13.0;
MARKETING_VERSION = 1.2.0;
MARKETING_VERSION = 1.2.1;
PRODUCT_BUNDLE_IDENTIFIER = com.innmind.Innmind;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES;
Expand Down
11 changes: 11 additions & 0 deletions Innmind/Model/Svg.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,17 @@ final class Svg: ObservableObject {
self.refetch = refetch
}

static func vendor(_ vendor: Vendor) -> Svg {
return .init(
{
return await vendor.svg()
},
{
return await vendor.reload()
}
)
}

static func dependencies(_ package: Vendor.Package) -> Svg {
return .init(
{
Expand Down
19 changes: 8 additions & 11 deletions Innmind/Views/VendorView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,20 @@ import SwiftUI

struct VendorView: View {
@Environment(\.openURL) var openUrl
@EnvironmentObject var svg: Svg

@State private var zoom: Zoom = .middle
@State private var content: Data?
let vendor: Vendor

var body: some View {
VStack {
if let content {
if let content = svg.content {
SvgView(content: content, zoom: $zoom)
} else {
LoadingView()
.onAppear {
self.svg.load()
}
}
}
.toolbar {
Expand All @@ -38,20 +41,14 @@ struct VendorView: View {
Text(Zoom.max.name()).tag(Zoom.max)
}
.pickerStyle(SegmentedPickerStyle())
.disabled(self.content == nil)
.disabled(self.svg.content == nil)
Button {
content = nil
Task {
await vendor.reload()
}
self.svg.reload()
} label: {
Image(systemName: "arrow.clockwise.circle")
.accessibilityLabel("Reload Graph")
}
.disabled(self.content == nil)
}
.task {
self.content = await vendor.svg()
.disabled(self.svg.content == nil)
}
}
}
14 changes: 13 additions & 1 deletion Innmind/Views/WindowView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,23 @@ struct DisplayTargetSvgView: View {
@Binding var vendor: Vendor?
@Binding var package: Vendor.Package?

private var vendorSvg: Svg?

init(vendor: Binding<Vendor?>, package: Binding<Vendor.Package?>) {
_vendor = vendor
_package = package

if let currentVendor = vendor.wrappedValue {
vendorSvg = Svg.vendor(currentVendor)
}
}

var body: some View {
if let package {
PackageGraphs(package: package)
} else if let vendor {
} else if let vendor, let vendorSvg {
VendorView(vendor: vendor)
.environmentObject(vendorSvg)
} else {
EmptyView()
}
Expand Down

0 comments on commit 698f132

Please sign in to comment.