your personal website on atproto - mirror blento.app

small fixes

Florian 5f2595ae 42a52430

+62 -3
+1 -1
src/lib/Profile.svelte
··· 41 41 {profileData?.displayName || handle} 42 42 </div> 43 43 44 - <div class="scrollbar -mx-4 flex-grow overflow-y-scroll px-4"> 44 + <div class="scrollbar -mx-4 flex-grow overflow-y-scroll px-4 overflow-x-hidden"> 45 45 <div 46 46 class="text-base-600 dark:text-base-400 prose dark:prose-invert prose-a:text-accent-500 prose-a:no-underline" 47 47 >
+43
src/lib/helper.ts
··· 97 97 compactItems(items, mobile); 98 98 } 99 99 100 + // Fix all collisions between items (not just one moved item) 101 + // Items higher on the page have priority and stay in place 102 + export function fixAllCollisions(items: Item[], mobile: boolean = false) { 103 + // Sort by Y position (top-to-bottom, then left-to-right) 104 + // Items at the top have priority and won't be moved 105 + const sortedItems = items.toSorted((a, b) => 106 + mobile ? a.mobileY - b.mobileY || a.mobileX - b.mobileX : a.y - b.y || a.x - b.x 107 + ); 108 + 109 + // Process each item and push it down if it overlaps with any item above it 110 + for (let i = 0; i < sortedItems.length; i++) { 111 + const item = sortedItems[i]; 112 + 113 + // Clamp X to valid range 114 + if (mobile) { 115 + item.mobileX = clamp(item.mobileX, 0, COLUMNS - item.mobileW); 116 + } else { 117 + item.x = clamp(item.x, 0, COLUMNS - item.w); 118 + } 119 + 120 + // Check for collisions with all items that come before (higher priority) 121 + let hasCollision = true; 122 + while (hasCollision) { 123 + hasCollision = false; 124 + for (let j = 0; j < i; j++) { 125 + const other = sortedItems[j]; 126 + if (overlaps(item, other, mobile)) { 127 + // Push item down below the colliding item 128 + if (mobile) { 129 + item.mobileY = other.mobileY + other.mobileH; 130 + } else { 131 + item.y = other.y + other.h; 132 + } 133 + hasCollision = true; 134 + break; // Restart collision check from the beginning 135 + } 136 + } 137 + } 138 + } 139 + 140 + compactItems(items, mobile); 141 + } 142 + 100 143 // Move all items up as far as possible without collisions 101 144 export function compactItems(items: Item[], mobile: boolean = false) { 102 145 // Sort by Y position (top-to-bottom) so upper items settle first.
+18 -2
src/lib/website/load.ts
··· 9 9 import { data } from './data'; 10 10 import { CardDefinitionsByType } from '$lib/cards'; 11 11 import type { Item } from '$lib/types'; 12 + import { compactItems, fixAllCollisions, fixCollisions } from '$lib/helper'; 12 13 13 14 type LoadedData = { 14 15 did: string; ··· 38 39 timePassed, 39 40 'seconds ago' 40 41 ); 41 - return migrateData(JSON.parse(cachedResult)); 42 + return checkData(migrateData(JSON.parse(cachedResult))); 42 43 } 43 44 } catch (error) { 44 45 console.log('getting cached result failed', error); ··· 146 147 147 148 await platform?.env?.USER_DATA_CACHE?.put(handle, JSON.stringify(result)); 148 149 149 - return migrateData(result); 150 + return checkData(migrateData(result)); 150 151 } 151 152 152 153 function migrateFromV0ToV1(data: LoadedData): LoadedData { ··· 161 162 card.mobileH *= 2; 162 163 card.mobileW *= 2; 163 164 card.version = 1; 165 + } 166 + 167 + return data; 168 + } 169 + 170 + function checkData(data: LoadedData): LoadedData { 171 + const cards = Object.values(data.data['app.blento.card']).map((i) => i.value) as Item[]; 172 + 173 + console.log(cards); 174 + if (cards.length > 0) { 175 + fixAllCollisions(cards); 176 + fixAllCollisions(cards, true); 177 + 178 + compactItems(cards); 179 + compactItems(cards, true); 164 180 } 165 181 166 182 return data;