Skip to content

Commit 66a34ae

Browse files
committed
MOBILE-5096 site-logo: Show logos depending on site
1 parent a8bb6dd commit 66a34ae

2 files changed

Lines changed: 36 additions & 14 deletions

File tree

src/core/classes/sites/unauthenticated-site.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { CorePath } from '@static/path';
2323
import { CoreJsonPatch, JsonPatchOperation } from '@static/json-patch';
2424
import { CoreUtils } from '@static/utils';
2525
import { CoreLogger } from '@static/logger';
26+
import { CoreSiteConfig } from './site';
2627

2728
/**
2829
* Class that represents a Moodle site where the user still hasn't authenticated.
@@ -187,22 +188,20 @@ export class CoreUnauthenticatedSite {
187188
* @param config Site public config.
188189
* @returns Logo URL.
189190
*/
191+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
190192
getLogoUrl(config?: CoreSitePublicConfigResponse): string | undefined {
191-
config = config ?? this.publicConfig;
192-
if (!config || this.forcesLocalLogo()) {
193-
return;
194-
}
195-
196-
return config.logourl || config.compactlogourl || undefined;
193+
return undefined;
197194
}
198195

199196
/**
200197
* Check show top logo mode.
201198
*
199+
* @param config Site config.
202200
* @returns The top logo mode.
203201
*/
204-
getShowTopLogo(): 'online' | 'offline' | 'hidden' {
205-
return this.isDemoModeSite() ? 'hidden' : CoreConstants.CONFIG.showTopLogo;
202+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
203+
getShowTopLogo(config?: CoreSiteConfig): 'online' | 'offline' | 'hidden' {
204+
return 'hidden';
206205
}
207206

208207
/**

src/core/components/site-logo/site-logo.ts

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
import { Component, OnInit, OnDestroy, input, computed, signal, effect } from '@angular/core';
15+
import { Component, OnInit, OnDestroy, input, computed, signal, effect, untracked } from '@angular/core';
1616
import { CoreSites } from '@services/sites';
1717
import { CoreEventObserver, CoreEvents } from '@static/events';
18-
import { CoreSite } from '@classes/sites/site';
18+
import { CoreSite, CoreSiteConfig } from '@classes/sites/site';
1919
import { toBoolean } from '@/core/transforms/boolean';
2020
import { CorePromiseUtils } from '@static/promise-utils';
2121
import { CoreUnauthenticatedSite } from '@classes/sites/unauthenticated-site';
@@ -51,14 +51,17 @@ export class CoreSiteLogoComponent implements OnInit, OnDestroy {
5151
const showLogo = this.showLogo();
5252
const logoError = this.logoError();
5353
const hideOnError = this.hideOnError();
54+
const siteConfig = this.siteConfig();
5455

55-
if (!showLogo || (logoType === CoreSiteLogoType.TOP && site.getShowTopLogo() === 'hidden')) {
56+
if (!showLogo || (logoType === CoreSiteLogoType.TOP && site.getShowTopLogo(siteConfig) === 'hidden')) {
5657
return false;
5758
}
5859

5960
return !logoError || !hideOnError;
6061
});
6162

63+
protected readonly siteConfig = signal<CoreSiteConfig | undefined>(undefined);
64+
6265
protected readonly siteEffective = computed<CoreSite | CoreUnauthenticatedSite>(() =>
6366
this.site() ?? CoreSites.getRequiredCurrentSite());
6467

@@ -88,7 +91,11 @@ export class CoreSiteLogoComponent implements OnInit, OnDestroy {
8891

8992
constructor() {
9093
effect(async () => {
91-
await this.loadInfo(this.siteEffective());
94+
const site = this.siteEffective();
95+
untracked(() => {
96+
void this.updateSiteConfig(site);
97+
void this.loadInfo(site);
98+
});
9299
});
93100

94101
}
@@ -98,7 +105,12 @@ export class CoreSiteLogoComponent implements OnInit, OnDestroy {
98105
*/
99106
async ngOnInit(): Promise<void> {
100107
this.updateSiteObserver = CoreEvents.on(CoreEvents.SITE_UPDATED, async () => {
101-
await this.loadInfo(this.siteEffective());
108+
const site = this.siteEffective();
109+
110+
untracked(() => {
111+
void this.updateSiteConfig(site);
112+
void this.loadInfo(site);
113+
});
102114
}, this.siteId());
103115
}
104116

@@ -111,6 +123,17 @@ export class CoreSiteLogoComponent implements OnInit, OnDestroy {
111123
this.logoError.set(!success);
112124
}
113125

126+
/**
127+
* Update the site config.
128+
*
129+
* @param site The site to update the config from.
130+
*/
131+
protected async updateSiteConfig(site: CoreSite | CoreUnauthenticatedSite): Promise<void> {
132+
if (site instanceof CoreSite && this.logoType() === CoreSiteLogoType.TOP) {
133+
this.siteConfig.set(await CorePromiseUtils.ignoreErrors(site.getConfig()));
134+
}
135+
}
136+
114137
/**
115138
* Load the site name, config and logo.
116139
*
@@ -120,7 +143,7 @@ export class CoreSiteLogoComponent implements OnInit, OnDestroy {
120143
const siteName = await site.getSiteName();
121144
this.siteName.set(siteName || '');
122145

123-
if (!this.showLogo() || (this.logoType() === CoreSiteLogoType.TOP && site.getShowTopLogo() === 'hidden')) {
146+
if (!this.showLogo() || (this.logoType() === CoreSiteLogoType.TOP && site.getShowTopLogo(this.siteConfig()) === 'hidden')) {
124147
return;
125148
}
126149

0 commit comments

Comments
 (0)