Add image under new ID

FossilOrigin-Name: ef42c049e208f207dbda34c2c0b313e216d97354a1a74ec49089f3f2df3b1b61
This commit is contained in:
nekobit 2022-07-13 03:03:34 +00:00
parent 9b66c172d8
commit 15849c03d5
4 changed files with 41 additions and 8 deletions

43
dist/js/main.js vendored
View file

@ -2,7 +2,7 @@
// Global state variable
let state = {
file: {
files: [],
files: {},
file_counter: 0,
}
};
@ -246,10 +246,11 @@
rightbar_frame.height = rbar_frame_win.document.body.scrollHeight;
}
function construct_file_upload(file, file_content)
function construct_file_upload(id, file, file_content)
{
let container = document.createElement("div");
container.className = "file-upload";
container.id = "file-id-" + id;
let content = document.createElement("img");
let info = document.createElement("span");
info.className = "upload-info";
@ -260,13 +261,43 @@
return container;
}
// Created if not exist
function filepicker_create(id)
{
if (!state.file[id])
{
state.file[id] = { files: [], count: 0 }
return true;
}
return false;
}
function filepicker_add(id, file)
{
filepicker_create(id);
state.file[id].files.push(file);
return state.file[id].count++;
}
function evt_file_upload(e)
{
let target = e.target;
// is New?
let id = state.file.file_counter;
// TODO do something with this
if (target.classList.contains("used"))
target.id = `id-${state.file.file_counter++}`;
if (!target.classList.contains("used"))
{
target.id = `file-picker-id-${state.file.file_counter++}`;
target.classList.add("used");
}
else {
// "id-476" -> 476
id = Number(target.id.substr("file-picker-id-".length));
}
let file_upload_dom = this.closest("form").querySelector(".file-uploads-container");
file_upload_dom.className = "file-uploads-container";
@ -280,7 +311,9 @@
reader = new FileReader();
reader.onload = (() => {
return (e) => {
file_upload_dom.appendChild(construct_file_upload(files, e.target.result));
let file_id = filepicker_add(id, file);
file_upload_dom.appendChild(construct_file_upload(file_id, files, e.target.result));
}
})(file);
reader.readAsDataURL(file);

View file

@ -124,7 +124,7 @@ void render_base_page(struct base_page* page, struct session* ssn, mastodont_t*
(g_cache.panel_html.response ?
g_cache.panel_html.response : ""));
if (!(ssn->config.theme && strcmp(ssn->config.theme, "treebird") == 0 &&
if (ssn->config.theme && !(strcmp(ssn->config.theme, "treebird") == 0 &&
ssn->config.themeclr == 0))
{
easprintf(&theme_str, "<link rel=\"stylesheet\" type=\"text/css\" href=\"/%s%s.css\">",

View file

@ -34,7 +34,7 @@ int set_config_str(struct session* ssn,
{
if (ssn->post.set.is_set && post->is_set && page == curr_page)
{
printf("Set-Cookie: %s=%s; HttpOnly; Path=/; SameSite=Strict;\r\n",
printf("Set-Cookie: %s=%s; HttpOnly; Path=/; Max-Age=31536000; SameSite=Strict;\r\n",
cookie_name, keypstr(post));
}

View file

@ -310,7 +310,7 @@ void content_notifications_compact(struct session* ssn, mastodont_t* api, char**
}
// Set theme
if (!(ssn->config.theme && strcmp(ssn->config.theme, "treebird") == 0 &&
if (ssn->config.theme && !(strcmp(ssn->config.theme, "treebird") == 0 &&
ssn->config.themeclr == 0))
{
easprintf(&theme_str, "<link rel=\"stylesheet\" type=\"text/css\" href=\"/%s%s.css\">",