WIP PWA for Grain
0
fork

Configure Feed

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

fix: update profile cache after editing profile

- Subscribe grain-profile to cache updates for reactive UI
- Only update cache if it exists (preserves galleries)
- Handle avatar URL correctly based on change type
- Add defensive check for missing galleries

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

+36 -1
+20
src/components/pages/grain-edit-profile.js
··· 2 2 import { router } from '../../router.js'; 3 3 import { auth } from '../../services/auth.js'; 4 4 import { grainApi } from '../../services/grain-api.js'; 5 + import { recordCache } from '../../services/record-cache.js'; 5 6 import { readFileAsDataURL, resizeImage } from '../../utils/image-resize.js'; 6 7 import '../atoms/grain-icon.js'; 7 8 import '../atoms/grain-button.js'; ··· 318 319 319 320 // Refresh user data in header 320 321 await auth.refreshUser(); 322 + 323 + // Update profile cache if it exists (merge preserves galleries etc) 324 + if (recordCache.has(`profile:${auth.user.handle}`)) { 325 + // Determine avatar URL: new upload uses refreshed URL, removal uses null, unchanged keeps original 326 + let avatarUrl; 327 + if (this._newAvatarDataUrl) { 328 + avatarUrl = auth.user.avatar; 329 + } else if (this._avatarRemoved) { 330 + avatarUrl = null; 331 + } else { 332 + avatarUrl = this._avatarUrl; 333 + } 334 + 335 + recordCache.set(`profile:${auth.user.handle}`, { 336 + displayName: this._displayName.trim() || null, 337 + description: this._description.trim() || null, 338 + avatarUrl 339 + }); 340 + } 321 341 322 342 // Go back to settings 323 343 history.back();
+16 -1
src/components/pages/grain-profile.js
··· 119 119 } else { 120 120 this.#fetchProfile(); 121 121 } 122 + 123 + // Subscribe to cache updates 124 + this.#cacheCallback = (data) => { 125 + this._profile = { ...this._profile, ...data }; 126 + }; 127 + recordCache.subscribe(`profile:${this.handle}`, this.#cacheCallback); 122 128 } 129 + 130 + disconnectedCallback() { 131 + super.disconnectedCallback(); 132 + if (this.#cacheCallback) { 133 + recordCache.unsubscribe(`profile:${this.handle}`, this.#cacheCallback); 134 + } 135 + } 136 + 137 + #cacheCallback = null; 123 138 124 139 async #fetchProfile() { 125 140 try { ··· 166 181 @avatar-updated=${this.#handleRefresh} 167 182 ></grain-profile-header> 168 183 169 - ${this._profile.galleries.length > 0 ? html` 184 + ${this._profile.galleries?.length > 0 ? html` 170 185 <grain-gallery-grid 171 186 handle=${this.handle} 172 187 .galleries=${this._profile.galleries}