mirror of
https://github.com/VGEAREN/Stockbar.git
synced 2026-10-06 14:33:11 +08:00
feat(settings): sort '我的股票' with held stocks first
Stocks with both costPrice and holdingShares set (effective values from real portfolio or active watchlist) appear at the top; the rest follow in original order. Makes managing larger watchlists easier.
This commit is contained in:
@@ -247,10 +247,10 @@ struct SettingsView: View {
|
||||
}
|
||||
}
|
||||
|
||||
// 已有股票
|
||||
// 已有股票:设置了持仓的排在前面,未设置持仓的在后
|
||||
if !appState.stocks.isEmpty {
|
||||
section("我的股票") {
|
||||
ForEach(appState.stocks) { s in stockRow(s) }
|
||||
ForEach(sortedStocksForSettings) { s in stockRow(s) }
|
||||
}
|
||||
}
|
||||
} // end else
|
||||
@@ -261,6 +261,22 @@ struct SettingsView: View {
|
||||
.frame(width: 284, height: 480)
|
||||
}
|
||||
|
||||
// MARK: - 排序辅助
|
||||
|
||||
/// 设置页"我的股票"排序:有持仓(成本 + 股数都设置了)的排在前面,
|
||||
/// 其它的排在后面;组内保持原顺序。
|
||||
private var sortedStocksForSettings: [Stock] {
|
||||
let withHolding = appState.stocks.filter {
|
||||
appState.effectiveCostPrice(for: $0) != nil
|
||||
&& appState.effectiveShares(for: $0) != nil
|
||||
}
|
||||
let withoutHolding = appState.stocks.filter {
|
||||
appState.effectiveCostPrice(for: $0) == nil
|
||||
|| appState.effectiveShares(for: $0) == nil
|
||||
}
|
||||
return withHolding + withoutHolding
|
||||
}
|
||||
|
||||
// MARK: - 子视图
|
||||
|
||||
@ViewBuilder
|
||||
|
||||
Reference in New Issue
Block a user