Skip to content

Commit dabc931

Browse files
committed
Debug
1 parent 4943817 commit dabc931

File tree

1 file changed

+67
-31
lines changed

1 file changed

+67
-31
lines changed

app/views/papers/_vote_summary.html.erb

Lines changed: 67 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -30,40 +30,76 @@
3030
</div>
3131

3232
<script>
33-
document.addEventListener('DOMContentLoaded', function() {
34-
console.log('DOM Content Loaded - Initializing vote comment storage');
35-
36-
const commentField = document.getElementById('vote-comment');
37-
console.log('Comment field found:', commentField);
38-
39-
const paperId = commentField.dataset.paperId;
40-
console.log('Paper ID:', paperId);
41-
42-
const storageKey = `vote_comment_${paperId}`;
43-
console.log('Storage key:', storageKey);
33+
(function() {
34+
try {
35+
console.log('Script starting - checking localStorage availability');
36+
if (!window.localStorage) {
37+
console.error('localStorage is not available in this browser');
38+
return;
39+
}
4440

45-
// Load saved comment if it exists
46-
const savedComment = localStorage.getItem(storageKey);
47-
console.log('Saved comment from storage:', savedComment);
48-
49-
if (savedComment) {
50-
commentField.value = savedComment;
51-
console.log('Restored comment from storage');
52-
}
41+
document.addEventListener('DOMContentLoaded', function() {
42+
console.log('DOM Content Loaded - Initializing vote comment storage');
43+
44+
const commentField = document.getElementById('vote-comment');
45+
if (!commentField) {
46+
console.error('Could not find comment field with ID vote-comment');
47+
return;
48+
}
49+
console.log('Comment field found:', commentField);
50+
51+
const paperId = commentField.dataset.paperId;
52+
if (!paperId) {
53+
console.error('No paper ID found in data attributes');
54+
return;
55+
}
56+
console.log('Paper ID:', paperId);
57+
58+
const storageKey = `vote_comment_${paperId}`;
59+
console.log('Storage key:', storageKey);
60+
61+
// Load saved comment if it exists
62+
try {
63+
const savedComment = localStorage.getItem(storageKey);
64+
console.log('Saved comment from storage:', savedComment);
65+
66+
if (savedComment) {
67+
commentField.value = savedComment;
68+
console.log('Restored comment from storage');
69+
}
70+
} catch (e) {
71+
console.error('Error accessing localStorage:', e);
72+
}
5373

54-
// Save comment on input
55-
commentField.addEventListener('input', function() {
56-
console.log('Input detected, saving comment:', this.value);
57-
localStorage.setItem(storageKey, this.value);
58-
});
74+
// Save comment on input
75+
commentField.addEventListener('input', function() {
76+
try {
77+
console.log('Input detected, saving comment:', this.value);
78+
localStorage.setItem(storageKey, this.value);
79+
} catch (e) {
80+
console.error('Error saving to localStorage:', e);
81+
}
82+
});
5983

60-
// Clear storage when form is submitted
61-
const form = commentField.closest('form');
62-
form.addEventListener('submit', function() {
63-
console.log('Form submitted, clearing storage');
64-
localStorage.removeItem(storageKey);
65-
});
66-
});
84+
// Clear storage when form is submitted
85+
const form = commentField.closest('form');
86+
if (form) {
87+
form.addEventListener('submit', function() {
88+
try {
89+
console.log('Form submitted, clearing storage');
90+
localStorage.removeItem(storageKey);
91+
} catch (e) {
92+
console.error('Error clearing localStorage:', e);
93+
}
94+
});
95+
} else {
96+
console.error('Could not find parent form element');
97+
}
98+
});
99+
} catch (e) {
100+
console.error('Error in vote comment storage script:', e);
101+
}
102+
})();
67103
</script>
68104

69105
<div class="form-group">

0 commit comments

Comments
 (0)