diff --git a/app/community/routes.py b/app/community/routes.py index 31553420..d622c6b6 100644 --- a/app/community/routes.py +++ b/app/community/routes.py @@ -735,7 +735,12 @@ def add_post(actor, type): if not community.local_only: federate_post(community, post) - return redirect(f"/post/{post.id}") + resp = make_response(redirect(f"/post/{post.id}")) + # remove cookies used to maintain state when switching post type + resp.delete_cookie('post_title') + resp.delete_cookie('post_description') + resp.delete_cookie('post_tags') + return resp else: # GET form.communities.data = community.id form.notify_author.data = True diff --git a/app/static/js/scripts.js b/app/static/js/scripts.js index 4aeb7ebd..1ae8780b 100644 --- a/app/static/js/scripts.js +++ b/app/static/js/scripts.js @@ -34,6 +34,7 @@ document.addEventListener("DOMContentLoaded", function () { setupLightboxTeaser(); setupLightboxPostBody(); setupPostTeaserHandler(); + setupPostTypeSwitcher(); }); function setupPostTeaserHandler() { @@ -47,6 +48,26 @@ function setupPostTeaserHandler() { }); } +function setupPostTypeSwitcher() { + document.querySelectorAll('#type_of_post a').forEach(a => { + a.onclick = function() { + setCookie('post_title', document.getElementById('title').value, 0.1); + setCookie('post_description', document.getElementById('body').value, 0.1); + setCookie('post_tags', document.getElementById('tags').value, 0.1); + }; + }); + + var typeSwitcher = document.getElementById('type_of_post'); + var title = document.getElementById('title'); + var body = document.getElementById('body'); + var tags = document.getElementById('tags'); + if(typeSwitcher && title && body && tags) { + title.value = getCookie('post_title'); + body.value = getCookie('post_description'); + tags.value = getCookie('post_tags'); + } +} + function setupYouTubeLazyLoad() { const lazyVideos = document.querySelectorAll(".video-wrapper"); @@ -799,7 +820,7 @@ function getCookie(name) { var cookie = cookies[i].trim(); if (cookie.indexOf(name + '=') === 0) { - return cookie.substring(name.length + 1); + return decodeURIComponent(cookie.substring(name.length + 1)); } }