New Screen - Route Validation

This commit is contained in:
Michael Shanks 2020-02-25 10:01:07 +00:00
parent 4750309fed
commit b28f28a167
1 changed files with 25 additions and 10 deletions

View File

@ -21,30 +21,31 @@
let layoutComponent let layoutComponent
let screens let screens
let name = "" let name = ""
let route = ""
let saveAttempted = false let saveAttempted = false
store.subscribe(s => { $: layoutComponents = pipe(
layoutComponents = pipe( $store.components,
s.components,
[ [
filter(c => c.container), filter(c => c.container),
map(c => ({ name: c.name, ...splitName(c.name) })), map(c => ({ name: c.name, ...splitName(c.name) })),
] ]
) )
layoutComponent = layoutComponent $: layoutComponent = layoutComponent
? find(c => c.name === layoutComponent.name)(layoutComponents) ? find(c => c.name === layoutComponent.name)(layoutComponents)
: layoutComponents[0] : layoutComponents[0]
screens = s.screens $: screens = $store.screens
}) $: route = !route && screens.length === 0 ? "*" : route
const save = () => { const save = () => {
saveAttempted = true saveAttempted = true
const isValid = const isValid =
name.length > 0 && !screenNameExists(name) && layoutComponent name.length > 0 && !screenNameExists(name)
&& route.length > 0 && !routeNameExists(route)
&& layoutComponent
if (!isValid) return if (!isValid) return
@ -61,6 +62,19 @@
return s.name.toLowerCase() === name.toLowerCase() return s.name.toLowerCase() === name.toLowerCase()
})(screens) })(screens)
} }
const routeNameExists = route => {
return some(s => {
return s.route.toLowerCase() === route.toLowerCase()
})(screens)
}
const routeChanged = event => {
const r = event.target.value
if (!r.startsWith("/")) {
route = "/" + r
}
}
</script> </script>
<div bind:this={componentSelectorModal} id="new-component-modal" uk-modal> <div bind:this={componentSelectorModal} id="new-component-modal" uk-modal>
@ -86,8 +100,9 @@
<div class="uk-form-controls"> <div class="uk-form-controls">
<input <input
class="uk-input uk-form-small" class="uk-input uk-form-small"
class:uk-form-danger={saveAttempted && route.length === 0} class:uk-form-danger={saveAttempted && (route.length === 0 || routeNameExists(route))}
bind:value={route} /> bind:value={route}
on:change={routeChanged}/>
</div> </div>
</div> </div>