Skip to content

Commit

Permalink
configurable message unload behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
slatinsky committed Nov 1, 2022
1 parent 965cbdd commit 0144318
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
18 changes: 16 additions & 2 deletions src/routes/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script>
import { nameRenderer, timestampFormat, developerMode, theme, online, linkHandler } from './settingsStore';
import { nameRenderer, timestampFormat, developerMode, theme, online, linkHandler, unloadMessages } from './settingsStore';
import { timestampRenderers } from './time';
let testDate = '2020-09-16T11:04:47.215+00:00';
Expand Down Expand Up @@ -80,7 +80,7 @@
</label>
<label>
<input type="radio" name="online" value={true} bind:group={$online} />
<span>If local assets doesn't exist</span>
<span>If local assets don't exist</span>
</label>
{/key}
</div>
Expand All @@ -103,6 +103,20 @@
{/key}
</div>

<p>Unload messages that are not visible?</p>
<div class="radios">
{#key $unloadMessages}
<label>
<input type="radio" name="unloadMessages" value={true} bind:group={$unloadMessages} />
<span>Yes (uses less RAM)</span>
</label>
<label>
<input type="radio" name="unloadMessages" value={false} bind:group={$unloadMessages} />
<span>No (fixes messages going up and down in some browsers while scrolling, but browser may be laggy if you scroll long enough)</span>
</label>
{/key}
</div>

<style>
.title {
font-size: 28px;
Expand Down
11 changes: 8 additions & 3 deletions src/routes/channels/[guildId]/[channelId]/Message.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script>
import { nameRenderer, online, linkHandler } from '../../../settingsStore';
import { nameRenderer, linkHandler, unloadMessages } from '../../../settingsStore';
import { onMount, onDestroy } from 'svelte';
import { fade } from 'svelte/transition';
import MessageMarkdown from './MessageMarkdown.svelte';
Expand Down Expand Up @@ -79,12 +79,17 @@
onMount(() => {
observer.observe(root);
unloadObserver.observe(root);
if ($unloadMessages) {
console.log("unloading messages");
unloadObserver.observe(root);
}
});
onDestroy(() => {
observer.disconnect();
unloadObserver.disconnect();
if ($unloadMessages) {
unloadObserver.disconnect();
}
});
Expand Down
2 changes: 2 additions & 0 deletions src/routes/settingsStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export const developerMode = writable(false);
export const theme = writable("dark");
export const online = writable(false);
export const linkHandler = writable("app");
export const unloadMessages = writable(false);

function withLocalStorage(store, localstorageKey: string, type = "string") {
const restoredValue = localStorage.getItem(localstorageKey);
Expand Down Expand Up @@ -34,4 +35,5 @@ withLocalStorage(developerMode, "developerMode", "bool");
withLocalStorage(theme, "theme", "string");
withLocalStorage(online, "online", "bool");
withLocalStorage(linkHandler, "linkHandler", "string");
withLocalStorage(unloadMessages, "unloadMessages", "bool");

0 comments on commit 0144318

Please sign in to comment.