Skip to content

Commit b47ff21

Browse files
committed
feat: Add localStorage support for initializing comment sort preference
1 parent 4ad956a commit b47ff21

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

frontend/src/components/meh-comments/meh-comments.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,9 @@ export class MehComments {
5454

5555
/**
5656
* Comment sort order: 'oldest' (default), 'newest', or 'threaded'
57+
* Can be initialized from localStorage 'meh-sort' key if present
5758
*/
58-
@Prop() sort: 'oldest' | 'newest' | 'threaded' = 'oldest';
59+
@Prop({ mutable: true }) sort: 'oldest' | 'newest' | 'threaded' = 'oldest';
5960

6061
@State() comments: any[] = [];
6162
@State() loading: boolean = true;
@@ -93,6 +94,17 @@ export class MehComments {
9394
// Process the backend URL (clean or detect)
9495
this.backend = detectBackendUrl(this.backend);
9596

97+
// Check localStorage for sort preference
98+
try {
99+
const savedSort = localStorage.getItem('meh-sort');
100+
if (savedSort && ['oldest', 'newest', 'threaded'].includes(savedSort)) {
101+
this.sort = savedSort as 'oldest' | 'newest' | 'threaded';
102+
}
103+
} catch (e) {
104+
// Ignore localStorage errors (e.g., in private browsing mode)
105+
console.warn('Could not access localStorage for sort preference:', e);
106+
}
107+
96108
// Initialize the TranslationManager with default translations
97109
this.translator = new TranslationManager(this.defaultTranslations);
98110

0 commit comments

Comments
 (0)