local storage fix?

This commit is contained in:
2025-04-08 13:49:53 -05:00
parent 2119a653f1
commit 6ac319831f
+19 -13
View File
@@ -110,8 +110,10 @@ const CommentSection: React.FC<CommentFormProps> = ({ postId }) => {
className="w-full px-4 py-2 border border-primary-300 rounded-md focus:outline-none focus:ring-2 focus:ring-accent focus:border-transparent" className="w-full px-4 py-2 border border-primary-300 rounded-md focus:outline-none focus:ring-2 focus:ring-accent focus:border-transparent"
required required
onFocus={() => { onFocus={() => {
const savedName = localStorage.getItem('name'); if (typeof window !== 'undefined') {
if (savedName) setName(savedName); const savedName = localStorage.getItem('name');
if (savedName) setName(savedName);
}
}} }}
/> />
</div> </div>
@@ -127,8 +129,10 @@ const CommentSection: React.FC<CommentFormProps> = ({ postId }) => {
className="w-full px-4 py-2 border border-primary-300 rounded-md focus:outline-none focus:ring-2 focus:ring-accent focus:border-transparent" className="w-full px-4 py-2 border border-primary-300 rounded-md focus:outline-none focus:ring-2 focus:ring-accent focus:border-transparent"
required required
onFocus={() => { onFocus={() => {
const savedEmail = localStorage.getItem('email'); if (typeof window !== 'undefined') {
if (savedEmail) setEmail(savedEmail); const savedEmail = localStorage.getItem('email');
if (savedEmail) setEmail(savedEmail);
}
}} }}
/> />
</div> </div>
@@ -153,16 +157,18 @@ const CommentSection: React.FC<CommentFormProps> = ({ postId }) => {
type="checkbox" type="checkbox"
id="save-info" id="save-info"
className="h-4 w-4 text-accent border-primary-300 rounded focus:ring-accent" className="h-4 w-4 text-accent border-primary-300 rounded focus:ring-accent"
checked={localStorage.getItem('saveInfo') === 'true'} checked={typeof window !== 'undefined' && localStorage.getItem('saveInfo') === 'true'}
onChange={(e) => { onChange={(e) => {
const saveInfo = e.target.checked; if (typeof window !== 'undefined') {
localStorage.setItem('saveInfo', saveInfo.toString()); const saveInfo = e.target.checked;
if (saveInfo) { localStorage.setItem('saveInfo', saveInfo.toString());
localStorage.setItem('name', name); if (saveInfo) {
localStorage.setItem('email', email); localStorage.setItem('name', name);
} else { localStorage.setItem('email', email);
localStorage.removeItem('name'); } else {
localStorage.removeItem('email'); localStorage.removeItem('name');
localStorage.removeItem('email');
}
} }
}} }}
/> />