mirror of
https://github.com/appwrite/console.git
synced 2026-11-18 20:47:21 +00:00
feat: feedback store
This commit is contained in:
1 parent
0963a3bb1c
commit
f98aff66d6
4 files changed
+111
-18
No files matched your search
@@ -65,14 +65,16 @@
|
||||
<div class="drop-arrow" class:u-hide={!show} bind:this={arrow} />
|
||||
{#if show}
|
||||
<div class="drop is-no-arrow" style="position: revert">
|
||||
<section
|
||||
class:u-overflow-y-auto={scrollable}
|
||||
class:u-max-height-200={scrollable}
|
||||
class="drop-section ">
|
||||
<ul class="drop-list">
|
||||
<slot name="list" />
|
||||
</ul>
|
||||
</section>
|
||||
{#if $$slots.list}
|
||||
<section
|
||||
class:u-overflow-y-auto={scrollable}
|
||||
class:u-max-height-200={scrollable}
|
||||
class="drop-section ">
|
||||
<ul class="drop-list">
|
||||
<slot name="list" />
|
||||
</ul>
|
||||
</section>
|
||||
{/if}
|
||||
<slot name="other" />
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
@@ -1,7 +1,13 @@
|
||||
<script lang="ts">
|
||||
import { base } from '$app/paths';
|
||||
import { AvatarInitials, DropList, DropListItem, DropListLink } from '$lib/components';
|
||||
import { app } from '$lib/stores/app';
|
||||
import {
|
||||
AvatarInitials,
|
||||
DropList,
|
||||
DropListItem,
|
||||
DropListLink,
|
||||
FeedbackGeneral
|
||||
} from '$lib/components';
|
||||
import { app, feedback } from '$lib/stores/app';
|
||||
import { user } from '$lib/stores/user';
|
||||
import { organizationList, organization, newOrgModal } from '$lib/stores/organization';
|
||||
import AppwriteLogo from '$lib/images/appwrite-gray-light.svg';
|
||||
@@ -10,21 +16,29 @@
|
||||
import SystemMode from '$lib/images/mode/system-mode.svg';
|
||||
import { FeedbackNPS } from '$lib/components';
|
||||
|
||||
let showFeedback = true;
|
||||
let showFeedback = false;
|
||||
import { slide } from 'svelte/transition';
|
||||
import { page } from '$app/stores';
|
||||
|
||||
let showDropdown = false;
|
||||
let droplistElement: HTMLDivElement;
|
||||
|
||||
const onBlur = (event: MouseEvent) => {
|
||||
function toggleFeedback() {
|
||||
showFeedback = !showFeedback;
|
||||
if ($feedback.notification) {
|
||||
feedback.toggleNotification();
|
||||
feedback.addVisualization();
|
||||
}
|
||||
}
|
||||
|
||||
function onBlur(event: MouseEvent) {
|
||||
if (
|
||||
showDropdown &&
|
||||
!(event.target === droplistElement || droplistElement.contains(event.target as Node))
|
||||
) {
|
||||
showDropdown = false;
|
||||
}
|
||||
};
|
||||
}
|
||||
</script>
|
||||
|
||||
<svelte:window on:click={onBlur} />
|
||||
@@ -41,15 +55,27 @@
|
||||
|
||||
<div class="main-header-end">
|
||||
<nav class="u-flex is-only-desktop">
|
||||
{#if $feedback.notification}
|
||||
<div class="u-flex u-cross-center">
|
||||
<div class="pulse-notification" />
|
||||
</div>
|
||||
{/if}
|
||||
<DropList bind:show={showFeedback} scrollable={true}>
|
||||
<button class="button is-small is-text" on:click={() => (showFeedback = !showFeedback)}>
|
||||
<button class="button is-small is-text" on:click={toggleFeedback}>
|
||||
<span class="text">Feedback</span>
|
||||
</button>
|
||||
<svelte:fragment slot="other">
|
||||
<FeedbackNPS bind:show={showFeedback}>
|
||||
<svelte:fragment slot="title">How Can We Improve</svelte:fragment>
|
||||
Your feedback is important to us. Please be honest and tell us what you think.
|
||||
</FeedbackNPS>
|
||||
{#if $feedback.type === 'nps'}
|
||||
<FeedbackNPS bind:show={showFeedback}>
|
||||
<svelte:fragment slot="title">How Can We Improve</svelte:fragment>
|
||||
Your feedback is important to us. Please be honest and tell us what you think.
|
||||
</FeedbackNPS>
|
||||
{:else if $feedback.type === 'general'}
|
||||
<FeedbackGeneral bind:show={showFeedback}>
|
||||
<svelte:fragment slot="title">How Can We Improve</svelte:fragment>
|
||||
Your feedback is important to us. Please be honest and tell us what you think.
|
||||
</FeedbackGeneral>
|
||||
{/if}
|
||||
</svelte:fragment>
|
||||
</DropList>
|
||||
<a
|
||||
|
||||
@@ -5,11 +5,57 @@ export type AppStore = {
|
||||
theme: 'light' | 'dark' | 'auto';
|
||||
themeInUse: 'light' | 'dark';
|
||||
};
|
||||
|
||||
export type Feedback = {
|
||||
elapsed: number;
|
||||
visualized: number;
|
||||
notification: boolean;
|
||||
type: 'nps' | 'general';
|
||||
};
|
||||
|
||||
export const app = writable<AppStore>({
|
||||
theme: 'auto',
|
||||
themeInUse: 'light'
|
||||
});
|
||||
|
||||
function createFeedbackStore() {
|
||||
const { subscribe, update } = writable<Feedback>({
|
||||
elapsed: parseInt(localStorage.getItem('feedbackElapsed') ?? '0'),
|
||||
visualized: parseInt(localStorage.getItem('feedbackVisualized') ?? '0'),
|
||||
notification: false,
|
||||
type: 'nps'
|
||||
});
|
||||
return {
|
||||
subscribe,
|
||||
update,
|
||||
toggleNotification: () =>
|
||||
update((feedback) => {
|
||||
feedback.notification = !feedback.notification;
|
||||
return feedback;
|
||||
}),
|
||||
switchType: () =>
|
||||
update((feedback) => {
|
||||
feedback.type = feedback.type === 'nps' ? 'general' : 'nps';
|
||||
return feedback;
|
||||
}),
|
||||
addVisualization: () =>
|
||||
update((feedback) => {
|
||||
localStorage.setItem('feedbackVisualized', (feedback.visualized + 1).toString());
|
||||
feedback.visualized = feedback.visualized + 1;
|
||||
return feedback;
|
||||
}),
|
||||
|
||||
setElapsed: (time: number) => {
|
||||
update((feedback) => {
|
||||
localStorage.setItem('feedbackElapsed', time.toString());
|
||||
feedback.elapsed = time;
|
||||
return feedback;
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
export const feedback = createFeedbackStore();
|
||||
|
||||
if (browser) {
|
||||
app.update((n) => ({
|
||||
...n,
|
||||
|
||||
@@ -11,11 +11,30 @@
|
||||
import { log } from '$lib/stores/logs';
|
||||
import { onMount } from 'svelte';
|
||||
import { loading } from '../store';
|
||||
import { feedback } from '$lib/stores/app';
|
||||
|
||||
onMount(() => {
|
||||
loading.set(false);
|
||||
const interval = 60000;
|
||||
checkForFeedback(interval);
|
||||
|
||||
setInterval(() => {
|
||||
checkForFeedback(interval);
|
||||
}, interval);
|
||||
});
|
||||
|
||||
function checkForFeedback(interval: number) {
|
||||
feedback.setElapsed($feedback.elapsed + interval);
|
||||
const minutes = $feedback.elapsed / 60000;
|
||||
if (minutes < 60) {
|
||||
feedback.toggleNotification();
|
||||
} else if (minutes > 60 && $feedback.visualized === 0) {
|
||||
feedback.toggleNotification();
|
||||
} else if ((minutes - 60) % 60 >= $feedback.visualized) {
|
||||
feedback.toggleNotification();
|
||||
}
|
||||
}
|
||||
|
||||
beforeNavigate(() => {
|
||||
$log.show = false;
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user