okay so working when you manually save ribbon

need to make it save position when you switch ribbon instead of manual save
but good progress
undo
saint 2024-05-28 16:15:07 -04:00
parent 14e1bec9e5
commit 168a057a2a
4 changed files with 14 additions and 7 deletions

View File

@ -17,7 +17,7 @@ struct SelectedRibbon: Identifiable, Equatable {
/// Int64 is the recommended type for auto-incremented database ids.
/// Use nil for players that are not inserted yet in the database.
var id: Int64?
var ribbonId: Int64
var ribbonGroupId: Int64
}
extension SelectedRibbon {
@ -32,7 +32,7 @@ extension SelectedRibbon: Codable, FetchableRecord, MutablePersistableRecord {
// Define database columns from CodingKeys
fileprivate enum Columns {
static let id = Column(CodingKeys.id)
static let ribbonId = Column(CodingKeys.ribbonId)
static let ribbonGroupId = Column(CodingKeys.ribbonGroupId)
}
/// Updates a player id after it has been inserted in the database.

View File

@ -52,8 +52,15 @@ struct SelectedRibbonRequest: Queryable {
// print(ret3)
// print("FETCH JOIN RIBBON")
var ret = try Ribbon.fetchAll(db, sql: "SELECT Ribbon.* FROM SelectedRibbon join Ribbon on SelectedRibbon.ribbonId = ribbon.rowId WHERE SelectedRibbon.rowId = 1") // [Player]
// print(ret)
var ret = try Ribbon.fetchAll(db, sql: """
SELECT Ribbon.* FROM SelectedRibbon \
JOIN (select distinct r1.* from Ribbon r1 join Ribbon r2 ON \
r1.undoLevel = r2.currentLevel AND r1.id = r2.id ORDER BY pos ASC) as Ribbon \
ON SelectedRibbon.ribbonGroupId = Ribbon.groupId \
WHERE SelectedRibbon.rowId = 1
""")
// [Player]
print("Selected Ribbon query result: \(ret)")
return ret
}
}

View File

@ -69,7 +69,7 @@ struct AppDatabase {
try db.create(table: "SelectedRibbon") { t in
t.autoIncrementedPrimaryKey("id")
t.column("ribbonId", .integer).notNull()
t.column("ribbonGroupId", .integer).notNull()
}
try db.create(table: "ScrollState") { t in
@ -394,7 +394,7 @@ extension AppDatabase {
scrollId: "1",
scrollOffset: 0).inserted(db)
_ = try SelectedRibbon(id: 1, ribbonId: 1).inserted(db)
_ = try SelectedRibbon(id: 1, ribbonGroupId: 1).inserted(db)
}
}
} catch {

View File

@ -74,7 +74,7 @@ func goToRibbon(selectedRibbon: Ribbon,
refresh.wrappedValue.toggle()
var updateSelectRibbon = SelectedRibbon(id: Int64(1), ribbonId: destRibbon.id!)
var updateSelectRibbon = SelectedRibbon(id: Int64(1), ribbonGroupId: Int64(destRibbon.groupId))
// print("Saving selected ribbon")
// print(updateSelectRibbon)
do {