Update static/js/08-settings.js
This commit is contained in:
parent
13b3564b84
commit
20af884e7e
@ -53,15 +53,7 @@ Glow.cloneSettingsState = source => {
|
|||||||
String(value.presence_mode || "").toLowerCase()
|
String(value.presence_mode || "").toLowerCase()
|
||||||
)
|
)
|
||||||
? String(value.presence_mode).toLowerCase()
|
? String(value.presence_mode).toLowerCase()
|
||||||
: "online",
|
: "online"
|
||||||
dm_layout_mode:
|
|
||||||
value.dm_layout_mode === "compact"
|
|
||||||
? "compact"
|
|
||||||
: "cards",
|
|
||||||
show_presence_badge:
|
|
||||||
typeof value.show_presence_badge === "boolean"
|
|
||||||
? value.show_presence_badge
|
|
||||||
: Glow.state.profilePresenceBadgeVisible !== false
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -70,7 +62,7 @@ Glow.initializeSettingsDraft = settings => {
|
|||||||
Glow.state.settings = saved;
|
Glow.state.settings = saved;
|
||||||
Glow.state.settingsSaved = saved;
|
Glow.state.settingsSaved = saved;
|
||||||
Glow.state.settingsDraft = Glow.cloneSettingsState(saved);
|
Glow.state.settingsDraft = Glow.cloneSettingsState(saved);
|
||||||
Glow.clearSettingsDirty();
|
Glow.clearSettingsDirty?.();
|
||||||
};
|
};
|
||||||
|
|
||||||
Glow.previewSettingsDraft = () => {
|
Glow.previewSettingsDraft = () => {
|
||||||
@ -78,8 +70,6 @@ Glow.previewSettingsDraft = () => {
|
|||||||
Glow.applyAccentColor(draft.accent_color);
|
Glow.applyAccentColor(draft.accent_color);
|
||||||
Glow.applyThemeMode(draft.theme_mode);
|
Glow.applyThemeMode(draft.theme_mode);
|
||||||
Glow.applyCustomCss(draft.custom_css || "");
|
Glow.applyCustomCss(draft.custom_css || "");
|
||||||
Glow.saveDmLayoutPreference(draft.dm_layout_mode || "cards");
|
|
||||||
Glow.state.profilePresenceBadgeVisible = draft.show_presence_badge !== false;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Glow.updateSettingsDraft = patch => {
|
Glow.updateSettingsDraft = patch => {
|
||||||
@ -89,7 +79,7 @@ Glow.updateSettingsDraft = patch => {
|
|||||||
...patch
|
...patch
|
||||||
};
|
};
|
||||||
Glow.previewSettingsDraft();
|
Glow.previewSettingsDraft();
|
||||||
Glow.markSettingsDirty();
|
Glow.markSettingsDirty?.();
|
||||||
};
|
};
|
||||||
|
|
||||||
Glow.syncSettingsSavePanel = () => {
|
Glow.syncSettingsSavePanel = () => {
|
||||||
@ -98,7 +88,7 @@ Glow.syncSettingsSavePanel = () => {
|
|||||||
|
|
||||||
const shouldShow =
|
const shouldShow =
|
||||||
Glow.state.activeView === "settings" &&
|
Glow.state.activeView === "settings" &&
|
||||||
Glow.isSettingsDirty();
|
Glow.isSettingsDirty?.();
|
||||||
|
|
||||||
panel.classList.toggle("hidden", !shouldShow);
|
panel.classList.toggle("hidden", !shouldShow);
|
||||||
|
|
||||||
@ -135,10 +125,7 @@ Glow.saveSettingsDraft = async () => {
|
|||||||
presence_mode:
|
presence_mode:
|
||||||
["online", "silent", "focus", "dnd"].includes(draft.presence_mode)
|
["online", "silent", "focus", "dnd"].includes(draft.presence_mode)
|
||||||
? draft.presence_mode
|
? draft.presence_mode
|
||||||
: "online",
|
: "online"
|
||||||
dm_layout_mode:
|
|
||||||
draft.dm_layout_mode === "compact" ? "compact" : "cards",
|
|
||||||
show_presence_badge: draft.show_presence_badge !== false
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const data = await Glow.apiUpdateMySettings(payload);
|
const data = await Glow.apiUpdateMySettings(payload);
|
||||||
@ -151,7 +138,7 @@ Glow.saveSettingsDraft = async () => {
|
|||||||
Glow.state.settingsSaved = Glow.cloneSettingsState(merged);
|
Glow.state.settingsSaved = Glow.cloneSettingsState(merged);
|
||||||
Glow.state.settingsDraft = Glow.cloneSettingsState(merged);
|
Glow.state.settingsDraft = Glow.cloneSettingsState(merged);
|
||||||
Glow.previewSettingsDraft();
|
Glow.previewSettingsDraft();
|
||||||
Glow.clearSettingsDirty();
|
Glow.clearSettingsDirty?.();
|
||||||
|
|
||||||
if (Glow.state.currentUser) {
|
if (Glow.state.currentUser) {
|
||||||
Glow.state.currentUser.presence_mode =
|
Glow.state.currentUser.presence_mode =
|
||||||
@ -166,59 +153,22 @@ Glow.discardSettingsDraft = () => {
|
|||||||
const saved = Glow.state.settingsSaved || Glow.cloneSettingsState({});
|
const saved = Glow.state.settingsSaved || Glow.cloneSettingsState({});
|
||||||
Glow.state.settingsDraft = Glow.cloneSettingsState(saved);
|
Glow.state.settingsDraft = Glow.cloneSettingsState(saved);
|
||||||
Glow.previewSettingsDraft();
|
Glow.previewSettingsDraft();
|
||||||
Glow.clearSettingsDirty();
|
Glow.clearSettingsDirty?.();
|
||||||
if (Glow.state.activeView === "settings") {
|
if (Glow.state.activeView === "settings") {
|
||||||
Glow.renderSettingsView();
|
Glow.renderSettingsView();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Glow.closeSettingsViewRequested = async () => {
|
|
||||||
if (!Glow.isSettingsDirty()) {
|
|
||||||
await Glow.openFeed?.();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
const values = await Glow.openDialog({
|
|
||||||
title: "Unsaved settings changes",
|
|
||||||
body: "You have unsaved settings changes. Save them before leaving?",
|
|
||||||
confirmText: "Save and leave",
|
|
||||||
cancelText: "Stay"
|
|
||||||
});
|
|
||||||
|
|
||||||
if (values === null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
await Glow.saveSettingsDraft();
|
|
||||||
await Glow.openFeed?.();
|
|
||||||
return true;
|
|
||||||
} catch (error) {
|
|
||||||
Glow.showToast(error.message || "Could not save settings.", "error");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
Glow.loadMySettings = async () => {
|
Glow.loadMySettings = async () => {
|
||||||
try {
|
try {
|
||||||
const data = await Glow.apiGetMySettings();
|
const data = await Glow.apiGetMySettings();
|
||||||
const base = Glow.cloneSettingsState({
|
const base = Glow.cloneSettingsState(data.settings || {});
|
||||||
...(data.settings || {}),
|
|
||||||
dm_layout_mode:
|
|
||||||
data.settings?.dm_layout_mode || Glow.loadDmLayoutPreference(),
|
|
||||||
show_presence_badge:
|
|
||||||
typeof data.settings?.show_presence_badge === "boolean"
|
|
||||||
? data.settings.show_presence_badge
|
|
||||||
: Glow.state.profilePresenceBadgeVisible !== false
|
|
||||||
});
|
|
||||||
Glow.initializeSettingsDraft(base);
|
Glow.initializeSettingsDraft(base);
|
||||||
Glow.previewSettingsDraft();
|
Glow.previewSettingsDraft();
|
||||||
} catch (_) {
|
} catch (_) {
|
||||||
const fallback = Glow.cloneSettingsState({
|
const fallback = Glow.cloneSettingsState({
|
||||||
theme_mode: localStorage.getItem("glow_theme_mode") || "dark",
|
theme_mode: localStorage.getItem("glow_theme_mode") || "dark",
|
||||||
accent_color: Glow.state.accentColor,
|
accent_color: Glow.state.accentColor,
|
||||||
dm_layout_mode: Glow.loadDmLayoutPreference(),
|
|
||||||
show_presence_badge: Glow.state.profilePresenceBadgeVisible !== false,
|
|
||||||
profile_visibility: "public",
|
profile_visibility: "public",
|
||||||
last_active_visibility: "everyone",
|
last_active_visibility: "everyone",
|
||||||
presence_mode: "online"
|
presence_mode: "online"
|
||||||
@ -359,6 +309,7 @@ Glow.toggleHeaderMenu = () => {
|
|||||||
Glow.openSettings = async () => {
|
Glow.openSettings = async () => {
|
||||||
Glow.state.activeView = "settings";
|
Glow.state.activeView = "settings";
|
||||||
Glow.updateViewUI();
|
Glow.updateViewUI();
|
||||||
|
|
||||||
if (!Glow.state.settingsSaved && Glow.state.currentUser) {
|
if (!Glow.state.settingsSaved && Glow.state.currentUser) {
|
||||||
await Glow.loadMySettings();
|
await Glow.loadMySettings();
|
||||||
} else if (!Glow.state.settingsDraft) {
|
} else if (!Glow.state.settingsDraft) {
|
||||||
@ -367,6 +318,7 @@ Glow.openSettings = async () => {
|
|||||||
);
|
);
|
||||||
Glow.previewSettingsDraft();
|
Glow.previewSettingsDraft();
|
||||||
}
|
}
|
||||||
|
|
||||||
Glow.renderSettingsView();
|
Glow.renderSettingsView();
|
||||||
Glow.syncSettingsSavePanel();
|
Glow.syncSettingsSavePanel();
|
||||||
};
|
};
|
||||||
@ -501,35 +453,6 @@ Glow.renderSettingsView = () => {
|
|||||||
resetNameColor
|
resetNameColor
|
||||||
);
|
);
|
||||||
|
|
||||||
const dmLayout = Glow.renderChoicePills({
|
|
||||||
label: "DM layout",
|
|
||||||
value: draft.dm_layout_mode || "cards",
|
|
||||||
options: [
|
|
||||||
{ value: "cards", label: "Cards" },
|
|
||||||
{ value: "compact", label: "Compact" }
|
|
||||||
],
|
|
||||||
onChange: value => {
|
|
||||||
Glow.updateSettingsDraft({ dm_layout_mode: value });
|
|
||||||
Glow.loadDms?.().catch(() => {});
|
|
||||||
Glow.renderSettingsView();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
const presenceBadge = Glow.renderChoicePills({
|
|
||||||
label: "Profile presence badge",
|
|
||||||
value: draft.show_presence_badge === false ? "hidden" : "shown",
|
|
||||||
options: [
|
|
||||||
{ value: "shown", label: "Shown" },
|
|
||||||
{ value: "hidden", label: "Hidden" }
|
|
||||||
],
|
|
||||||
onChange: value => {
|
|
||||||
Glow.updateSettingsDraft({
|
|
||||||
show_presence_badge: value !== "hidden"
|
|
||||||
});
|
|
||||||
Glow.renderSettingsView();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
const profileVisibility = Glow.renderChoicePills({
|
const profileVisibility = Glow.renderChoicePills({
|
||||||
label: "Profile visibility",
|
label: "Profile visibility",
|
||||||
value: draft.profile_visibility || "public",
|
value: draft.profile_visibility || "public",
|
||||||
@ -583,8 +506,6 @@ Glow.renderSettingsView = () => {
|
|||||||
iTitle,
|
iTitle,
|
||||||
iText,
|
iText,
|
||||||
nameColorWrap,
|
nameColorWrap,
|
||||||
dmLayout,
|
|
||||||
presenceBadge,
|
|
||||||
profileVisibility,
|
profileVisibility,
|
||||||
lastActiveVisibility,
|
lastActiveVisibility,
|
||||||
presenceMode
|
presenceMode
|
||||||
@ -701,7 +622,8 @@ Glow.renderSettingsView = () => {
|
|||||||
|
|
||||||
bannerLabel.append(bannerInput);
|
bannerLabel.append(bannerInput);
|
||||||
bannerWrap.append(bannerLabel);
|
bannerWrap.append(bannerLabel);
|
||||||
profileVisuals.append(pvTitle, pvText, backgroundWrap, bannerLabel);
|
|
||||||
|
profileVisuals.append(pvTitle, pvText, backgroundWrap, bannerWrap);
|
||||||
|
|
||||||
const cssSection = document.createElement("section");
|
const cssSection = document.createElement("section");
|
||||||
cssSection.className = "settings-section";
|
cssSection.className = "settings-section";
|
||||||
@ -781,7 +703,7 @@ Glow.els.settingsSaveButton?.addEventListener("click", async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
Glow.els.settingsCloseButton?.addEventListener("click", async () => {
|
Glow.els.settingsCloseButton?.addEventListener("click", async () => {
|
||||||
if (!Glow.isSettingsDirty()) {
|
if (!Glow.isSettingsDirty?.()) {
|
||||||
await Glow.openFeed?.();
|
await Glow.openFeed?.();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user