Skip to content

Commit c3da200

Browse files
committed
fix mobile header not getting scrolled
1 parent 6e069f1 commit c3da200

File tree

4 files changed

+118
-59
lines changed

4 files changed

+118
-59
lines changed

frontend/src/journal/JournalEntry.svelte

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
4343
let liClasses = $derived.by(() => {
4444
const t = e.t;
45-
let liClasses = t.toLowerCase();
45+
let liClasses = `entry ${t.toLowerCase()}`;
4646
if (t === "Custom") {
4747
liClasses += ` ${e.type}`;
4848
}
@@ -339,3 +339,15 @@
339339
</ul>
340340
{/if}
341341
</li>
342+
343+
<style>
344+
.entry {
345+
padding: 0 1.5em;
346+
}
347+
348+
@media (width <= 767px) {
349+
.entry {
350+
padding: 0 1em;
351+
}
352+
}
353+
</style>

frontend/src/journal/JournalTable.svelte

Lines changed: 98 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<script lang="ts">
22
import { createVirtualizer } from "@tanstack/svelte-virtual";
3-
import { onDestroy, type Snippet } from "svelte";
3+
import { onDestroy, onMount, tick, type Snippet } from "svelte";
44
import { derived, writable } from "svelte/store";
55
66
import type { Entry } from "../entries";
@@ -15,6 +15,8 @@
1515
import JournalEntry from "./JournalEntry.svelte";
1616
import JournalFilters from "./JournalFilters.svelte";
1717
import type { AccountJournalEntry } from "../api/validators";
18+
import Header from "../sidebar/Header.svelte";
19+
import { hideHeader } from "../stores";
1820
1921
type E = Entry | AccountJournalEntry;
2022
interface Props {
@@ -161,68 +163,98 @@
161163
});
162164
}
163165
});
166+
167+
let mobileHeader = $state(false);
168+
onMount(() => {
169+
const mediaQuery = window.matchMedia("(width <= 767px)");
170+
const onChange = () => {
171+
// Wait for update tick so keyboard shortcut not duplicated.
172+
if (mediaQuery.matches) {
173+
$hideHeader = true;
174+
tick().then(() => mobileHeader = true);
175+
} else {
176+
mobileHeader = false;
177+
tick().then(() => $hideHeader = false);
178+
}
179+
};
180+
181+
mediaQuery.addEventListener("change", onChange);
182+
onChange();
183+
184+
onDestroy(() => {
185+
$hideHeader = false;
186+
mediaQuery.removeEventListener("change", onChange);
187+
});
188+
});
164189
</script>
165190

166191
<div class="fixed-fullsize-container">
167192
<div bind:this={vlistOuter} class="vlist-outer">
168193
<div
169-
class="flex-table journal vlist-inner"
194+
class="flex-table vlist-inner"
170195
style="height: {$virtualizer.getTotalSize()}px;"
171196
>
172197
<ol
173-
class="vlist-items"
198+
class="vlist-items journal"
174199
style="transform: translateY({items[0]?.start ?? 0}px);"
175200
>
176201
{#each items as row (row.index)}
177202
{#if row.index === 0}
178203
<li class="head" bind:this={head} data-index="0">
179-
{@render header?.()}
180-
<div class="filter-container">
204+
{#if mobileHeader}
205+
<div class="header-mobile">
206+
<Header />
207+
</div>
208+
{/if}
209+
<div class="container">
210+
{@render header?.()}
181211
<JournalFilters />
182212
</div>
183-
<p>
184-
<!-- TODO: ARIA tags -->
185-
<span
186-
class="datecell"
187-
data-sort="date"
188-
data-sort-name="date"
189-
onclick={headerClick}
190-
aria-hidden="true"
191-
>
192-
{_("Date")}
193-
</span>
194-
<span
195-
class="flag"
196-
data-sort="string"
197-
data-sort-name="flag"
198-
onclick={headerClick}
199-
aria-hidden="true"
200-
>
201-
{_("F")}
202-
</span>
203-
<span
204-
class="description"
205-
data-sort="string"
206-
data-sort-name="narration"
207-
onclick={headerClick}
208-
aria-hidden="true"
209-
>
210-
{_("Payee")}/{_("Narration")}
211-
</span>
212-
<span class="num">{_("Units")}</span>
213-
<span class="cost num">
214-
{_("Cost")}
215-
{#if showChangeAndBalance}
216-
/ {_("Change")}
217-
{/if}
218-
</span>
219-
<span class="num">
220-
{_("Price")}
221-
{#if showChangeAndBalance}
222-
/ {_("Balance")}
223-
{/if}
224-
</span>
225-
</p>
213+
<div class="table-head">
214+
<p>
215+
<!-- TODO: ARIA tags -->
216+
<span
217+
class="datecell"
218+
data-sort="date"
219+
data-sort-name="date"
220+
onclick={headerClick}
221+
aria-hidden="true"
222+
>
223+
{_("Date")}
224+
</span>
225+
<span
226+
class="flag"
227+
data-sort="string"
228+
data-sort-name="flag"
229+
onclick={headerClick}
230+
aria-hidden="true"
231+
>
232+
{_("F")}
233+
</span>
234+
<span
235+
class="description"
236+
data-sort="string"
237+
data-sort-name="narration"
238+
onclick={headerClick}
239+
aria-hidden="true"
240+
>
241+
{_("Payee")}/{_("Narration")}
242+
</span>
243+
<span class="num">{_("Units")}</span>
244+
<span class="cost num">
245+
{_("Cost")}
246+
{#if showChangeAndBalance}
247+
/ {_("Change")}
248+
{/if}
249+
</span>
250+
<span class="num">
251+
{_("Price")}
252+
{#if showChangeAndBalance}
253+
/ {_("Balance")}
254+
{/if}
255+
</span>
256+
</p>
257+
</div>
226258
</li>
227259
{:else}
228260
<JournalEntry
@@ -240,15 +272,9 @@
240272
</div>
241273

242274
<style>
243-
.fixed-fullsize-container {
244-
position: absolute;
245-
top: 0;
246-
left: 0;
247-
}
248-
249275
.vlist-outer {
250276
height: 100%;
251-
padding: 1.5em;
277+
/* padding: 1.5em; */
252278
contain: strict;
253279
overflow-y: auto;
254280
}
@@ -266,7 +292,22 @@
266292
width: 100%;
267293
}
268294
269-
.filter-container {
270-
margin-bottom: 0.25rem;
295+
.head > .container {
296+
padding: 1.5em 1.5em 0 1.5em;
297+
margin-bottom: 0.25em;
298+
}
299+
300+
.head .table-head {
301+
padding: 0 1.5em;
302+
}
303+
304+
@media (width <= 767px) {
305+
.head > .container {
306+
padding: 1em 1em 0 1em;
307+
}
308+
309+
.head .table-head {
310+
padding: 0 1em;
311+
}
271312
}
272313
</style>
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
<script lang="ts">
2+
import { hideHeader } from "../stores";
23
import AsideWithButton from "./AsideWithButton.svelte";
34
import Header from "./Header.svelte";
45
</script>
56

6-
<Header />
7+
{#if !$hideHeader}
8+
<Header />
9+
{/if}
710
<AsideWithButton />

frontend/src/stores/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,6 @@ export const years = derived_array(ledgerData, (v) => v.years);
6060
export const currencies_sorted = derived_array(currencies, ($currencies) =>
6161
$currencies.toSorted(),
6262
);
63+
64+
/** Whether to hide the global header and handle it manually. */
65+
export const hideHeader = writable(false);

0 commit comments

Comments
 (0)