<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Hlulani Baloyi</title>
    <description>The latest articles on DEV Community by Hlulani Baloyi (@hlulani_b).</description>
    <link>https://dev.to/hlulani_b</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4171821%2F5367ebef-a634-45a9-bad1-f0b7ef2336a6.png</url>
      <title>DEV Community: Hlulani Baloyi</title>
      <link>https://dev.to/hlulani_b</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/hlulani_b"/>
    <language>en</language>
    <item>
      <title>Pinning the next match to the top of a cached fixtures list</title>
      <dc:creator>Hlulani Baloyi</dc:creator>
      <pubDate>Fri, 09 Oct 2026 15:21:19 +0000</pubDate>
      <link>https://dev.to/hlulani_b/pinning-the-next-match-to-the-top-of-a-cached-fixtures-list-210f</link>
      <guid>https://dev.to/hlulani_b/pinning-the-next-match-to-the-top-of-a-cached-fixtures-list-210f</guid>
      <description>&lt;p&gt;A few weeks ago I wrote about keeping the league table readable when the signal at the ground disappears. The fixtures list had the same problem, plus one of its own: people only ever want the next game, and they want it before they scroll. The list I was copying the layout from is the one on &lt;a href="https://baduzah-celtics.co.za/" rel="noopener noreferrer"&gt;https://baduzah-celtics.co.za/&lt;/a&gt;, where upcoming matches and finished ones sit in the same feed, so I had to split them myself.&lt;/p&gt;

&lt;p&gt;The data is an array of matches with an ISO kick-off time, home and away names, and a score that is null until the game is played. Around thirty rows for a season. Small enough that I never bothered with IndexedDB.&lt;/p&gt;

&lt;h2&gt;
  
  
  Splitting past and upcoming
&lt;/h2&gt;

&lt;p&gt;My first attempt compared kick-off strings to &lt;code&gt;new Date().toISOString()&lt;/code&gt;. It mostly worked, which is the worst kind of working. A match that kicked off at 15:00 dropped into "played" at 15:00 exactly, while the score was still null for another two hours, and the top of the page showed nothing at all during the game.&lt;/p&gt;

&lt;p&gt;Now a match counts as upcoming until it has a score or is more than three hours past kick-off:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;THREE_HOURS&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;60&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;60&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;isUpcoming&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;match&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;now&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;now&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;match&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;score&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;match&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;kickoff&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;getTime&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;THREE_HOURS&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;now&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;upcoming&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;matches&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;m&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;isUpcoming&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;m&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sort&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;kickoff&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;kickoff&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;next&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;upcoming&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;next&lt;/code&gt; gets its own card above the list, with the date written out in words. Everything else renders below in the usual rows.&lt;/p&gt;

&lt;h2&gt;
  
  
  The cache bit
&lt;/h2&gt;

&lt;p&gt;Same pattern as the table: fetch with a four second timeout, save the raw JSON to localStorage with a timestamp, fall back to the saved copy when the request fails. Two changes this time.&lt;/p&gt;

&lt;p&gt;I save the fetch time and the server's own &lt;code&gt;updated&lt;/code&gt; field separately. They differ more than you would think, because the feed itself is sometimes a day behind, and showing only my fetch time made stale data look fresh.&lt;/p&gt;

&lt;p&gt;And I recompute &lt;code&gt;isUpcoming&lt;/code&gt; on render, not on fetch. If the phone loaded the list at noon and you open it again at six, the noon copy still knows the afternoon game is finished, even without a connection. That one took me an embarrassingly long time to notice, because I was always testing at my desk with wifi.&lt;/p&gt;

&lt;p&gt;Still not sure what to do about postponed games. The feed keeps the old date and adds nothing, so for now they just sit in "upcoming" with a date in the past until somebody fixes the data.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>pwa</category>
    </item>
    <item>
      <title>Showing a league table offline when the signal at the ground is bad</title>
      <dc:creator>Hlulani Baloyi</dc:creator>
      <pubDate>Thu, 08 Oct 2026 19:38:07 +0000</pubDate>
      <link>https://dev.to/hlulani_b/showing-a-league-table-offline-when-the-signal-at-the-ground-is-bad-3c5c</link>
      <guid>https://dev.to/hlulani_b/showing-a-league-table-offline-when-the-signal-at-the-ground-is-bad-3c5c</guid>
      <description>&lt;p&gt;Our club plays at a ground where the mobile signal drops to nothing about ten minutes before kick-off, which is exactly when people want to check the log and the next fixture. So the small page I keep for the club had to work without a connection, at least for the last thing it managed to load.&lt;/p&gt;

&lt;p&gt;The table comes in as JSON: sixteen teams, eight numbers each. The first version fetched it on every page load and showed a spinner forever when the request failed. Not great on a match day.&lt;/p&gt;

&lt;p&gt;What I ended up with is boring but it works:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Fetch the JSON with a short timeout (four seconds).&lt;/li&gt;
&lt;li&gt;If it arrives, render it and save the raw string to localStorage together with the time it was fetched.&lt;/li&gt;
&lt;li&gt;If the request fails or times out, read the saved copy, render it, and show a small line under the table: "Last updated 14:05, no connection".&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The timestamp turned out to matter more than I expected. Without it people assumed the table was live and argued about points that were already out of date.&lt;/p&gt;

&lt;p&gt;Two things I'd do differently from the start. First, store the parsed numbers, not the HTML, because I changed the table layout twice and old cached HTML looked broken. Second, keep the cache key versioned (table-v2), so a format change doesn't try to read the old shape.&lt;/p&gt;

&lt;p&gt;Next I want the fixtures list to work the same way, with the next match pinned to the top. If you've done offline caching for something similar and found a cleaner pattern than localStorage plus a timestamp, I'd like to hear it.&lt;/p&gt;

</description>
      <category>javascript</category>
    </item>
  </channel>
</rss>
