sebastiangreger / kirby3-commentions

A versatile comment system and integrated Webmention endpoint for Kirby 3.
MIT License
58 stars 7 forks source link

Jump to anchor after submission #99

Closed getflourish closed 1 year ago

getflourish commented 3 years ago

After a submission, it would be nice to jump to the comments section.

This could be done, e.g. by adjusting the form action in commentions-form.php

<form action="<?= $page->url() ?>#commentions" method="post" <?= option('sgkirby.commentions.hideforms') ? 'class="expandertarget"' : '' ?>>

But it would require an id on the commentions-list.

getflourish commented 3 years ago

Ah, now see that the feedback is recommended to placed on the top of the page. Then the default behaviour makes sense. I actually placed the feedback with the form below the post. So maybe this issue can be seen as an option or just ignored. :)

sebastiangreger commented 3 years ago

Thanks for pointing out your use case!

I'll keep this in mind in combination with #96 ...display preferences after submission are quite obviously more diverse than what the current design enables and I consider it worth a try to accommodate them as flexibly as possible.

sebastiangreger commented 3 years ago

This, too, is now possible in the Commentions 2.0 beta 1.

See the documentation at https://github.com/sebastiangreger/kirby3-commentions/tree/develop#frontend-helper ...you'd have to add an id attribute to the helper for the feedback section and a jump (or jump-success and jump-error) attribute to the form helper.

This is all beta still; feedback and bug reports are most welcome :slightly_smiling_face:

MaluNoPeleke commented 3 years ago

I have played around and found this setup the best for my case:

    <?php
        commentions('feedback', ['class' => 'pt-[3.75rem] !mt-[-3.75rem]', 'id' => 'formfeedbacksuccess']);
        commentions('list', ['grouped' => true]);
        echo "<hr>";
        commentions('feedback', ['class' => 'pt-[3.75rem] !mt-[-3.75rem]', 'id' => 'formfeedbackerror']);
        commentions('form', ['class' => 'rounded-lg', 'collapse-webmentions' => false, 'jump-error' => 'formfeedbackerror', 'jump-success' => 'formfeedbacksuccess']);
    ?>

The only issue with this is that on a successful comment submit the feedback gets displayed twice. Is there a way to avoid that?

sebastiangreger commented 3 years ago

Hmm, having the feedback element twice on one page is a use case not currently considered. You're essentially after a "conditional" feedback element… I'll keep this in mind in future considerations.

Untested, but I imagine that this workaround should work:

if (get('thx')) {
    commentions('feedback', ['class' => 'pt-[3.75rem] !mt-[-3.75rem]', 'id' => 'formfeedbacksuccess']);
}
...
if (!get('thx')) {
    commentions('feedback', ['class' => 'pt-[3.75rem] !mt-[-3.75rem]', 'id' => 'formfeedbackerror']);
}
...

It makes use of the fact that a success message is always tied to ?thx=xyz present in the URL as the page is called.

MaluNoPeleke commented 3 years ago

Thanks, all your code snippets work as desired :)

sebastiangreger commented 1 year ago

@getflourish @MaluNoPeleke I hope you don't mind me pinging you here in a slightly off-topic manner, but I'd like to draw your attention to my update that I am no longer able to maintain the Commentions plugin in the future → details here.