explorer: fix loading null settings from localStorage

This commit is contained in:
Christophe de Vienne 2021-06-14 16:39:15 +02:00
parent e202ab1106
commit 789b73b518
3 changed files with 91 additions and 60 deletions

View File

@ -17032,7 +17032,10 @@ var $author$project$UIExplorer$Settings = function (dark) {
}; };
var $elm$json$Json$Decode$bool = _Json_decodeBool; var $elm$json$Json$Decode$bool = _Json_decodeBool;
var $elm$json$Json$Decode$decodeString = _Json_runOnString; var $elm$json$Json$Decode$decodeString = _Json_runOnString;
var $author$project$UIExplorer$decodeSettings = A2( var $author$project$UIExplorer$decodeSettings = $elm$json$Json$Decode$oneOf(
_List_fromArray(
[
A2(
$elm$json$Json$Decode$field, $elm$json$Json$Decode$field,
'settings', 'settings',
A2( A2(
@ -17043,17 +17046,26 @@ var $author$project$UIExplorer$decodeSettings = A2(
A2( A2(
$elm$json$Json$Decode$map, $elm$json$Json$Decode$map,
$author$project$UIExplorer$Settings, $author$project$UIExplorer$Settings,
A2($elm$json$Json$Decode$field, 'dark', $elm$json$Json$Decode$bool)), $elm$json$Json$Decode$oneOf(
_List_fromArray(
[
A2($elm$json$Json$Decode$field, 'dark', $elm$json$Json$Decode$bool),
$elm$json$Json$Decode$succeed(true)
]))),
s); s);
if (!_v0.$) { if (!_v0.$) {
var settings = _v0.a; var settings = _v0.a;
return $elm$json$Json$Decode$succeed(settings); return $elm$json$Json$Decode$succeed(settings);
} else { } else {
return $elm$json$Json$Decode$succeed( var err = _v0.a;
{a1: false}); return $elm$json$Json$Decode$fail(
$elm$json$Json$Decode$errorToString(err));
} }
}, },
$elm$json$Json$Decode$string)); $elm$json$Json$Decode$string)),
$elm$json$Json$Decode$succeed(
{a1: false})
]));
var $author$project$Main$decodeFlags = A3( var $author$project$Main$decodeFlags = A3(
$elm$json$Json$Decode$map2, $elm$json$Json$Decode$map2,
$author$project$Main$Flags, $author$project$Main$Flags,

View File

@ -17032,7 +17032,10 @@ var $author$project$UIExplorer$Settings = function (dark) {
}; };
var $elm$json$Json$Decode$bool = _Json_decodeBool; var $elm$json$Json$Decode$bool = _Json_decodeBool;
var $elm$json$Json$Decode$decodeString = _Json_runOnString; var $elm$json$Json$Decode$decodeString = _Json_runOnString;
var $author$project$UIExplorer$decodeSettings = A2( var $author$project$UIExplorer$decodeSettings = $elm$json$Json$Decode$oneOf(
_List_fromArray(
[
A2(
$elm$json$Json$Decode$field, $elm$json$Json$Decode$field,
'settings', 'settings',
A2( A2(
@ -17043,17 +17046,26 @@ var $author$project$UIExplorer$decodeSettings = A2(
A2( A2(
$elm$json$Json$Decode$map, $elm$json$Json$Decode$map,
$author$project$UIExplorer$Settings, $author$project$UIExplorer$Settings,
A2($elm$json$Json$Decode$field, 'dark', $elm$json$Json$Decode$bool)), $elm$json$Json$Decode$oneOf(
_List_fromArray(
[
A2($elm$json$Json$Decode$field, 'dark', $elm$json$Json$Decode$bool),
$elm$json$Json$Decode$succeed(true)
]))),
s); s);
if (!_v0.$) { if (!_v0.$) {
var settings = _v0.a; var settings = _v0.a;
return $elm$json$Json$Decode$succeed(settings); return $elm$json$Json$Decode$succeed(settings);
} else { } else {
return $elm$json$Json$Decode$succeed( var err = _v0.a;
{a1: false}); return $elm$json$Json$Decode$fail(
$elm$json$Json$Decode$errorToString(err));
} }
}, },
$elm$json$Json$Decode$string)); $elm$json$Json$Decode$string)),
$elm$json$Json$Decode$succeed(
{a1: false})
]));
var $author$project$Main$decodeFlags = A3( var $author$project$Main$decodeFlags = A3(
$elm$json$Json$Decode$map2, $elm$json$Json$Decode$map2,
$author$project$Main$Flags, $author$project$Main$Flags,

View File

@ -69,23 +69,30 @@ type alias Settings =
decodeSettings : Decode.Decoder Settings decodeSettings : Decode.Decoder Settings
decodeSettings = decodeSettings =
Decode.string Decode.oneOf
[ Decode.string
|> Decode.andThen |> Decode.andThen
(\s -> (\s ->
case case
Decode.decodeString Decode.decodeString
(Decode.map Settings (Decode.map Settings
(Decode.field "dark" Decode.bool) (Decode.oneOf
[ Decode.field "dark" Decode.bool
, Decode.succeed True
]
)
) )
s s
of of
Ok settings -> Ok settings ->
Decode.succeed settings Decode.succeed settings
Err _ -> Err err ->
Decode.succeed { dark = False } Decode.fail <| Decode.errorToString err
) )
|> Decode.field "settings" |> Decode.field "settings"
, Decode.succeed { dark = False }
]
saveSettings : Settings -> Cmd msg saveSettings : Settings -> Cmd msg