Skip to content

Commit 49e1697

Browse files
author
yashrajbharticybtekk
committed
UI fixes
1 parent 823476a commit 49e1697

File tree

2 files changed

+56
-7
lines changed

2 files changed

+56
-7
lines changed

js/app-details.mjs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,18 @@ export class AppDetailsComponent extends HTMLElement {
3636
};
3737
}
3838

39+
processContent(content) {
40+
let processedContent = content.replace(/\n/g, "<br>");
41+
const githubUrlRegex =
42+
/(https:\/\/github\.com\/LiquidGalaxyLAB\/)([^\s<>"']+)/g;
43+
processedContent = processedContent.replace(
44+
githubUrlRegex,
45+
'<md-assist-chip label="$2" href="$1$2" target="_blank"></md-assist-chip>'
46+
);
47+
48+
return processedContent;
49+
}
50+
3951
render() {
4052
const appData = this.data;
4153
if (!appData) {
@@ -78,14 +90,14 @@ export class AppDetailsComponent extends HTMLElement {
7890
margin: 0;
7991
}
8092
81-
md-assist-chip {
93+
.type {
8294
text-transform: capitalize;
8395
}
8496
</style>
8597
8698
<div>
8799
<h2>About ${name}</h2>
88-
<md-assist-chip label="${type}" href="./index.html?app=${type}"></md-assist-chip>
100+
<md-assist-chip class="type" label="${type}" href="./index.html?app=${type}"></md-assist-chip>
89101
<div class="info">
90102
<p><strong><md-icon>schedule</md-icon></strong> ${date}</p>
91103
${
@@ -96,7 +108,7 @@ export class AppDetailsComponent extends HTMLElement {
96108
<p><strong><md-icon>history</md-icon></strong>Version ${version}</p>
97109
</div>
98110
<div class="content">
99-
<p>${content.replace(/\n/g, "<br>")}</p>
111+
<p>${this.processContent(content)}</p>
100112
</div>
101113
</div>
102114
`;

js/carousel-component.mjs

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,13 @@ export class CarouselComponent extends HTMLElement {
44
constructor() {
55
super();
66
this.attachShadow({ mode: "open" });
7+
this.isPortrait = false;
8+
this.PORTRAIT_WIDTH = 250;
9+
this.LANDSCAPE_WIDTH = 500;
710
}
811

9-
connectedCallback() {
12+
async connectedCallback() {
13+
await this.checkImageOrientation();
1014
this.render();
1115
this.setupCarousel();
1216
}
@@ -37,7 +41,9 @@ export class CarouselComponent extends HTMLElement {
3741
}
3842
3943
.carousel-item {
40-
flex: 0 0 500px;
44+
flex: 0 0 ${
45+
this.isPortrait ? this.PORTRAIT_WIDTH : this.LANDSCAPE_WIDTH
46+
}px;
4147
max-inline-size: 100%;
4248
scroll-snap-align: center;
4349
display: flex;
@@ -93,6 +99,33 @@ export class CarouselComponent extends HTMLElement {
9399
return [data.carousel_assets, data.base_url];
94100
}
95101

102+
async checkImageOrientation() {
103+
const assets = this.carouselAssets[0];
104+
const baseUrl = this.carouselAssets[1];
105+
106+
const firstWebpImage = assets.find((asset) => asset.endsWith(".webp"));
107+
108+
if (firstWebpImage) {
109+
const imageUrl = `https://raw.githubusercontent.com/LiquidGalaxyLAB/Data/refs/heads/main${
110+
baseUrl + firstWebpImage
111+
}`;
112+
113+
try {
114+
const img = new Image();
115+
await new Promise((resolve, reject) => {
116+
img.onload = () => resolve();
117+
img.onerror = () => reject();
118+
img.src = imageUrl;
119+
});
120+
121+
this.isPortrait = img.height > img.width;
122+
} catch (error) {
123+
console.warn("Could not load image for orientation check:", error);
124+
this.isPortrait = false;
125+
}
126+
}
127+
}
128+
96129
setupCarousel() {
97130
const carousel = this.shadowRoot.querySelector(".carousel");
98131
const prevButton = this.shadowRoot.querySelector(".prev");
@@ -105,7 +138,9 @@ export class CarouselComponent extends HTMLElement {
105138
scrollToNext(carousel) {
106139
const prevButton = this.shadowRoot.querySelector(".prev");
107140
const nextButton = this.shadowRoot.querySelector(".next");
108-
const itemWidth = 500;
141+
const itemWidth = this.isPortrait
142+
? this.PORTRAIT_WIDTH
143+
: this.LANDSCAPE_WIDTH;
109144
const maxScrollLeft = carousel.scrollWidth - carousel.clientWidth;
110145
if (carousel.scrollLeft + itemWidth >= maxScrollLeft)
111146
nextButton.setAttribute("disabled", "true");
@@ -117,7 +152,9 @@ export class CarouselComponent extends HTMLElement {
117152
scrollToPrev(carousel) {
118153
const prevButton = this.shadowRoot.querySelector(".prev");
119154
const nextButton = this.shadowRoot.querySelector(".next");
120-
const itemWidth = 500;
155+
const itemWidth = this.isPortrait
156+
? this.PORTRAIT_WIDTH
157+
: this.LANDSCAPE_WIDTH;
121158
if (carousel.scrollLeft <= 0) prevButton.setAttribute("disabled", "true");
122159
nextButton?.removeAttribute("disabled");
123160

0 commit comments

Comments
 (0)