Update setting

pull/1/head
I Made Setia Baruna 2021-01-07 22:42:26 +08:00
parent 8cf6e996f6
commit 33e14ec8e9
7 changed files with 153 additions and 36 deletions

View File

@ -6,6 +6,7 @@
const dispatch = createEventDispatcher(); const dispatch = createEventDispatcher();
export let className;
export let icon = null; export let icon = null;
export let options; export let options;
export let placeholder = 'Select...'; export let placeholder = 'Select...';
@ -109,7 +110,7 @@
<svelte:window on:click={onWindowClick} on:keydown={onKeyDown} /> <svelte:window on:click={onWindowClick} on:keydown={onKeyDown} />
<div class="select-none relative" bind:this={container}> <div class={`select-none relative ${className}`} bind:this={container}>
<button <button
class={`flex w-full relative items-center px-4 bg-background rounded-2xl h-14 focus:outline-none focus:border-primary border-2 border-transparent ease-in duration-100 ${classes}`} class={`flex w-full relative items-center px-4 bg-background rounded-2xl h-14 focus:outline-none focus:border-primary border-2 border-transparent ease-in duration-100 ${classes}`}
on:click={toggleOptions}> on:click={toggleOptions}>

View File

@ -0,0 +1,40 @@
<script>
import { server, loading } from '../stores/server';
import { readSave, updateSave, fromRemote } from '../stores/saveManager';
import { onMount } from 'svelte';
let unsubscribe = null;
let firstLoad = true;
$: if ($fromRemote) {
readLocalData();
}
onMount(() => {
readLocalData();
});
function readLocalData() {
loading.set(true);
firstLoad = true;
if (unsubscribe) unsubscribe();
console.log('setting read local');
const data = readSave('server');
if (data !== null) {
const currentServer = data;
server.set(currentServer);
}
unsubscribe = server.subscribe((val) => {
if (firstLoad) return;
console.log('server changed', val);
updateSave('server', val);
});
firstLoad = false;
loading.set(false);
}
</script>

View File

@ -10,6 +10,7 @@
import { showSidebar } from '../stores/sidebar'; import { showSidebar } from '../stores/sidebar';
import { checkLocalSave } from '../stores/saveManager'; import { checkLocalSave } from '../stores/saveManager';
import TodoData from '../components/TodoData.svelte'; import TodoData from '../components/TodoData.svelte';
import SettingData from '../components/SettingData.svelte';
export let segment; export let segment;
@ -33,6 +34,7 @@
<Modal> <Modal>
<DataSync> <DataSync>
<TodoData /> <TodoData />
<SettingData />
<main style="flex: 1 0 auto;"> <main style="flex: 1 0 auto;">
<slot /> <slot />
</main> </main>

View File

