Seperate themes and layouts into seperate settings #63

Merged
twig merged 13 commits from better-themes into main 2025-08-05 21:47:20 +00:00
Showing only changes of commit a81fc4739a - Show all commits

View file

@ -9,7 +9,7 @@
<div v-for="style of styles" class="theme-preview-container">
<span class="theme-instance"
:title="style.displayName"
@click="changeTheme(StyleLayout.style, style)">
@click="changeTheme(styleLayout.style, style)">
<div class="theme-content-container">
<span class="style-background"
:style="{background:`linear-gradient(${style.previewGradient})`}"
@ -26,7 +26,7 @@
<div v-for="layout of layouts" class="theme-preview-container">
<div class="theme-instance"
:title="layout.displayName"
@click="changeTheme(StyleLayout.layout, layout)">
@click="changeTheme(styleLayout.layout, layout)">
<div class="theme-content-container">
<span class="layout-background"
:style="{backgroundImage:`url(${layout.previewImageUrl})`}"
@ -65,7 +65,7 @@ const layoutFolder = `${baseURL}themes/layout`
const timeFormatTextStrings = ["Auto", "12-Hour", "24-Hour"]
enum StyleLayout {
enum styleLayout {
twig marked this conversation as resolved Outdated

Enum options should use PascalCase

Enum options should use PascalCase
twig marked this conversation as resolved Outdated

Both enum and enum options should use PascalCase/CamelCase, that's what I meant.

enum StyleLayout  {
  Style,
  Layout
}
Both _enum_ and enum _options_ should use PascalCase/CamelCase, that's what I meant. ```ts enum StyleLayout { Style, Layout } ```

okay this makes more sense

okay this makes more sense
style,
layout
}
@ -88,7 +88,7 @@ async function parseTheme(url: string): Promise<Theme | void> {
const metadataMatch = styleData.match(/\/\*([\s\S]*?)\*\//);
if (!metadataMatch) {
alert(`Failed to fetch metadata for a theme, panicing`)
alert(`Failed to fetch metadata for a theme, panicking`)
twig marked this conversation as resolved Outdated

Should be "panicking"

Should be "panicking"
return
}
@ -101,20 +101,20 @@ async function parseTheme(url: string): Promise<Theme | void> {
let previewImageUrl: string | undefined
for (const line of commentContent) {
const line_array = line.split("=")
if (line_array.length === 2) {
switch (line_array[0].trim()) {
const lineArray = line.split("=")
twig marked this conversation as resolved Outdated

lineArray please

`lineArray` please
if (lineArray.length === 2) {
switch (lineArray[0].trim()) {
case "displayName":
displayName = line_array[1].trim()
displayName = lineArray[1].trim()
break
case "complementaryColor":
complementaryColor = line_array[1].trim()
complementaryColor = lineArray[1].trim()
break
case "previewGradient":
previewGradient = line_array[1].trim()
previewGradient = lineArray[1].trim()
break
case "previewImageUrl":
previewImageUrl = `${layoutFolder}/${line_array[1].trim()}`
previewImageUrl = `${layoutFolder}/${lineArray[1].trim()}`
break
}
}
@ -137,8 +137,8 @@ async function parseTheme(url: string): Promise<Theme | void> {
async function parseThemeLayout(
folder: string,
incomingThemeList: Array<string>,
outputThemeList: Array<Theme>) {
incomingThemeList: string[],
twig marked this conversation as resolved Outdated

string[] instead of Array<string>

`string[]` instead of `Array<string>`
outputThemeList: Theme[]) {
twig marked this conversation as resolved Outdated

string[] instead of Array<string>

`string[]` instead of `Array<string>`
for (const theme of incomingThemeList) {
const parsedThemeData = await parseTheme(`${folder}/${theme}`)
@ -148,11 +148,11 @@ async function parseThemeLayout(
}
}
const styles: Array<Theme> = [];
const layouts: Array<Theme> = [];
const styles: Theme[] = [];
twig marked this conversation as resolved Outdated

string[] instead of Array<string>

`string[]` instead of `Array<string>`
const layouts: Theme[] = [];
twig marked this conversation as resolved Outdated

Theme[] instead of Array<Theme>

`Theme[]` instead of `Array<Theme>`
const styleList: any = await $fetch(`${styleFolder}/styles.json`)
const layoutList: any = await $fetch(`${layoutFolder}/layouts.json`)
const styleList = await $fetch(`${styleFolder}/styles.json`)
twig marked this conversation as resolved Outdated

Avoid use of any

Avoid use of `any`
const layoutList = await $fetch(`${layoutFolder}/layouts.json`)
twig marked this conversation as resolved Outdated

Avoid use of any

Avoid use of `any`
if (Array.isArray(styleList)) {
await parseThemeLayout(styleFolder, styleList, styles)
@ -161,8 +161,8 @@ if (Array.isArray(layoutList)) {
await parseThemeLayout(layoutFolder, layoutList, layouts)
}
function changeTheme(themeType: StyleLayout, theme: Theme) {
if (themeType == StyleLayout.style) {
function changeTheme(themeType: styleLayout, theme: Theme) {
if (themeType == styleLayout.style) {
settingSave("selectedThemeStyle", theme.themeUrl)
} else {
settingSave("selectedThemeLayout", theme.themeUrl)