Skip to content

Commit

Permalink
update for livewire 3
Browse files Browse the repository at this point in the history
  • Loading branch information
freekmurze committed Oct 3, 2023
1 parent 3f7fa03 commit af166f0
Showing 1 changed file with 62 additions and 77 deletions.
139 changes: 62 additions & 77 deletions resources/views/dashboard.blade.php
Original file line number Diff line number Diff line change
@@ -1,85 +1,70 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>Dashboard</title>
<meta name="google" value="notranslate">
<meta name="csrf-token" content="{{ csrf_token() }}">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">

{{ $assets }}

@stack('assets')

<livewire:styles />
</head>
<body class="leading-snug">
<div
x-data="theme('{{ $theme }}', '{{ $initialMode }}')"
x-init="init"
:class="mode === 'dark' ? 'dark-mode' : ''"
>
<div class="fixed inset-0 w-screen h-screen grid gap-2 p-2 bg-canvas text-default">
<livewire:dashboard-update-mode />

{{ $slot }}
</div>
</div>

<livewire:scripts />

@stack('scripts')

<script>
const theme = (theme, initialMode) => ({
theme,
mode: initialMode,
init() {
if (this.theme === 'device') {
this.detectDeviceColorScheme();
return;
}
if (this.theme === 'auto') {
this.listenForUpdateModeEvent();
return;
}
},
detectDeviceColorScheme() {
const mediaQuery = matchMedia("(prefers-color-scheme: dark)");
this.mode = mediaQuery.matches ? 'dark' : 'light';
mediaQuery.addListener((event) => {
this.mode = mediaQuery.matches ? 'dark' : 'light';
});
},
listenForUpdateModeEvent() {
window.Livewire.on('updateMode', newMode => {
if (newMode !== this.mode) {
this.mode = newMode;
}
})
},
<head>
<title>Dashboard</title>
<meta name="google" value="notranslate">
<meta name="csrf-token" content="{{ csrf_token() }}">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">

{{ $assets }}

@stack('assets')
</head>
<body class="leading-snug">
<div
x-data="theme('{{ $theme }}', '{{ $initialMode }}')"
x-init="init"
:class="mode === 'dark' ? 'dark-mode' : ''"
>
<div class="fixed inset-0 w-screen h-screen grid gap-2 p-2 bg-canvas text-default">
<livewire:dashboard-update-mode/>

{{ $slot }}
</div>
</div>

@stack('scripts')

<script>
const theme = (theme, initialMode) => ({
theme,
mode: initialMode,
init() {
if (this.theme === 'device') {
this.detectDeviceColorScheme();
return;
}
if (this.theme === 'auto') {
this.listenForUpdateModeEvent();
return;
}
},
detectDeviceColorScheme() {
const mediaQuery = matchMedia("(prefers-color-scheme: dark)");
this.mode = mediaQuery.matches ? 'dark' : 'light';
mediaQuery.addListener((event) => {
this.mode = mediaQuery.matches ? 'dark' : 'light';
});
},
Livewire.hook('request', ({ fail }) => {
fail(({ status, preventDefault }) => {
if (status === 419) {
preventDefault()
}
})
window.location.reload();
listenForUpdateModeEvent() {
window.Livewire.on('updateMode', newMode => {
if (newMode !== this.mode) {
this.mode = newMode;
}
})
</script>
},
});
</script>


</body>
</body>
</html>

0 comments on commit af166f0

Please sign in to comment.