Skip to content

Commit

Permalink
feat: flattened ui and add url/comments link
Browse files Browse the repository at this point in the history
  • Loading branch information
mattrighetti committed Nov 4, 2023
1 parent 70a0bb7 commit 0007c9c
Show file tree
Hide file tree
Showing 7 changed files with 158 additions and 107 deletions.
23 changes: 19 additions & 4 deletions HNReader.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 50;
objectVersion = 54;
objects = {

/* Begin PBXBuildFile section */
Expand All @@ -15,6 +15,7 @@
330718D415D21296AA14E7CA /* HackerNewsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 33071291447141A6D31E671B /* HackerNewsTests.swift */; };
330719203034BDB177F28C41 /* +DateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 33071B0E5439D8D207CB68F4 /* +DateTests.swift */; };
33071F1C64D4742E1F947FAA /* ItemDownloader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 33071D0E5913DB91DDDBDADB /* ItemDownloader.swift */; };
5F109D592AF6F50D00AE6AF3 /* ConditionalRedactedModifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F109D582AF6F50D00AE6AF3 /* ConditionalRedactedModifier.swift */; };
C93F99B6267554F00046F870 /* ItemCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = C93F99B5267554F00046F870 /* ItemCell.swift */; };
C93F99B8267557FC0046F870 /* ItemList.swift in Sources */ = {isa = PBXBuildFile; fileRef = C93F99B7267557FC0046F870 /* ItemList.swift */; };
C93F99BA267580CE0046F870 /* HTMLText.swift in Sources */ = {isa = PBXBuildFile; fileRef = C93F99B9267580CE0046F870 /* HTMLText.swift */; };
Expand Down Expand Up @@ -49,6 +50,7 @@
33071D0E5913DB91DDDBDADB /* ItemDownloader.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ItemDownloader.swift; sourceTree = "<group>"; };
33071E538EC434DF1A245518 /* HackerNewsClientTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HackerNewsClientTests.swift; sourceTree = "<group>"; };
33071EEBE46634E658582AE3 /* ItemTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ItemTests.swift; sourceTree = "<group>"; };
5F109D582AF6F50D00AE6AF3 /* ConditionalRedactedModifier.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConditionalRedactedModifier.swift; sourceTree = "<group>"; };
C93F99B5267554F00046F870 /* ItemCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ItemCell.swift; sourceTree = "<group>"; };
C93F99B7267557FC0046F870 /* ItemList.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ItemList.swift; sourceTree = "<group>"; };
C93F99B9267580CE0046F870 /* HTMLText.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HTMLText.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -190,6 +192,7 @@
C93F99B5267554F00046F870 /* ItemCell.swift */,
C93F99B7267557FC0046F870 /* ItemList.swift */,
C9926691267588B80035A88F /* Components */,
5F109D582AF6F50D00AE6AF3 /* ConditionalRedactedModifier.swift */,
);
path = View;
sourceTree = "<group>";
Expand Down Expand Up @@ -269,8 +272,9 @@
C9D0936B26741BBE002CC786 /* Project object */ = {
isa = PBXProject;
attributes = {
BuildIndependentTargetsInParallel = YES;
LastSwiftUpdateCheck = 1250;
LastUpgradeCheck = 1250;
LastUpgradeCheck = 1510;
TargetAttributes = {
C9D0937226741BBE002CC786 = {
CreatedOnToolsVersion = 12.5;
Expand Down Expand Up @@ -330,6 +334,7 @@
C9D0938026741BBF002CC786 /* Persistence.swift in Sources */,
C9D0937926741BBE002CC786 /* HomeView.swift in Sources */,
C93F99B6267554F00046F870 /* ItemCell.swift in Sources */,
5F109D592AF6F50D00AE6AF3 /* ConditionalRedactedModifier.swift in Sources */,
C93F99B8267557FC0046F870 /* ItemList.swift in Sources */,
C9E9BCFD2674C80E001B4E19 /* AppState.swift in Sources */,
C9E9BD032674D095001B4E19 /* User.swift in Sources */,
Expand Down Expand Up @@ -370,6 +375,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES;
CLANG_ANALYZER_NONNULL = YES;
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
Expand Down Expand Up @@ -400,9 +406,11 @@
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
DEAD_CODE_STRIPPING = YES;
DEBUG_INFORMATION_FORMAT = dwarf;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
ENABLE_USER_SCRIPT_SANDBOXING = YES;
GCC_C_LANGUAGE_STANDARD = gnu11;
GCC_DYNAMIC_NO_PIC = NO;
GCC_NO_COMMON_BLOCKS = YES;
Expand Down Expand Up @@ -431,6 +439,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES;
CLANG_ANALYZER_NONNULL = YES;
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
Expand Down Expand Up @@ -461,9 +470,11 @@
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
DEAD_CODE_STRIPPING = YES;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_USER_SCRIPT_SANDBOXING = YES;
GCC_C_LANGUAGE_STANDARD = gnu11;
GCC_NO_COMMON_BLOCKS = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
Expand All @@ -489,10 +500,11 @@
ASSETCATALOG_COMPILER_INCLUDE_ALL_APPICON_ASSETS = YES;
CODE_SIGN_ENTITLEMENTS = HNReader/HNReader.entitlements;
CODE_SIGN_IDENTITY = "Apple Development";
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "-";
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 1;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_ASSET_PATHS = "\"HNReader/Preview Content\"";
DEVELOPMENT_TEAM = H89RFW5UZ6;
ENABLE_HARDENED_RUNTIME = YES;
Expand Down Expand Up @@ -521,10 +533,11 @@
ASSETCATALOG_COMPILER_INCLUDE_ALL_APPICON_ASSETS = YES;
CODE_SIGN_ENTITLEMENTS = HNReader/HNReader.entitlements;
CODE_SIGN_IDENTITY = "Apple Development";
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "-";
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 1;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_ASSET_PATHS = "\"HNReader/Preview Content\"";
DEVELOPMENT_TEAM = H89RFW5UZ6;
ENABLE_HARDENED_RUNTIME = YES;
Expand Down Expand Up @@ -552,6 +565,7 @@
BUNDLE_LOADER = "$(TEST_HOST)";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_TEAM = H89RFW5UZ6;
INFOPLIST_FILE = HNReaderTests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
Expand All @@ -574,6 +588,7 @@
BUNDLE_LOADER = "$(TEST_HOST)";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_TEAM = H89RFW5UZ6;
INFOPLIST_FILE = HNReaderTests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
Expand Down
Binary file not shown.
4 changes: 3 additions & 1 deletion HNReader/HNReaderApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ struct HNReaderApp: App {
var body: some Scene {
WindowGroup {
HomeView()
.frame(minWidth: 800, maxWidth: .infinity, minHeight: 500, maxHeight: .infinity)
.onAppear {
displayMode = appState.getColorScheme()
}
.preferredColorScheme(displayMode)
.environmentObject(appState)

}

Settings {
Expand All @@ -45,7 +47,7 @@ struct HNReaderApp: App {
}
}
.frame(minHeight: 100)
.frame(minWidth: 300)
.frame(minWidth: 100)
.preferredColorScheme(displayMode)
}
}
Expand Down
5 changes: 5 additions & 0 deletions HNReader/Model/Item.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ public struct Item: Decodable {
}
}

public var scoreString: String? {
guard let score = score else { return nil }
return "\(score)"
}

public var timeStringRepresentation: String? {
Date().timeElapsedStringRepresentation(since: Date(timeIntervalSince1970: TimeInterval(time!)))
}
Expand Down
38 changes: 38 additions & 0 deletions HNReader/View/ConditionalRedactedModifier.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//
// ConditionalRedacted.swift
// HNReader
//
// Created by Mattia Righetti on 04/11/23.
//

import SwiftUI

struct ConditionalRedactedModifier: ViewModifier {
var isRedacted: Bool

func body(content: Content) -> some View {
if isRedacted {
content.redacted(reason: .placeholder)
} else {
content
}
}
}

extension View {
func redactIfNull(_ obj: Optional<Any>) -> some View {
switch obj {
case .none:
return self.modifier(ConditionalRedactedModifier(isRedacted: true))
case .some(_):
return self.modifier(ConditionalRedactedModifier(isRedacted: false))
}
}
}

#Preview {
VStack {
Text("Some Text").redactIfNull(Optional<String>.none)
}
.frame(width: 500, height: 500)
}
Loading

0 comments on commit 0007c9c

Please sign in to comment.