Skip to content

Commit

Permalink
Merge pull request #144 from kyasu1/change-shared-msg-handling
Browse files Browse the repository at this point in the history
Add hasActionTypeChanged to prevent unintentional page reoads
  • Loading branch information
ryan-haskell committed Oct 6, 2023
2 parents 3da079a + 313b2ef commit 513ad4f
Showing 1 changed file with 41 additions and 1 deletion.
42 changes: 41 additions & 1 deletion projects/cli/src/codegen/src/Commands/Generate.elm
Expand Up @@ -565,7 +565,7 @@ mainElmModule data =
]
, in_ =
CodeGen.Expression.ifElse
{ condition = CodeGen.Expression.value "isAuthProtected (Route.fromUrl () model.url).path && oldAction /= newAction"
{ condition = CodeGen.Expression.value "isAuthProtected (Route.fromUrl () model.url).path && (hasActionTypeChanged oldAction newAction)"
, ifBranch =
CodeGen.Expression.letIn
{ let_ =
Expand Down Expand Up @@ -660,6 +660,7 @@ mainElmModule data =
}
, toLayoutFromPageDeclaration data.pages
, toAuthProtectedPageDeclaration
, hasActionTypeChangedDeclaration
, CodeGen.Declaration.function
{ name = "subscriptions"
, annotation =
Expand Down Expand Up @@ -1235,6 +1236,45 @@ toAuthProtectedPageDeclaration =
}


hasActionTypeChangedDeclaration : CodeGen.Declaration
hasActionTypeChangedDeclaration =
CodeGen.Declaration.function
{ name = "hasActionTypeChanged"
, annotation = CodeGen.Annotation.type_ "Auth.Action.Action user -> Auth.Action.Action user -> Bool"
, arguments = [ CodeGen.Argument.new "oldAction", CodeGen.Argument.new "newAction" ]
, expression =
CodeGen.Expression.caseExpression
{ value = CodeGen.Argument.new "( newAction, oldAction )"
, branches =
[ { name = "( Auth.Action.LoadPageWithUser _, Auth.Action.LoadPageWithUser _ )"
, arguments = []
, expression = CodeGen.Expression.value "False"
}
, { name = "( Auth.Action.ShowLoadingPage _, Auth.Action.ShowLoadingPage _ )"
, arguments = []
, expression = CodeGen.Expression.value "False"
}
, { name = "( Auth.Action.ReplaceRoute _, Auth.Action.ReplaceRoute _ )"
, arguments = []
, expression = CodeGen.Expression.value "False"
}
, { name = "( Auth.Action.PushRoute _, Auth.Action.PushRoute _ )"
, arguments = []
, expression = CodeGen.Expression.value "False"
}
, { name = "( Auth.Action.LoadExternalUrl _, Auth.Action.LoadExternalUrl _ )"
, arguments = []
, expression = CodeGen.Expression.value "False"
}
, { name = "( _, _ )"
, arguments = []
, expression = CodeGen.Expression.value "True"
}
]
}
}


toPageMsgCustomType : List PageFile -> List ( String, List CodeGen.Annotation )
toPageMsgCustomType pages =
let
Expand Down

0 comments on commit 513ad4f

Please sign in to comment.