Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemenatation of chooseRadio function along with tests #1840

Closed
wants to merge 3 commits into from

Conversation

chrissound
Copy link

@chrissound chrissound commented Jul 29, 2024

Before submitting your PR, check that you've:

After submitting your PR:

  • Update the Changelog.md file with a link to your PR
  • Check that CI passes (or if it fails, for reasons unrelated to your change, like CI timeouts)

I've been asked to upstream this work, so here it is! It's basically a helper function to make it easier to set radio form inputs.

Copy link
Member

@jezen jezen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an excellent addition the the library, though I think we ought to tidy up some minor details first.

Comment on lines 969 to 970
-- > <label for="color-red">Red</label>
-- > <input id="color-red" name="color" value="Red" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think typical radio input markup should look like this:

<input id="color-red" name="color" value="red">
<label for="color-red">Red</label>

i.e., the input should come before the label. Also, self-closing tags don't need a trailing slash.

-- @since 1.6.17
chooseRadio :: T.Text -- ^ The text contained within the @\<label>@.
-> RequestBuilder site ()
chooseRadio v = do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think v could be a better name. Perhaps labelText?

Comment on lines 984 to 988
mres <- fmap rbdResponse getSIO
res <-
case mres of
Nothing -> failure "chooseRadio: No response available"
Just res -> return res
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you're only using mres in one place, you may as well inline it.

Suggested change
mres <- fmap rbdResponse getSIO
res <-
case mres of
Nothing -> failure "chooseRadio: No response available"
Just res -> return res
res <- case rbdResponse <$> getSIO of
Nothing -> failure "chooseRadio: No response available"
Just res -> pure res

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pretty sure this can't be inlined unless using LamdbdaCase >>= \case? Otherwise we need >>= (\v -> case v of ...) but I think that is less readable but happy to do that if preferred.

case mres of
Nothing -> failure "chooseRadio: No response available"
Just res -> return res
let body = simpleBody res
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar deal here — this binding is only used once, so it may as well be inlined below.

Just res -> return res
let body = simpleBody res

let name = genericNameFromHTML (==) (v) body
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless my eyes (and brain) are failing me, I think the parentheses are redundant here.

Suggested change
let name = genericNameFromHTML (==) (v) body
let name = genericNameFromHTML (==) labelText (simpleBody res)

Comment on lines 993 to 994
Right name' -> addPostParam name' $ v
Left e -> failure $ e
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function application operators are redundant in both cases. Also, let's try to use slightly more descriptive names 🙂

Suggested change
Right name' -> addPostParam name' $ v
Left e -> failure $ e
Right name' -> addPostParam name' labelText
Left err -> failure err

@chrissound
Copy link
Author

Thanks, will try sort this all out later today.

@jezen
Copy link
Member

jezen commented Aug 15, 2024

Closing this in favour of #1842.

@jezen jezen closed this Aug 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants