Skip to content

Commit

Permalink
Global config to backstore (#398)
Browse files Browse the repository at this point in the history
* Loading config variables also in backstore

* Wait some ms before assuming there is no configuration file

* Updating npm packages
  • Loading branch information
ktecho authored Feb 16, 2024
1 parent 2daefea commit 958308b
Show file tree
Hide file tree
Showing 9 changed files with 98 additions and 39 deletions.
32 changes: 16 additions & 16 deletions web/backoffice/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions web/backoffice/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
"@sveltejs/vite-plugin-svelte": "^3.0.2",
"autoprefixer": "^10.4.17",
"btc2fiat": "*",
"daisyui": "^4.6.1",
"daisyui": "^4.7.2",
"eslint": "^8.56.0",
"eslint-plugin-svelte": "^2.35.1",
"nostr-tools": "^1.13.1",
"npm-run-all": "4.x",
"postcss": "^8.4.33",
"svelte": "^4.2.9",
"svelte-check": "^3.6.3",
"postcss": "^8.4.35",
"svelte": "^4.2.11",
"svelte-check": "^3.6.4",
"svelte-toasts": "1.x",
"tailwindcss": "^3.4.1",
"typescript": "^5.0.0",
Expand Down
16 changes: 16 additions & 0 deletions web/backoffice/src/routes/+layout.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import {getConfigurationFromFile} from "$sharedLib/utils";
import {fileConfiguration} from "$sharedLib/stores";
import { browser } from "$app/environment";

// Load configuration from file before
// any other component code runs
async function loadConfig() {
let config = await getConfigurationFromFile() ?? {};
config.backend_present = true;
fileConfiguration.set(config);
}

if (browser) {
loadConfig()
.catch(error => console.log('Error while trying to load config from file:', error));
}
40 changes: 39 additions & 1 deletion web/backoffice/src/routes/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,51 @@
import { browser } from '$app/environment';
import { page } from '$app/stores';
import { user } from "$lib/stores";
import { Info, Error, token, NostrPublicKey } from "$sharedLib/stores";
import {
Info,
Error,
token,
NostrPublicKey,
fileConfiguration,
isSuperAdmin,
NostrGlobalConfig
} from "$sharedLib/stores";
import type { Placement } from "$sharedLib/stores";
import { getProfile } from "$lib/services/api";
import Navbar from "$sharedLib/components/Navbar.svelte";
import Footer from "$sharedLib/components/Footer.svelte";
import LoginModalLightning from "$lib/components/auth/Modal.svelte";
import LoginModal from "$sharedLib/components/login/Modal.svelte";
import {getConfigurationKey, subscribeConfiguration} from "$sharedLib/services/nostr";
function subscribeGlobalConf() {
let receivedAt = 0;
const serializedGlobalConfig = localStorage.getItem("NostrGlobalConfig");
if (serializedGlobalConfig) {
$NostrGlobalConfig = JSON.parse(serializedGlobalConfig);
receivedAt = parseInt(localStorage.getItem("NostrGlobalConfigReceivedAt") ?? '0');
}
subscribeConfiguration($fileConfiguration.admin_pubkeys, [getConfigurationKey('site_specific_config')],
(setup, rcAt) => {
if (rcAt > receivedAt) {
receivedAt = rcAt;
$NostrGlobalConfig = setup;
localStorage.setItem('NostrGlobalConfig', JSON.stringify(setup));
localStorage.setItem('NostrGlobalConfigReceivedAt', receivedAt.toString());
}
});
}
$: if ($fileConfiguration?.admin_pubkeys?.length > 0) {
subscribeGlobalConf();
}
$: if ($NostrPublicKey && $fileConfiguration?.admin_pubkeys?.includes($NostrPublicKey)) {
$isSuperAdmin = true;
}
const infoUnsubscribe = Info.subscribe(value => {
if (value) {
Expand Down
14 changes: 7 additions & 7 deletions web/frontoffice/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion web/frontoffice/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"eslint-plugin-svelte": "^2.35.1",
"npm-run-all": "4.x",
"postcss": "^8.4.35",
"svelte": "^4.2.10",
"svelte": "^4.2.11",
"svelte-check": "^3.6.4",
"svelte-dnd-action": "^0.9.38",
"svelte-meta-tags": "^3.1.0",
Expand Down
16 changes: 8 additions & 8 deletions web/shared/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions web/shared/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
"eslint": "^8.56.0",
"eslint-plugin-svelte": "^2.35.1",
"publint": "^0.2.7",
"svelte": "^4.2.10",
"svelte-check": "^3.6.3",
"svelte": "^4.2.11",
"svelte-check": "^3.6.4",
"tslib": "^2.6.2",
"typescript": "^5.0.0",
"vite": "^5.0.12"
Expand Down
5 changes: 5 additions & 0 deletions web/shared/src/lib/components/Navbar.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@
virtualPages = getPages();
let retries = 5;
while ((!$fileConfiguration || Object.keys($fileConfiguration).length === 0) && retries-- > 0) {
await new Promise(resolve => setTimeout(resolve, 30));
}
if ($fileConfiguration?.admin_pubkeys?.length > 0) {
let allPagesListReceivedAt = 0;
Expand Down

0 comments on commit 958308b

Please sign in to comment.