Skip to content

Commit

Permalink
fix: fix host url and link button for yc links
Browse files Browse the repository at this point in the history
  • Loading branch information
mattrighetti committed Nov 4, 2023
1 parent 56bd25d commit 239d04c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
Binary file not shown.
30 changes: 18 additions & 12 deletions HNReader/View/ItemCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@

import SwiftUI

func nullableString(_ s: String?) -> String {
guard let s = s else { return "" }
return s
}

struct ItemCell: View {
var itemId: Int
let itemDownloader: ItemDownloader
Expand All @@ -26,20 +31,22 @@ struct ItemCell: View {
.font(.custom("IBMPlexSerif-Bold", size: 17))
.redactIfNull(item)

Text(item?.urlHost ?? String(repeating: "-", count: 30))
.font(.custom("IBMPlexSerif-Light", size: 12))
.redactIfNull(item)
if let url = item?.urlHost {
Text(url)
.font(.custom("IBMPlexSerif-Light", size: 12))
.redactIfNull(item)
}

HStack {
Text(item?.scoreString ?? String(repeating: "-", count: 3))
Text(nullableString(item?.scoreString))
.font(.custom("IBMPlexSerif-SemiBold", size: 12))
.redactIfNull(item)

Text("Posted by \(item?.by ?? "?")")
Text("Posted by \(nullableString(item?.by))")
.font(.custom("IBMPlexSerif-Regular", size: 12))
.redactIfNull(item)

Text("\(item?.timeStringRepresentation ?? String(repeating: "-", count: 3))")
Text("\(nullableString(item?.timeStringRepresentation))")
.font(.custom("IBMPlexSerif-Regular", size: 12))
.redactIfNull(item)

Expand Down Expand Up @@ -85,24 +92,23 @@ struct ItemCell: View {
Label(title: {}, icon: {
Image(systemName: "arrow.up.right")
})
.foregroundStyle(.primary)
.foregroundStyle(item?.url != nil ? .primary : .tertiary)
.padding()
}
.frame(width: 50, height: 50)
.onHover { isHovered in
guard item?.url == nil else { return }
DispatchQueue.main.async {
if (isHovered) {
NSCursor.pointingHand.push()
NSCursor.operationNotAllowed.push()
} else {
NSCursor.pop()
}
}
}
.onTapGesture {
if let item = item {
guard let url = URL(string: item.url!) else { return }
NSWorkspace.shared.open(url)
}
guard let url = item?.url, let url = URL(string: url) else { return }
NSWorkspace.shared.open(url)
}
}.padding(.leading)
}
Expand Down

0 comments on commit 239d04c

Please sign in to comment.