diff --git a/dist/js/main.js b/dist/js/main.js index 7f3ec20..df0eeb8 100644 --- a/dist/js/main.js +++ b/dist/js/main.js @@ -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); diff --git a/src/base_page.c b/src/base_page.c index f5794a1..9f2a308 100644 --- a/src/base_page.c +++ b/src/base_page.c @@ -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, "", diff --git a/src/local_config_set.c b/src/local_config_set.c index 1447c43..5fdd725 100644 --- a/src/local_config_set.c +++ b/src/local_config_set.c @@ -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)); } diff --git a/src/notifications.c b/src/notifications.c index d8dd2f8..bc4be96 100644 --- a/src/notifications.c +++ b/src/notifications.c @@ -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, "",