Skip to content

Commit

Permalink
Adjust main view footer to new model ✨
Browse files Browse the repository at this point in the history
  • Loading branch information
Freymaurer committed Dec 5, 2023
1 parent e2b32af commit fad0b26
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 20 deletions.
1 change: 1 addition & 0 deletions src/Client/Client.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<DefineConstants>FABLE_COMPILER</DefineConstants>
</PropertyGroup>
<ItemGroup>
<Compile Include="Helper.fs" />
<None Include="..\..\.editorconfig" Link=".editorconfig" />
<None Include="vite.config.mts" />
<None Include="paket.references" />
Expand Down
10 changes: 10 additions & 0 deletions src/Client/Helper.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[<AutoOpenAttribute>]
module Helper

open Fable.Core

let log (a) = Browser.Dom.console.log a

let logf a b =
let txt : string = sprintf a b
log txt
1 change: 0 additions & 1 deletion src/Client/Spreadsheet/Sidebar.Controller.fs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ let createTable (usePrevOutput:bool) (state: Spreadsheet.Model) : Spreadsheet.Mo
let tables = state.ArcFile.Value.Tables()
let newName = createNewTableName 0 tables.TableNames
let newTable = ArcTable.init(newName)
printfn "hit!"
if usePrevOutput && (tables.TableCount-1) >= state.ActiveTableIndex then
let table = tables.GetTableAt(state.ActiveTableIndex)
let output = table.GetOutputColumn()
Expand Down
42 changes: 24 additions & 18 deletions src/Client/Spreadsheet/Table.Controller.fs
Original file line number Diff line number Diff line change
Expand Up @@ -38,26 +38,32 @@ let renameTable (tableIndex:int) (newName: string) (state: Spreadsheet.Model) :
{state with ArcFile = state.ArcFile}

let removeTable (removeIndex: int) (state: Spreadsheet.Model) : Spreadsheet.Model =
state.Tables.RemoveTableAt removeIndex
// If the only existing table was removed init model from beginning
if state.Tables.TableCount = 0 then
Spreadsheet.Model.init()
if state.Tables.TableCount = 0 then
state
else
// if active table is removed get the next closest table and set it active
if state.ActiveTableIndex = removeIndex then
let nextTable_Index =
let neighbors = findNeighborTables removeIndex state.Tables
match neighbors with
| Some (i, _), _ -> i
| None, Some (i, _) -> i
// This is a fallback option, which should never be hit
| _ -> 0
{ state with
ArcFile = state.ArcFile
ActiveTableIndex = nextTable_Index }
// Tables still exist and an inactive one was removed. Just remove it.
state.Tables.RemoveTableAt removeIndex
// If the only existing table was removed init model from beginning
if state.Tables.TableCount = 0 then
Spreadsheet.Model.init()
else
{state with ArcFile = state.ArcFile}
// if active table is removed get the next closest table and set it active
if state.ActiveTableIndex = removeIndex then
let nextTable_Index =
let neighbors = findNeighborTables removeIndex state.Tables
match neighbors with
| Some (i, _), _ -> i
| None, Some (i, _) -> i
// This is a fallback option, which should never be hit
| _ -> 0
{ state with
ArcFile = state.ArcFile
ActiveTableIndex = nextTable_Index }
// Tables still exist and an inactive one was removed. Just remove it.
else
let nextTable_Index = if state.ActiveTableIndex > removeIndex then state.ActiveTableIndex - 1 else state.ActiveTableIndex
{ state with
ArcFile = state.ArcFile
ActiveTableIndex = nextTable_Index }

///<summary>Add `n` rows to active table.</summary>
let addRows (n: int) (state: Spreadsheet.Model) : Spreadsheet.Model =
Expand Down
1 change: 1 addition & 0 deletions src/Client/Update/SpreadsheetUpdate.fs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ module Spreadsheet =
ActiveTableIndex = nextIndex }
state, model, cmd
| RemoveTable removeIndex ->
logf "RemoveTable: %i" removeIndex
let cmd = createPromiseCmd <| fun _ -> Controller.removeTable removeIndex state
state, model, cmd
| RenameTable (index, name) ->
Expand Down
2 changes: 1 addition & 1 deletion src/Client/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,6 @@
<script type="text/javascript">
var global = global || window;
</script>
<script type="module" src="/output/Client.js"></script>
<script type="module" src="/output/Client.fs.js"></script>
</body>
</html>

0 comments on commit fad0b26

Please sign in to comment.