try to get list of themes from server side

This commit is contained in:
Felix Ableitner 2022-02-16 15:18:25 +01:00
parent 904d33e895
commit 8049ce6abf
5 changed files with 446 additions and 414 deletions

View file

@ -19,6 +19,7 @@
"dependencies": { "dependencies": {
"@typescript-eslint/parser": "^5.6.0", "@typescript-eslint/parser": "^5.6.0",
"autosize": "^5.0.1", "autosize": "^5.0.1",
"buffer": "^6.0.3",
"check-password-strength": "^2.0.3", "check-password-strength": "^2.0.3",
"choices.js": "^10.0.0", "choices.js": "^10.0.0",
"classnames": "^2.3.1", "classnames": "^2.3.1",

View file

@ -66,7 +66,8 @@ server.get("/css/themes-list", async (req, res) => {
"litely", "litely",
"nord", "nord",
]; ];
fs.readdir(extraThemesFolder, function (err, data) { fs.readdir(extraThemesFolder, function (_, data) {
if (data != null) {
data = data data = data
.filter(d => d.endsWith(".min.css")) .filter(d => d.endsWith(".min.css"))
.map(d => d.replace(".min.css", "")); .map(d => d.replace(".min.css", ""));
@ -74,10 +75,14 @@ server.get("/css/themes-list", async (req, res) => {
// use set to remove duplicate values // use set to remove duplicate values
data = Array.from(new Set(data)); data = Array.from(new Set(data));
res.send(data); res.send(data);
} else {
res.send(builtinThemes);
}
}); });
}); });
server.get("/css/themes/:name", async (req, res) => { server.get("/css/themes/:name", async (req, res) => {
res.contentType("text/css");
const theme = req.params.name; const theme = req.params.name;
if (!theme.endsWith(".css")) { if (!theme.endsWith(".css")) {
res.send("Theme must be a css file"); res.send("Theme must be a css file");

View file

@ -29,6 +29,7 @@ import {
debounce, debounce,
elementUrl, elementUrl,
fetchCommunities, fetchCommunities,
fetchThemes,
fetchUsers, fetchUsers,
getLanguage, getLanguage,
getNativeLanguageName, getNativeLanguageName,
@ -40,7 +41,6 @@ import {
setTheme, setTheme,
setupTippy, setupTippy,
showLocal, showLocal,
themes,
toast, toast,
updateCommunityBlock, updateCommunityBlock,
updatePersonBlock, updatePersonBlock,
@ -548,7 +548,7 @@ export class Settings extends Component<any, SettingsState> {
{i18n.t("theme")} {i18n.t("theme")}
</option> </option>
<option value="browser">{i18n.t("browser_default")}</option> <option value="browser">{i18n.t("browser_default")}</option>
{themes.map(theme => ( {fetchThemes().map(theme => (
<option value={theme}>{theme}</option> <option value={theme}>{theme}</option>
))} ))}
</select> </select>

View file

@ -166,24 +166,22 @@ export const languages = [
{ code: "lt" }, { code: "lt" },
]; ];
export function themes() { export function fetchThemes(): Promise<string[]> {
const builtinThemes = [ var promise = new Promise<string[]>((resolve, reject) => {
"litera", if (isBrowser()) {
"materia", const url = `${window.location.protocol}//${window.location.host}/css/themes-list`;
"minty", console.log(url);
"solar", fetch(url).then(res => {
"united", res.json().then(json => {
"cyborg", console.log(json);
"darkly", resolve(json);
"journal", });
"sketchy", });
"vaporwave", } else {
"vaporwave-dark", listThemes().then(themes => resolve(themes));
"i386", }
"litely", });
"nord", return promise;
];
return builtinThemes;
} }
const DEFAULT_ALPHABET = const DEFAULT_ALPHABET =

800
yarn.lock

File diff suppressed because it is too large Load diff