mirror of
https://github.com/dergigi/boris.git
synced 2025-12-17 06:34:24 +01:00
feat: preload logged-in user profile image for offline access
Preload profile images when profiles are fetched and when displayed in the sidebar to ensure they're cached by the Service Worker for offline access.
This commit is contained in:
@@ -7,6 +7,7 @@ import { useEventModel } from 'applesauce-react/hooks'
|
||||
import { Models } from 'applesauce-core'
|
||||
import IconButton from './IconButton'
|
||||
import { faBooks } from '../icons/customIcons'
|
||||
import { preloadImage } from '../hooks/useImageCache'
|
||||
|
||||
interface SidebarHeaderProps {
|
||||
onToggleCollapse: () => void
|
||||
@@ -36,6 +37,13 @@ const SidebarHeader: React.FC<SidebarHeaderProps> = ({ onToggleCollapse, onLogou
|
||||
|
||||
const profileImage = getProfileImage()
|
||||
|
||||
// Preload profile image for offline access
|
||||
useEffect(() => {
|
||||
if (profileImage) {
|
||||
preloadImage(profileImage)
|
||||
}
|
||||
}, [profileImage])
|
||||
|
||||
// Close menu when clicking outside
|
||||
useEffect(() => {
|
||||
const handleClickOutside = (event: MouseEvent) => {
|
||||
|
||||
@@ -5,6 +5,7 @@ import { IEventStore } from 'applesauce-core'
|
||||
import { prioritizeLocalRelays, partitionRelays } from '../utils/helpers'
|
||||
import { rebroadcastEvents } from './rebroadcastService'
|
||||
import { UserSettings } from './settingsService'
|
||||
import { preloadImage } from '../hooks/useImageCache'
|
||||
|
||||
/**
|
||||
* Fetches profile metadata (kind:0) for a list of pubkeys
|
||||
@@ -65,6 +66,19 @@ export const fetchProfiles = async (
|
||||
|
||||
const profiles = Array.from(profilesByPubkey.values())
|
||||
|
||||
// Preload profile images for offline access
|
||||
for (const profile of profiles) {
|
||||
try {
|
||||
const profileData = JSON.parse(profile.content)
|
||||
const picture = profileData.picture
|
||||
if (picture) {
|
||||
preloadImage(picture)
|
||||
}
|
||||
} catch {
|
||||
// Ignore parse errors - profile content might be invalid JSON
|
||||
}
|
||||
}
|
||||
|
||||
// Rebroadcast profiles to local/all relays based on settings
|
||||
if (profiles.length > 0) {
|
||||
await rebroadcastEvents(profiles, relayPool, settings)
|
||||
|
||||
Reference in New Issue
Block a user