Skip to content

Commit

Permalink
Undo changes to pagestate
Browse files Browse the repository at this point in the history
  • Loading branch information
Etschbeijer committed Dec 19, 2024
1 parent 4f0359c commit 31a0d13
Show file tree
Hide file tree
Showing 13 changed files with 52 additions and 44 deletions.
2 changes: 1 addition & 1 deletion src/Client/Index.fs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ let View (model : Model) (dispatch : Msg -> unit) =
prop.className "flex w-full overflow-auto h-screen"
prop.children [
Modals.ModalProvider.Main(model, dispatch)
match model.ProtocolState.IsHome, model.PersistentStorageState.Host with
match model.PageState.IsHome, model.PersistentStorageState.Host with
| false, _ ->
View.MainPageView.Main(model, dispatch)
| _, Some Swatehost.Excel ->
Expand Down
1 change: 1 addition & 0 deletions src/Client/Init.fs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ open Update

let initialModel =
{
PageState = PageState .init()
PersistentStorageState = PersistentStorageState .init()
DevState = DevState .init()
TermSearchState = TermSearch.Model .init()
Expand Down
2 changes: 1 addition & 1 deletion src/Client/MainComponents/Widgets.fs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ type Widget =

let content =
let switchContent =
if model.ProtocolState.TemplatesSelected.Length > 0 && model.ProtocolState.WidgetTypes = Routing.WidgetTypes.Protocol then
if model.ProtocolState.TemplatesSelected.Length > 0 && model.PageState.SidebarPage = Routing.SidebarPage.Protocol then
insertContent()
else selectContent()
Html.div [
Expand Down
24 changes: 16 additions & 8 deletions src/Client/Model.fs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,20 @@ type PersistentStorageState = {
HasOntologiesLoaded = false
}

type PageState = {
SidebarPage : Routing.SidebarPage
MainPage: Routing.MainPage
} with
static member init () =
{
SidebarPage = SidebarPage.BuildingBlock
MainPage = MainPage.Default
}
member this.IsHome =
match this.MainPage with
| MainPage.Default -> true
| _ -> false

module FilePicker =
type Model = {
FileNames : (int*string) list
Expand Down Expand Up @@ -234,8 +248,6 @@ module Protocol =
// ------ Protocol from Database ------
TemplatesSelected : ARCtrl.Template list
Templates : ARCtrl.Template []
WidgetTypes : Routing.WidgetTypes
MainPage : Routing.MainPage
} with
static member init () = {
// Client
Expand All @@ -244,13 +256,7 @@ module Protocol =
TemplatesSelected = []
// ------ Protocol from Database ------
Templates = [||]
WidgetTypes = WidgetTypes.BuildingBlock
MainPage = MainPage.Default
}
member this.IsHome =
match this.MainPage with
| MainPage.Default -> true
| _ -> false

type RequestBuildingBlockInfoStates =
| Inactive
Expand All @@ -263,6 +269,8 @@ type RequestBuildingBlockInfoStates =
| RequestDataBaseInformation -> "Search Database "

type Model = {
///PageState
PageState : PageState
///Data that needs to be persistent once loaded
PersistentStorageState : PersistentStorageState
///Error handling, Logging, etc.
Expand Down
2 changes: 1 addition & 1 deletion src/Client/Pages/FilePicker/FilePickerView.fs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ let update (filePickerMsg:FilePicker.Msg) (state: FilePicker.Model) (model: Mode
let nextModel = {
model with
Model.FilePickerState.FileNames = fileNames |> List.mapi (fun i x -> i + 1, x)
Model.ProtocolState.WidgetTypes = Routing.WidgetTypes.FilePicker
Model.PageState.SidebarPage = Routing.SidebarPage.FilePicker
}
let nextCmd = UpdateModel nextModel|> Cmd.ofMsg
state, nextCmd
Expand Down
8 changes: 4 additions & 4 deletions src/Client/Pages/ProtocolTemplates/ProtocolSearch.fs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ module private HelperProtocolSearch =
prop.children [
Html.ul [
Html.li [Html.a [
prop.onClick (fun _ -> UpdateModel {model with Model.ProtocolState.WidgetTypes = Routing.WidgetTypes.Protocol} |> dispatch)
prop.text (Routing.WidgetTypes.Protocol.AsStringRdbl)
prop.onClick (fun _ -> UpdateModel {model with Model.PageState.SidebarPage = Routing.SidebarPage.Protocol} |> dispatch)
prop.text (Routing.SidebarPage.Protocol.AsStringRdbl)
]]
Html.li [
prop.className "is-active"
prop.children (Html.a [
prop.onClick (fun _ -> UpdateModel {model with Model.ProtocolState.WidgetTypes = Routing.WidgetTypes.ProtocolSearch} |> dispatch)
prop.text (Routing.WidgetTypes.ProtocolSearch.AsStringRdbl)
prop.onClick (fun _ -> UpdateModel {model with Model.PageState.SidebarPage = Routing.SidebarPage.ProtocolSearch} |> dispatch)
prop.text (Routing.SidebarPage.ProtocolSearch.AsStringRdbl)
])
]
]
Expand Down
3 changes: 1 addition & 2 deletions src/Client/Pages/ProtocolTemplates/ProtocolState.fs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ module Protocol =
let nextModel = {
model with
Model.ProtocolState.TemplatesSelected = prots
Model.ProtocolState.WidgetTypes = Routing.WidgetTypes.Protocol
Model.PageState.SidebarPage = Routing.SidebarPage.Protocol
}
state, Cmd.ofMsg (UpdateModel nextModel)
| AddProtocol prot ->
Expand All @@ -70,7 +70,6 @@ module Protocol =
let nextState = {
state with
TemplatesSelected = templates
WidgetTypes = Routing.WidgetTypes.ProtocolSearch
}
nextState, Cmd.none
| ProtocolIncreaseTimesUsed templateId ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type SelectiveTemplateFromDB =
/// <param name="dispatch"></param>
static member ToProtocolSearchElement(model: Model) dispatch =
Daisy.button.button [
prop.onClick(fun _ -> UpdateModel {model with Model.ProtocolState.WidgetTypes = Routing.WidgetTypes.ProtocolSearch} |> dispatch)
prop.onClick(fun _ -> UpdateModel {model with Model.PageState.SidebarPage = Routing.SidebarPage.ProtocolSearch} |> dispatch)
button.primary
button.block
prop.text "Browse database"
Expand Down
2 changes: 1 addition & 1 deletion src/Client/Routing.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ open Elmish.UrlParser
open Feliz

[<RequireQualifiedAccess>]
type WidgetTypes =
type SidebarPage =
| BuildingBlock
| TermSearch
| FilePicker
Expand Down
2 changes: 1 addition & 1 deletion src/Client/SharedComponents/NavbarBurger.fs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ type NavbarBurger =
[<ReactComponent>]
static member private Dropdown(isOpen, setIsOpen, model: Model.Model, dispatch) =

let navigateTo = fun (mainPage: Routing.MainPage) -> {model with Model.ProtocolState.MainPage = mainPage} |> Messages.UpdateModel |> dispatch
let navigateTo = fun (mainPage: Routing.MainPage) -> {model with Model.PageState.MainPage = mainPage} |> Messages.UpdateModel |> dispatch
Components.BaseDropdown.Main(
isOpen,
setIsOpen,
Expand Down
18 changes: 9 additions & 9 deletions src/Client/SidebarComponents/Tabs.fs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ open Feliz.DaisyUI

type Tabs =

static member private NavigationTab (pageLink: Routing.WidgetTypes) (model:Model) (dispatch:Msg-> unit) =
let isActive = pageLink = model.ProtocolState.WidgetTypes
static member private NavigationTab (pageLink: Routing.SidebarPage) (model:Model) (dispatch:Msg-> unit) =
let isActive = pageLink = model.PageState.SidebarPage
Daisy.tab [
if isActive then tab.active
prop.className "navigation" // this class does not do anything, but disables <a> styling.
prop.onClick (fun e -> e.preventDefault(); UpdateModel { model with Model.ProtocolState.WidgetTypes = pageLink } |> dispatch)
prop.onClick (fun e -> e.preventDefault(); UpdateModel { model with Model.PageState.SidebarPage = pageLink } |> dispatch)
prop.children (pageLink.AsIcon())
]

Expand All @@ -25,11 +25,11 @@ type Tabs =
tabs.boxed
prop.className "w-full"
prop.children [
Tabs.NavigationTab Routing.WidgetTypes.BuildingBlock model dispatch
Tabs.NavigationTab Routing.WidgetTypes.TermSearch model dispatch
Tabs.NavigationTab Routing.WidgetTypes.Protocol model dispatch
Tabs.NavigationTab Routing.WidgetTypes.FilePicker model dispatch
Tabs.NavigationTab Routing.WidgetTypes.DataAnnotator model dispatch
Tabs.NavigationTab Routing.WidgetTypes.JsonExport model dispatch
Tabs.NavigationTab Routing.SidebarPage.BuildingBlock model dispatch
Tabs.NavigationTab Routing.SidebarPage.TermSearch model dispatch
Tabs.NavigationTab Routing.SidebarPage.Protocol model dispatch
Tabs.NavigationTab Routing.SidebarPage.FilePicker model dispatch
Tabs.NavigationTab Routing.SidebarPage.DataAnnotator model dispatch
Tabs.NavigationTab Routing.SidebarPage.JsonExport model dispatch
]
]
14 changes: 7 additions & 7 deletions src/Client/Views/MainPageViews.fs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ open MainPageUtil
type MainPageView =

static member DrawerSideContentItem (model: Model.Model, route: Routing.MainPage, onclick) =
let isActive = model.ProtocolState.MainPage = route
let isActive = model.PageState.MainPage = route
Html.li [
prop.onClick onclick
prop.children [
Expand All @@ -35,7 +35,7 @@ type MainPageView =
prop.ariaLabel "Back to spreadsheet view"
button.link
button.sm
prop.onClick (fun _ -> UpdateModel {model with Model.ProtocolState.MainPage = Routing.MainPage.Default} |> dispatch)
prop.onClick (fun _ -> UpdateModel {model with Model.PageState.MainPage = Routing.MainPage.Default} |> dispatch)
prop.children [
Html.i [prop.className "fa-solid fa-arrow-left"]
Html.span "Back"
Expand All @@ -44,9 +44,9 @@ type MainPageView =
Html.ul [
prop.className "menu gap-y-1"
prop.children [
MainPageView.DrawerSideContentItem(model, Routing.MainPage.Settings, fun _ -> UpdateModel {model with Model.ProtocolState.MainPage = Routing.MainPage.Settings} |> dispatch)
MainPageView.DrawerSideContentItem(model, Routing.MainPage.About, fun _ -> UpdateModel {model with Model.ProtocolState.MainPage = Routing.MainPage.About} |> dispatch)
MainPageView.DrawerSideContentItem(model, Routing.MainPage.PrivacyPolicy, fun _ -> UpdateModel {model with Model.ProtocolState.MainPage = Routing.MainPage.PrivacyPolicy} |> dispatch)
MainPageView.DrawerSideContentItem(model, Routing.MainPage.Settings, fun _ -> UpdateModel {model with Model.PageState.MainPage = Routing.MainPage.Settings} |> dispatch)
MainPageView.DrawerSideContentItem(model, Routing.MainPage.About, fun _ -> UpdateModel {model with Model.PageState.MainPage = Routing.MainPage.About} |> dispatch)
MainPageView.DrawerSideContentItem(model, Routing.MainPage.PrivacyPolicy, fun _ -> UpdateModel {model with Model.PageState.MainPage = Routing.MainPage.PrivacyPolicy} |> dispatch)
]
]
]
Expand Down Expand Up @@ -78,7 +78,7 @@ type MainPageView =

Html.div [
prop.ariaLabel "logo"
prop.onClick (fun _ -> UpdateModel {model with Model.ProtocolState.MainPage = Routing.MainPage.Default} |> dispatch)
prop.onClick (fun _ -> UpdateModel {model with Model.PageState.MainPage = Routing.MainPage.Default} |> dispatch)
prop.className "cursor-pointer"
prop.children [
Html.img [
Expand All @@ -90,7 +90,7 @@ type MainPageView =
]

static member MainContent(model: Model.Model, dispatch) =
match model.ProtocolState.MainPage with
match model.PageState.MainPage with
| Routing.MainPage.Settings ->
Pages.Settings.Main(model, dispatch)
| Routing.MainPage.About ->
Expand Down
16 changes: 8 additions & 8 deletions src/Client/Views/SidebarView.fs
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,26 @@ type SidebarView =
Html.div [
prop.className "grow overflow-y-auto"
prop.children [
match model.ProtocolState with
| {WidgetTypes = Routing.WidgetTypes.BuildingBlock } ->
match model.PageState with
| {SidebarPage = Routing.SidebarPage.BuildingBlock } ->
BuildingBlock.Core.addBuildingBlockComponent model dispatch

| {WidgetTypes = Routing.WidgetTypes.TermSearch } ->
| {SidebarPage = Routing.SidebarPage.TermSearch } ->
TermSearch.Main (model, dispatch)

| {WidgetTypes = Routing.WidgetTypes.FilePicker } ->
| {SidebarPage = Routing.SidebarPage.FilePicker } ->
FilePicker.filePickerComponent model dispatch

| {WidgetTypes = Routing.WidgetTypes.Protocol } ->
| {SidebarPage = Routing.SidebarPage.Protocol } ->
Protocol.Templates.Main (model, dispatch)

| {WidgetTypes = Routing.WidgetTypes.DataAnnotator } ->
| {SidebarPage = Routing.SidebarPage.DataAnnotator } ->
Pages.DataAnnotator.Main(model, dispatch)

| {WidgetTypes = Routing.WidgetTypes.JsonExport } ->
| {SidebarPage = Routing.SidebarPage.JsonExport } ->
JsonExporter.Core.FileExporter.Main(model, dispatch)

| {WidgetTypes = Routing.WidgetTypes.ProtocolSearch } ->
| {SidebarPage = Routing.SidebarPage.ProtocolSearch } ->
Protocol.SearchContainer.Main model dispatch
]
]
Expand Down

0 comments on commit 31a0d13

Please sign in to comment.