Sync: Community Changes #4239

This commit is contained in:
pushya22
2025-09-17 20:24:08 +05:30
committed by GitHub
3 changed files with 15 additions and 5 deletions

View File

@@ -85,8 +85,9 @@ export class UserService extends APIService {
});
}
async currentUserSettings(): Promise<IUserSettings> {
return this.get("/api/users/me/settings/")
async currentUserSettings(bustCache: boolean = false): Promise<IUserSettings> {
const url = bustCache ? `/api/users/me/settings/?t=${Date.now()}` : "/api/users/me/settings/";
return this.get(url)
.then((response) => response?.data)
.catch((error) => {
throw error?.response;

View File

@@ -175,6 +175,14 @@ export class ProfileStore implements IUserProfileStore {
runInAction(() => {
this.mutateUserProfile({ ...dataToUpdate, is_onboarded: true });
});
// Also fetch from backend to ensure consistency and refresh user settings with cache-busting
Promise.all([
this.fetchUserProfile(),
this.store.user.userSettings.fetchCurrentUserSettings(true), // Cache-busting enabled
]).catch((error) => {
console.error("Background sync failed:", error);
});
} catch (error) {
runInAction(() => {
this.error = {

View File

@@ -18,7 +18,8 @@ export interface IUserSettingsStore {
sidebarCollapsed: boolean;
isScrolled: boolean;
// actions
fetchCurrentUserSettings: () => Promise<IUserSettings | undefined>;
fetchCurrentUserSettings: (bustCache?: boolean) => Promise<IUserSettings | undefined>;
toggleLocalDB: (workspaceSlug: string | undefined, projectId: string | undefined) => Promise<void>;
toggleSidebar: (collapsed?: boolean) => void;
toggleIsScrolled: (isScrolled?: boolean) => void;
}
@@ -78,13 +79,13 @@ export class UserSettingsStore implements IUserSettingsStore {
* @description fetches user profile information
* @returns {Promise<IUserSettings | undefined>}
*/
fetchCurrentUserSettings = async () => {
fetchCurrentUserSettings = async (bustCache: boolean = false) => {
try {
runInAction(() => {
this.isLoading = true;
this.error = undefined;
});
const userSettings = await this.userService.currentUserSettings();
const userSettings = await this.userService.currentUserSettings(bustCache);
runInAction(() => {
this.isLoading = false;
this.data = userSettings;