Skip to content

Commit 0fcbe0f

Browse files
committed
Merge branch 'dev'
2 parents f2738a8 + e375620 commit 0fcbe0f

File tree

4 files changed

+41
-17
lines changed

4 files changed

+41
-17
lines changed

images/web-stories-min.png

70.9 KB
Loading

src/app/components/accent-switcher/accent-switcher.component.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, OnInit, OnDestroy, ChangeDetectorRef } from '@angular/core';
1+
import { Component, OnDestroy, ChangeDetectorRef } from '@angular/core';
22
import { Subscription } from 'rxjs';
33
import { AccentService } from 'src/app/services/accent-service.service';
44

@@ -7,13 +7,18 @@ import { AccentService } from 'src/app/services/accent-service.service';
77
templateUrl: './accent-switcher.component.html',
88
styleUrls: ['./accent-switcher.component.scss']
99
})
10-
export class AccentSwitcherComponent implements OnInit, OnDestroy {
10+
export class AccentSwitcherComponent implements OnDestroy {
1111
images: Array<string>;
1212
selected: string;
1313
accentSubscription: Subscription;
1414
customImageSubscription: Subscription;
1515
customImage: string | ArrayBuffer | null = null;
1616
index: number = 1;
17+
titleMappings: { [key: string]: string } = {
18+
"primary": "Dartegnian Blue",
19+
"secondary": "Vibrant Green",
20+
"tertiary": "Filling Station Purple",
21+
};
1722

1823
constructor(
1924
private accent: AccentService,
@@ -40,9 +45,6 @@ export class AccentSwitcherComponent implements OnInit, OnDestroy {
4045
);
4146
}
4247

43-
ngOnInit(): void {
44-
}
45-
4648
ngOnDestroy(): void {
4749
this.accentSubscription.unsubscribe();
4850
this.customImageSubscription.unsubscribe();
@@ -68,7 +70,8 @@ export class AccentSwitcherComponent implements OnInit, OnDestroy {
6870

6971
removeCustomImage() {
7072
this.customImage = null;
71-
this.accent.setCustomImage(null, true);
73+
this.accent.setCustomImage(null);
74+
this.changeAccent(1, "primary");
7275
}
7376

7477
private getFileDataUrl(file: File): Promise<string> {

src/app/components/other-sites/other-sites.component.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import { Component, OnInit } from '@angular/core';
1+
import { Component } from '@angular/core';
22

33
@Component({
44
selector: 'other-sites',
55
templateUrl: './other-sites.component.html',
66
styleUrls: ['./other-sites.component.scss']
77
})
8-
export class OtherSitesComponent implements OnInit {
8+
export class OtherSitesComponent {
99
otherSites: any[];
1010

1111
constructor() {
@@ -28,6 +28,12 @@ export class OtherSitesComponent implements OnInit {
2828
image: "blog",
2929
description: "My new blog that's self-hosted and powered by Ghost CMS. Has a custom theme with my standard Material You color scheme."
3030
},
31+
{
32+
name: "Web Stories",
33+
link: "https://stories.dartegnian.com",
34+
image: "web-stories",
35+
description: "Stories from my life, now on the web. Accelerated Mobile Pages (AMPs) built from scratch using Next.js."
36+
},
3137
{
3238
name: "Forever One (WG-Easy)",
3339
link: "https://wg.dartegnian.com",
@@ -42,7 +48,4 @@ export class OtherSitesComponent implements OnInit {
4248
}
4349
];
4450
}
45-
46-
ngOnInit(): void {
47-
}
4851
}

src/app/services/accent-service.service.ts

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ export class AccentService {
2626
customImage: string | ArrayBuffer | null = null;
2727
customImageSubscription: Subject<string | ArrayBuffer>;
2828

29+
isPlaying = false;
30+
2931
constructor(
3032
private idb: IdbService,
3133
private meta: Meta
@@ -39,21 +41,29 @@ export class AccentService {
3941
index = Number(index);
4042
this.activeIndex = index;
4143
this.accentSubscription.next(index);
42-
this.setThemeFromM3();
4344
this.setThemeInIdb(index);
45+
46+
if (!this.isPlaying) {
47+
this.setThemeFromM3();
48+
}
4449
}
4550

4651
public setThemeMode(mode: "light" | "dark") {
4752
this.themeMode = mode;
48-
this.setThemeFromM3();
4953
this.themeSubscription.next(mode);
54+
55+
if (!this.isPlaying) {
56+
this.setThemeFromM3();
57+
}
5058
}
5159

52-
public setMetaTagColor() {
60+
public setMetaTagColor(theme?: Theme) {
61+
const primaryColorNumber: number = theme ? theme.schemes[this.themeMode].primaryContainer as number : this.themeRawColorData?.schemes[this.themeMode].primaryContainer as number;
62+
5363
this.meta.updateTag({
5464
name: "theme-color",
5565
content: this.argbToRgb(
56-
this.themeRawColorData?.schemes[this.themeMode].primaryContainer as number
66+
primaryColorNumber
5767
)
5868
});
5969
}
@@ -67,7 +77,7 @@ export class AccentService {
6777
});
6878
}
6979

70-
async setThemeFromM3(element?: HTMLImageElement) {
80+
async setThemeFromM3() {
7181
const theme = await this.setM3ColorAndTarget(
7282
"accent-" + this.images[this.activeIndex],
7383
document.body
@@ -136,7 +146,8 @@ export class AccentService {
136146

137147
async setM3ColorAndTarget(
138148
parentOfImg: string,
139-
target: string | HTMLElement
149+
target: string | HTMLElement,
150+
isSiteFrameThemed?: boolean
140151
) {
141152
let theme = null;
142153
const parentElement = document.getElementById(parentOfImg);
@@ -167,9 +178,16 @@ export class AccentService {
167178
dark: this.themeMode === "light" ? false : true
168179
}
169180
);
181+
}
170182

183+
if (theme && isSiteFrameThemed) {
184+
this.setMetaTagColor(theme);
171185
}
172186

173187
return theme;
174188
}
189+
190+
setIsPlaying(isPlaying: boolean): void {
191+
this.isPlaying = isPlaying;
192+
}
175193
}

0 commit comments

Comments
 (0)