Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Settings, Calendar, Search, Moon, Sun, LogOut, RefreshCw, TrendingUp, G
import { useAppStore } from '../store/useAppStore';
import { GitHubApiService } from '../services/githubApi';
import { useDialog } from '../hooks/useDialog';
import { forceSyncToBackend } from '../services/autoSync';

export const Header: React.FC = () => {
const {
Expand Down Expand Up @@ -101,6 +102,9 @@ export const Header: React.FC = () => {

setRepositories(mergedRepositories);

// Force-push to backend immediately (bypass 2s debounce) so data survives a page refresh
forceSyncToBackend().catch(console.error);

// Note: Release fetching is now handled by the Refresh button in Release Timeline
// Header sync only syncs the starred repos list

Expand Down
16 changes: 14 additions & 2 deletions src/services/autoSync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,20 @@ export async function syncFromBackend(): Promise<void> {

// Update store then commit hash — hash only changes if setter succeeds
if (changed.repos && reposResult.status === 'fulfilled') {
state.setRepositories(reposResult.value.repositories);
_lastHash.repos = hashes.repos;
const backendRepos = reposResult.value.repositories;
const localRepos = state.repositories;
// Distinguish first-ever sync (bootstrap) from an authoritative empty backend.
// On bootstrap the hash is still '' — preserve local cache and push it to backend.
// On subsequent syncs, accept the backend state even if empty (e.g. user cleared
// stars from another device).
const isBootstrapEmpty =
backendRepos.length === 0 && localRepos.length > 0 && _lastHash.repos === '';
if (isBootstrapEmpty) {
_hasPendingPush = true;
} else {
state.setRepositories(backendRepos);
_lastHash.repos = hashes.repos;
}
}
if (changed.releases && releasesResult.status === 'fulfilled') {
state.setReleases(releasesResult.value.releases);
Expand Down
Loading