Experiment to rebuild Diffuse using web applets.
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

at s3 39 lines 1.0 kB view raw
1<script> 2 import { applets } from "@web-applets/sdk"; 3 import { QueueItem, State } from "./types"; 4 5 //////////////////////////////////////////// 6 // SETUP 7 //////////////////////////////////////////// 8 const context = applets.register<State>(); 9 10 // Initial state 11 context.data = { 12 past: [], 13 now: null, 14 future: [], 15 }; 16 17 // State helpers 18 function update(partial: Partial<State>): void { 19 context.data = { ...context.data, ...partial }; 20 } 21 22 //////////////////////////////////////////// 23 // ACTIONS 24 //////////////////////////////////////////// 25 context.setActionHandler("add", add); 26 context.setActionHandler("shift", shift); 27 28 function add(items: QueueItem[]) { 29 update({ future: [...context.data.future, ...items] }); 30 } 31 32 function shift() { 33 const now = context.data.future[0] || null; 34 const future = context.data.future.slice(1); 35 const past = context.data.now ? [...context.data.past, context.data.now] : context.data.past; 36 37 update({ past, now, future }); 38 } 39</script>