Skip to content

Commit

Permalink
fix(svelte): remove svelte-navigator from repository (#221)
Browse files Browse the repository at this point in the history
* Remove svelte-navigator

* add missing hash for initial state + theme from query

---------

Co-authored-by: Vladimir Kharlampidi <[email protected]>
  • Loading branch information
ilyakamens and nolimits4web authored Sep 18, 2024
1 parent 6c5b7eb commit ebe0b80
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 180 deletions.
4 changes: 3 additions & 1 deletion kitchen-sink/react/components/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import routes from '../routes.js';
import HomePage from '../pages/Home.jsx';

function App() {
const [theme, setTheme] = useState('ios');
const [theme, setTheme] = useState(
window.location.search.includes('theme=material') ? 'material' : 'ios'
);
const [currentColorTheme, setCurrentColorTheme] = useState('');
const setColorTheme = (color) => {
const htmlEl = document.documentElement;
Expand Down
41 changes: 23 additions & 18 deletions kitchen-sink/svelte/components/App.svelte
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
<script>
import { onMount, beforeUpdate } from 'svelte';
import { onMount, onDestroy, beforeUpdate } from 'svelte';
import { App } from 'konsta/svelte';
import { Router, Route, createHistory } from 'svelte-navigator';
import createHashSource from '../hashHistory.js';
import routes from '../routes.js';
import HomePage from '../pages/Home.svelte';
let theme = 'ios';
let theme = window.location.search.includes('theme=material') ? 'material' : 'ios';
const setTheme = (t) => {
theme = t;
};
Expand Down Expand Up @@ -42,29 +40,36 @@
}
};
let hash = window.location.hash || '';
function updateHash() {
hash = window.location.hash;
}
onMount(() => {
calcSafeAreas();
window.addEventListener('popstate', updateHash);
});
beforeUpdate(() => {
calcSafeAreas();
});
const hash = createHistory(createHashSource());
onDestroy(() => {
window.removeEventListener('popstate', updateHash);
});
$: component = routes.find(route => route.path === hash.slice(1))?.component;
</script>
<App {theme} safeAreas={!inIFrame}>
<Router history={hash} primary={false}>
<Route path="/">
<HomePage
{theme}
{setTheme}
colorTheme={currentColorTheme}
{setColorTheme}
/>
</Route>
{#each routes as route}
<Route path={route.path} component={route.component} />
{/each}
</Router>
{#if component}
<svelte:component this={component} />
{:else}
<HomePage
{theme}
{setTheme}
colorTheme={currentColorTheme}
{setColorTheme}
/>
{/if}
</App>
43 changes: 0 additions & 43 deletions kitchen-sink/svelte/hashHistory.js

This file was deleted.

4 changes: 3 additions & 1 deletion kitchen-sink/vue/components/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
kApp,
},
setup() {
const theme = ref('ios');
const theme = ref(
window.location.search.includes('theme=material') ? 'material' : 'ios'
);
const currentColorTheme = ref('');
const setColorTheme = (color) => {
const htmlEl = document.documentElement;
Expand Down
117 changes: 2 additions & 115 deletions package-lock.json

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

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@
"react-router-dom": "^6.26.1",
"rollup": "^4.21.0",
"svelte": "^5.0.0-next.241",
"svelte-navigator": "^3.2.2",
"tailwindcss": "^3.4.10",
"vite": "^5.4.2",
"vue": "^3.4.38",
Expand All @@ -73,4 +72,4 @@
"dependencies": {
"konsta": "file:src"
}
}
}

0 comments on commit ebe0b80

Please sign in to comment.