diff --git a/app/main/routes.py b/app/main/routes.py index ee09024..5d698cf 100644 --- a/app/main/routes.py +++ b/app/main/routes.py @@ -82,6 +82,14 @@ def user(username): next_url=next_url, prev_url=prev_url, form=form) +@bp.route('/user//popup') +@login_required +def user_popup(username): + user = User.query.filter_by(username=username).first_or_404() + form = EmptyForm() + return render_template('user_popup.html', user=user, form=form) + + @bp.route('/edit_profile', methods=['GET', 'POST']) @login_required def edit_profile(): diff --git a/app/templates/_post.html b/app/templates/_post.html index 8c0a9cd..2a1c697 100644 --- a/app/templates/_post.html +++ b/app/templates/_post.html @@ -7,7 +7,7 @@ {% set user_link %} - + {{ post.author.username }} {% endset %} diff --git a/app/templates/base.html b/app/templates/base.html index 5a66063..4d89cd9 100644 --- a/app/templates/base.html +++ b/app/templates/base.html @@ -79,6 +79,36 @@ const data = await response.json(); document.getElementById(destElem).innerText = data.text; } + + function initialize_popovers() { + const popups = document.getElementsByClassName('user_popup'); + for (let i = 0; i < popups.length; i++) { + const popover = new bootstrap.Popover(popups[i], { + content: 'Loading...', + trigger: 'hover focus', + placement: 'right', + html: true, + sanitize: false, + delay: {show: 500, hide: 0}, + container: popups[i], + customClass: 'd-inline', + }); + popups[i].addEventListener('show.bs.popover', async (ev) => { + if (ev.target.popupLoaded) { + return; + } + const response = await fetch('/user/' + ev.target.innerText.trim() + '/popup'); + const data = await response.text(); + const popover = bootstrap.Popover.getInstance(ev.target); + if (popover && data) { + ev.target.popupLoaded = true; + popover.setContent({'.popover-body': data}); + flask_moment_render_all(); + } + }); + } + } + document.addEventListener('DOMContentLoaded', initialize_popovers); diff --git a/app/templates/user_popup.html b/app/templates/user_popup.html new file mode 100644 index 0000000..a2d9f9f --- /dev/null +++ b/app/templates/user_popup.html @@ -0,0 +1,27 @@ +
+ +

{{ user.username }}

+ {% if user.about_me %}

{{ user.about_me }}

{% endif %} +
+ {% if user.last_seen %} +

{{ _('Last seen on') }}: {{ moment(user.last_seen).format('lll') }}

+ {% endif %} +

{{ _('%(count)d followers', count=user.followers.count()) }}, {{ _('%(count)d following', count=user.following.count()) }}

+ {% if user != current_user %} + {% if not current_user.is_following(user) %} +

+

+ {{ form.hidden_tag() }} + {{ form.submit(value=_('Follow'), class_='btn btn-outline-primary btn-sm') }} +
+

+ {% else %} +

+

+ {{ form.hidden_tag() }} + {{ form.submit(value=_('Unfollow'), class_='btn btn-outline-primary btn-sm') }} +
+

+ {% endif %} + {% endif %} +