Prevent duplicate bookmark names

This commit is contained in:
eikek
2022-01-10 00:36:57 +01:00
parent 54a4e6efee
commit ccb4df5bd7
7 changed files with 65 additions and 34 deletions

View File

@ -76,9 +76,11 @@ initWith bm =
isValid : Model -> Bool
isValid model =
Comp.PowerSearchInput.isValid model.queryModel
&& model.name
/= Nothing
List.all identity
[ Comp.PowerSearchInput.isValid model.queryModel
, model.name /= Nothing
, not model.nameExists
]
get : Model -> Maybe BookmarkedQuery
@ -116,14 +118,6 @@ update flags msg model =
nameCheck1 name =
Api.bookmarkNameExists flags name NameExistsResp
nameCheck2 =
case model.name of
Just n ->
Api.bookmarkNameExists flags n NameExistsResp
Nothing ->
Cmd.none
throttleSub =
Throttle.ifNeeded
(Time.every 150 (\_ -> UpdateThrottle))
@ -141,11 +135,7 @@ update flags msg model =
)
SetPersonal flag ->
let
( newThrottle, cmd ) =
Throttle.try nameCheck2 model.nameExistsThrottle
in
( { model | isPersonal = flag, nameExistsThrottle = newThrottle }, cmd, throttleSub )
( { model | isPersonal = flag }, Cmd.none, Sub.none )
QueryMsg lm ->
let
@ -218,7 +208,7 @@ view texts model =
]
[]
, span
[ class S.infoMessagePlain
[ class S.warnMessagePlain
, class "font-medium text-sm"
, classList [ ( "invisible", not model.nameExists ) ]
]

View File

@ -33,7 +33,7 @@ gb =
, userLocationText = "The bookmarked query is just for you"
, collectiveLocation = "Collective scope"
, collectiveLocationText = "The bookmarked query can be used and edited by all users"
, nameExistsWarning = "A bookmark with this name exists, it is overwritten on save!"
, nameExistsWarning = "A bookmark with this name exists!"
}
@ -45,5 +45,5 @@ de =
, userLocationText = "Der Bookmark ist nur für dich"
, collectiveLocation = "Kollektiv-Bookmark"
, collectiveLocationText = "Der Bookmark kann von allen Benutzer verwendet werden"
, nameExistsWarning = "Der Bookmark existiert bereits. Er wird beim Speichern überschrieben."
, nameExistsWarning = "Der Bookmark existiert bereits!"
}