Skip to content

Commit

Permalink
Add preference for comment collapsing
Browse files Browse the repository at this point in the history
  • Loading branch information
r-thomson committed May 5, 2024
1 parent af0bc51 commit c71947d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/components/Comment.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import { getContext, setContext } from 'svelte';
import { modNames, symbols, type FetchedKids } from '../hacker-news/api';
import type { DeletedHNItem, HNComment } from '../hacker-news/types';
import { collapseLongThreads } from '../preferences';
import Content from './Content.svelte';
import ExpandCollapseIcon from './ExpandCollapseIcon.svelte';
import Timestamp from './Timestamp.svelte';
Expand Down Expand Up @@ -79,7 +80,7 @@

{#if symbols.resolvedKids in comment && comment[symbols.resolvedKids].length > 0}
<div class="child-comments" hidden={collapsed}>
{#if depth === 6 && countChildComments(comment) > 1}
{#if $collapseLongThreads && depth === 5 && countChildComments(comment) > 1}
<a class="more-comments" href="item?id={comment.id}">
{countChildComments(comment)} More Comments &rarr;
</a>
Expand Down
15 changes: 13 additions & 2 deletions src/components/PreferencesModal.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
<script lang="ts">
import { highlightThreshold, maxStories, resetPreferences, showCounters } from '../preferences';
import {
highlightThreshold,
maxStories,
resetPreferences,
showCounters,
collapseLongThreads,
} from '../preferences';
/** Whether or not the modal is open. */
export let open: boolean;
Expand Down Expand Up @@ -37,7 +43,7 @@
<h2>Preferences</h2>

<form method="dialog" on:reset|preventDefault={onReset}>
<label id="showCountersSelect">
<label>
<input type="checkbox" bind:checked={$showCounters} />
Show counters in story lists
</label>
Expand All @@ -56,6 +62,11 @@
{/each}
</select>

<label>
<input type="checkbox" bind:checked={$collapseLongThreads} />
Collapse long comment threads
</label>

<div class="actions">
<button type="submit">Done</button>
<button type="reset">Reset</button>
Expand Down
2 changes: 2 additions & 0 deletions src/preferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ import { persistedStore } from './utils';
export const showCounters = persistedStore<boolean>('pref:showCounters', false);
export const maxStories = persistedStore<number>('pref:maxStories', 30);
export const highlightThreshold = persistedStore<number>('pref:highlightThreshold', 200);
export const collapseLongThreads = persistedStore<boolean>('pref:collapseLongThreads', true);

export function resetPreferences() {
showCounters.unset();
maxStories.unset();
highlightThreshold.unset();
collapseLongThreads.unset();
}

0 comments on commit c71947d

Please sign in to comment.