refactor(builder): single language manager, theme before branding
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> P0 user feedback: General asked admins to type locale codes comma-separated, and Branding (logos) came before Theme (colors). - Root cause: General duplicated language management as raw text/CSV inputs while a full Languages manager section (add/remove/set-default with per-locale content seeding) already existed one tab away. Removed the duplicate inputs; General now shows a read-only chip summary (default language first, marked) with a 'Manage languages' link to the real manager. One source of truth, no comma parsing, no risk of bypassing LocaleSyncService - Builder navigation now orders Theme before Branding - merchants pick a palette first, then upload logos that match it - New builder keys (languagesSummaryDesc, manageLanguages) in en/ru/hy; verified in browser (chips RU-default/EN/HY, nav order theme->branding)
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
import { ChangeDetectionStrategy, Component, computed, inject } from '@angular/core';
|
||||
import { FormsModule } from '@angular/forms';
|
||||
import { RouterLink } from '@angular/router';
|
||||
import { ProjectEditorFacade } from '../facade/project-editor.facade';
|
||||
import { TranslatePipe } from '../../../i18n/translate.pipe';
|
||||
import { TranslateService } from '../../../i18n/translate.service';
|
||||
import { LanguageService } from '../../../services/language.service';
|
||||
import { InputComponent } from '../../../shared/ui/input/input.component';
|
||||
import { FormFieldComponent } from '../../../shared/ui/form-field/form-field.component';
|
||||
import { SectionCardComponent } from '../../../shared/ui/section-card/section-card.component';
|
||||
@@ -10,7 +12,7 @@ import { SectionCardComponent } from '../../../shared/ui/section-card/section-ca
|
||||
@Component({
|
||||
selector: 'app-project-editor-general-section',
|
||||
standalone: true,
|
||||
imports: [FormsModule, TranslatePipe, InputComponent, FormFieldComponent, SectionCardComponent],
|
||||
imports: [FormsModule, RouterLink, TranslatePipe, InputComponent, FormFieldComponent, SectionCardComponent],
|
||||
templateUrl: './general-section.component.html',
|
||||
styleUrls: ['./section.shared.scss'],
|
||||
changeDetection: ChangeDetectionStrategy.OnPush
|
||||
@@ -18,12 +20,29 @@ import { SectionCardComponent } from '../../../shared/ui/section-card/section-ca
|
||||
export class ProjectEditorGeneralSectionComponent {
|
||||
private readonly facade = inject(ProjectEditorFacade);
|
||||
private readonly translate = inject(TranslateService);
|
||||
private readonly languageService = inject(LanguageService);
|
||||
|
||||
readonly bootstrap = this.facade.bootstrap;
|
||||
readonly fieldError = (key: string): string | null => {
|
||||
const messageKey = this.facade.fieldError(key);
|
||||
return messageKey ? this.translate.t(messageKey) : null;
|
||||
};
|
||||
readonly languagesValue = computed(() => (this.bootstrap()?.localization.supportedLocales ?? []).join(', '));
|
||||
|
||||
/** Default locale first, so the chip list reads as "primary + others". */
|
||||
readonly orderedLocales = computed(() => {
|
||||
const localization = this.bootstrap()?.localization;
|
||||
if (!localization) {
|
||||
return [] as string[];
|
||||
}
|
||||
const rest = localization.supportedLocales.filter(code => code !== localization.defaultLocale);
|
||||
return [localization.defaultLocale, ...rest];
|
||||
});
|
||||
|
||||
readonly languagesRoute = computed(() => ['/', this.languageService.currentLanguage(), 'edit', 'languages']);
|
||||
|
||||
isDefaultLocale(code: string): boolean {
|
||||
return code === this.bootstrap()?.localization.defaultLocale;
|
||||
}
|
||||
|
||||
updateMarketplaceName(value: string): void {
|
||||
this.facade.updateBootstrap(current => ({
|
||||
@@ -52,34 +71,4 @@ export class ProjectEditorGeneralSectionComponent {
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
updateDefaultLanguage(value: string): void {
|
||||
this.facade.updateBootstrap(current => ({
|
||||
...current,
|
||||
tenant: { ...current.tenant, defaultLocale: value },
|
||||
localization: { ...current.localization, defaultLocale: value }
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* Routes through facade.addLocale()/removeLocale() (LocaleSyncService)
|
||||
* instead of overwriting supportedLocales directly - a direct overwrite
|
||||
* skipped seeding/cleaning up per-locale nav and static-page translation
|
||||
* entries, leaving them out of sync with what this field claims is
|
||||
* supported (and Languages' add/remove buttons already do it correctly).
|
||||
*/
|
||||
updateSupportedLanguages(value: string): void {
|
||||
const next = new Set(value.split(',').map(item => item.trim().toLowerCase()).filter(Boolean));
|
||||
const current = this.bootstrap()?.localization.supportedLocales ?? [];
|
||||
for (const locale of current) {
|
||||
if (!next.has(locale)) {
|
||||
this.facade.removeLocale(locale);
|
||||
}
|
||||
}
|
||||
for (const locale of next) {
|
||||
if (!current.includes(locale)) {
|
||||
this.facade.addLocale(locale);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user