From bf1450799df0deb424a9675be89e13c29e3620d7 Mon Sep 17 00:00:00 2001
From: Mel <einebeere@gmail.com>
Date: Sat, 19 Feb 2022 20:00:38 +0100
Subject: Split state into stages to handle messages

---
 assets/src/components/share/RequestList.svelte | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

(limited to 'assets/src/components/share/RequestList.svelte')

diff --git a/assets/src/components/share/RequestList.svelte b/assets/src/components/share/RequestList.svelte
index 510e80c..1a3b715 100644
--- a/assets/src/components/share/RequestList.svelte
+++ b/assets/src/components/share/RequestList.svelte
@@ -1,6 +1,20 @@
 <script lang="ts">
-    import requests from "../../stores/received_requests";
+    import { derived } from "svelte/store";
+    import type { Readable } from "svelte/store";
+    import type { IncomingRequest } from "../../models/incoming_request";
+    import { getShareState, Sharing } from "../../state/share";
     import Request from "./Request.svelte";
+
+    const sharing = getShareState().state as Sharing;
+    const requestMap = sharing.getRequests();
+
+    function requestSorter(a: IncomingRequest, b: IncomingRequest): number {
+        return a.info.receivedAt.getTime() - b.info.receivedAt.getTime();
+    }
+
+    const requests: Readable<IncomingRequest[]> = derived(requestMap, $map => {
+        return Object.values($map).sort(requestSorter);
+    });
 </script>
 
 {#each $requests as request (request.info.token)}
-- 
cgit 1.4.1

