Skip to content

Commit

Permalink
fix sources block not updating properly after saving (#216)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdashlw authored Mar 24, 2024
1 parent 921ad0c commit 1f44047
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
3 changes: 1 addition & 2 deletions assets/js/misc.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ function formResult({target, detail}) {

const elements = {
'#description-form': '.image-description',
'#uploader-form': '.image_uploader',
'#source-form': '#image-source'
'#uploader-form': '.image_uploader'
};

function showResult(resultEl, formEl, response) {
Expand Down
16 changes: 15 additions & 1 deletion assets/js/sources.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { inputDuplicatorCreator } from './input-duplicator';

function imageSourcesCreator() {
function setupInputs() {
inputDuplicatorCreator({
addButtonSelector: '.js-image-add-source',
fieldSelector: '.js-image-source',
Expand All @@ -9,4 +9,18 @@ function imageSourcesCreator() {
});
}

function imageSourcesCreator() {
setupInputs();
document.addEventListener('fetchcomplete', ({ target, detail }) => {
const sourceSauce = document.querySelector('.js-sourcesauce');

if (target.matches('#source-form')) {
detail.text().then(text => {
sourceSauce.outerHTML = text;
setupInputs();
});
}
});
}

export { imageSourcesCreator };
2 changes: 1 addition & 1 deletion lib/philomena_web/templates/image/_source.html.slime
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.block
.js-sourcesauce
- has_sources = Enum.any?(@image.sources)
= form_for @changeset, Routes.image_source_path(@conn, :update, @image), [method: "put", class: "hidden", id: "source-form", data: [remote: "true"]], fn f ->
= if can?(@conn, :edit_metadata, @image) and [email protected]_ban do
Expand Down

0 comments on commit 1f44047

Please sign in to comment.