@ -107,10 +107,10 @@
intendedAscension >= currentAscension && intendedAscension >= currentAscension &&
currentLevel !== '' && currentLevel !== '' &&
currentLevel > 0 && currentLevel > 0 &&
currentLevel <= 80 && currentLevel <= 90 &&
intendedLevel !== '' && intendedLevel !== '' &&
intendedLevel > 0 && intendedLevel > 0 &&
intendedLevel <= 80; intendedLevel <= 90;
function updateIntendedAscension() { function updateIntendedAscension() {
intendedAscension = Math.max(currentAscension, intendedAscension); intendedAscension = Math.max(currentAscension, intendedAscension);

View File

@ -1,9 +1,21 @@
<script> <script>
import { mdiCheckCircleOutline, mdiGoogleDrive, mdiLoading } from '@mdi/js'; import { mdiCheckCircleOutline, mdiGoogleDrive, mdiLoading } from '@mdi/js';
import { onMount } from 'svelte';
import Button from '../components/Button.svelte'; import Button from '../components/Button.svelte';
import Icon from '../components/Icon.svelte'; import Icon from '../components/Icon.svelte';
import Select from '../components/Select.svelte';
import { driveSignedIn, driveLoading, synced, localModified, lastSyncTime } from '../stores/dataSync'; import { driveSignedIn, driveLoading, synced, localModified, lastSyncTime } from '../stores/dataSync';
import { server } from '../stores/server';
const servers = [
{ label: 'Asia/TW/HK/MO', value: 'Asia' },
{ label: 'America', value: 'America' },
{ label: 'Europe', value: 'Europe' },
];
let selectedServer = null;
function signIn() { function signIn() {
gapi.auth2.getAuthInstance().signIn(); gapi.auth2.getAuthInstance().signIn();
@ -13,6 +25,20 @@
gapi.auth2.getAuthInstance().signOut(); gapi.auth2.getAuthInstance().signOut();
} }
onMount(() => {
server.subscribe((val) => {
console.log('setting update');
selectedServer = servers.find((e) => e.value === val);
});
});
function updateServer() {
if (selectedServer === null) return;
server.set(selectedServer.value);
}
$: selectedServer, updateServer();
$: isSynced = $synced && !$localModified; $: isSynced = $synced && !$localModified;
</script> </script>
@ -21,7 +47,16 @@
</svelte:head> </svelte:head>
<div class="lg:ml-64 pt-20 px-8 lg:pt-8"> <div class="lg:ml-64 pt-20 px-8 lg:pt-8">
<p class="text-white mb-4">Data Version: <b>1.2</b></p> <div class="bg-item rounded-xl mb-4 p-4">
<p class="text-white">Data Version: <b>1.2</b></p>
</div>
<div class="bg-item rounded-xl mb-4 p-4">
<div class="flex flex-col md:flex-row md:items-center">
<p class="text-white mr-4">Select your server:</p>
<Select className="w-64" bind:selected={selectedServer} options={servers} placeholder="Select your server" />
</div>
</div>
<div class="bg-item rounded-xl mb-4 p-4">
<p class="text-white mb-2"> <p class="text-white mb-2">
Paimon.moe use Application Data Directory on your Google Drive to save and sync your wish counter and todo list. Paimon.moe use Application Data Directory on your Google Drive to save and sync your wish counter and todo list.
</p> </p>
@ -54,3 +89,4 @@
{/if} {/if}
{/if} {/if}
</div> </div>
</div>

View File

@ -8,6 +8,7 @@
import Icon from '../components/Icon.svelte'; import Icon from '../components/Icon.svelte';
import Button from '../components/Button.svelte'; import Button from '../components/Button.svelte';
import TodoDeleteModal from '../components/TodoDeleteModal.svelte'; import TodoDeleteModal from '../components/TodoDeleteModal.svelte';
import { getCurrentDay } from '../stores/server';
const { open: openModal, close: closeModal } = getContext('simple-modal'); const { open: openModal, close: closeModal } = getContext('simple-modal');
@ -15,7 +16,7 @@
let numberFormat = Intl.NumberFormat(); let numberFormat = Intl.NumberFormat();
let adding = false; let adding = false;
let todayOnly = false; let todayOnly = false;
let today = dayjs().format('dddd').toLowerCase(); let today = getCurrentDay();
async function reorder(index, pos) { async function reorder(index, pos) {
if ((index === 0 && pos === -1) || (index === $todos.length - 1 && pos === 1)) return; if ((index === 0 && pos === -1) || (index === $todos.length - 1 && pos === 1)) return;
@ -58,6 +59,7 @@
} }
function toggleTodayOnly() { function toggleTodayOnly() {
today = getCurrentDay();
todayOnly = !todayOnly; todayOnly = !todayOnly;
} }
@ -108,7 +110,10 @@
<Icon path={mdiLoading} color="white" spin /> <Icon path={mdiLoading} color="white" spin />
{:else if $todos.length > 0} {:else if $todos.length > 0}
<div> <div>
<Button className="float-right" size="md" on:click={toggleTodayOnly}>Show {todayOnly ? 'All Day' : 'Today Only'}</Button> <Button className="float-right" size="md" on:click={toggleTodayOnly}>
Show
{todayOnly ? 'All Day' : 'Today Only'}
</Button>
<p class="font-bold text-xl mb-4">Summary</p> <p class="font-bold text-xl mb-4">Summary</p>
</div> </div>
{:else} {:else}

33
src/stores/server.js Normal file
View File

@ -0,0 +1,33 @@
import { writable, get } from 'svelte/store';
import dayjs from 'dayjs';
import utc from 'dayjs/plugin/utc';
import timezone from 'dayjs/plugin/timezone';
dayjs.extend(utc);
dayjs.extend(timezone);
export const server = writable('Asia');
export const loading = writable(true);
const timeOffset = {
Asia: 8,
America: -5,
Europe: 1,
};
const weekdays = ['sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'];
export const getCurrentDay = () => {
const time = dayjs().utcOffset(timeOffset[get(server)]);
let day = time.day();
if (time.hour() > 0 && time.hour() < 4) {
day -= 1;
}
if (day === -1) {
day = 6;
}
console.log(weekdays[day], weekdays[time.day()], time.format());
return weekdays[day];
};