maintain state of title, description and tags when switching post type

This commit is contained in:
rimu 2025-01-05 14:10:25 +13:00
parent 5a6a013afd
commit 93f8184f0a
2 changed files with 28 additions and 2 deletions

View file

@ -735,7 +735,12 @@ def add_post(actor, type):
if not community.local_only: if not community.local_only:
federate_post(community, post) 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 else: # GET
form.communities.data = community.id form.communities.data = community.id
form.notify_author.data = True form.notify_author.data = True

View file

@ -34,6 +34,7 @@ document.addEventListener("DOMContentLoaded", function () {
setupLightboxTeaser(); setupLightboxTeaser();
setupLightboxPostBody(); setupLightboxPostBody();
setupPostTeaserHandler(); setupPostTeaserHandler();
setupPostTypeSwitcher();
}); });
function setupPostTeaserHandler() { 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() { function setupYouTubeLazyLoad() {
const lazyVideos = document.querySelectorAll(".video-wrapper"); const lazyVideos = document.querySelectorAll(".video-wrapper");
@ -799,7 +820,7 @@ function getCookie(name) {
var cookie = cookies[i].trim(); var cookie = cookies[i].trim();
if (cookie.indexOf(name + '=') === 0) { if (cookie.indexOf(name + '=') === 0) {
return cookie.substring(name.length + 1); return decodeURIComponent(cookie.substring(name.length + 1));
} }
} }