feat: 🚀 😃 convert repo into a monorepo 🚀 😃 (#51)
* Merge main into turbo-monrepo * feat: rename apps * feat: remove supbase videos and serve all from project * feat: move supabase to root * feat: update README * docs: update link
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
export const SNACKBAR_SEVERITY = {
|
||||
ERROR: 'ERROR',
|
||||
WARNING: 'WARNING',
|
||||
DEFAULT: 'DEFAULT',
|
||||
INFO: 'INFO',
|
||||
SUCCESS: 'SUCCESS'
|
||||
};
|
||||
|
||||
export const SNACKBAR_SEVERITY_COLOR = {
|
||||
ERROR: 'bg-red-600',
|
||||
WARNING: 'bg-yellow-600',
|
||||
INFO: 'bg-primary-600',
|
||||
DEFAULT: 'bg-gray-600',
|
||||
SUCCESS: 'bg-green-600'
|
||||
};
|
||||
@@ -0,0 +1,73 @@
|
||||
<script lang="ts">
|
||||
import { fly } from 'svelte/transition';
|
||||
import { InlineNotification } from 'carbon-components-svelte';
|
||||
import { capitalizeFirstLetter } from '$lib/utils/functions/string';
|
||||
|
||||
import { SNACKBAR_SEVERITY } from './constants';
|
||||
import { snackbarStore, snackbarStoreInitialState } from './store';
|
||||
|
||||
let timeoutId: NodeJS.Timeout | undefined;
|
||||
let kind: 'error' | 'info' | 'info-square' | 'success' | 'warning' | 'warning-alt' = 'info';
|
||||
|
||||
function handleClose() {
|
||||
if (typeof $snackbarStore.handleClose === 'function') {
|
||||
$snackbarStore.handleClose();
|
||||
}
|
||||
|
||||
snackbarStore.update((_s) => ({
|
||||
..._s,
|
||||
...snackbarStoreInitialState
|
||||
}));
|
||||
clearTimeout(timeoutId);
|
||||
timeoutId = undefined;
|
||||
}
|
||||
|
||||
// When open is true trigger autoHideDuration
|
||||
function handleOpen(open: boolean) {
|
||||
if (!open) {
|
||||
return;
|
||||
}
|
||||
|
||||
const { autoHideDuration } = $snackbarStore;
|
||||
|
||||
if (typeof autoHideDuration === 'number' && !timeoutId) {
|
||||
clearTimeout(timeoutId);
|
||||
timeoutId = setTimeout(handleClose, autoHideDuration);
|
||||
}
|
||||
}
|
||||
|
||||
$: handleOpen($snackbarStore.open);
|
||||
$: kind =
|
||||
$snackbarStore.severity === SNACKBAR_SEVERITY.SUCCESS
|
||||
? 'success'
|
||||
: $snackbarStore.severity === SNACKBAR_SEVERITY.ERROR
|
||||
? 'error'
|
||||
: 'info';
|
||||
</script>
|
||||
|
||||
{#if $snackbarStore.open}
|
||||
{#key $snackbarStore.message}
|
||||
<div transition:fly={{ x: 200, duration: 500 }} class="root absolute">
|
||||
<InlineNotification
|
||||
{kind}
|
||||
title={capitalizeFirstLetter(kind || '')}
|
||||
subtitle={$snackbarStore.message}
|
||||
on:close={(e) => {
|
||||
e.preventDefault();
|
||||
handleClose();
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
{/key}
|
||||
{/if}
|
||||
|
||||
<style>
|
||||
.root {
|
||||
right: 5%;
|
||||
left: auto;
|
||||
top: 24px;
|
||||
transform: translateX(-5%);
|
||||
min-width: 288px;
|
||||
z-index: 51;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,42 @@
|
||||
import { writable } from 'svelte/store';
|
||||
import { SNACKBAR_SEVERITY } from './constants';
|
||||
|
||||
export const snackbarStoreInitialState = {
|
||||
open: false,
|
||||
message: '',
|
||||
severity: SNACKBAR_SEVERITY.DEFAULT,
|
||||
handleClose: () => {},
|
||||
autoHideDuration: 6000
|
||||
};
|
||||
|
||||
export const snackbarStore = writable({ ...snackbarStoreInitialState });
|
||||
|
||||
export const snackbar = {
|
||||
success(message = 'Success') {
|
||||
snackbarStore.update((store) => {
|
||||
store.open = true;
|
||||
store.message = message;
|
||||
store.severity = SNACKBAR_SEVERITY.SUCCESS;
|
||||
|
||||
return store;
|
||||
});
|
||||
},
|
||||
error(message = 'Something went wrong - Please try later') {
|
||||
snackbarStore.update((store) => {
|
||||
store.open = true;
|
||||
store.message = message;
|
||||
store.severity = SNACKBAR_SEVERITY.ERROR;
|
||||
|
||||
return store;
|
||||
});
|
||||
},
|
||||
info(message = 'Update') {
|
||||
snackbarStore.update((store) => {
|
||||
store.open = true;
|
||||
store.message = message;
|
||||
store.severity = SNACKBAR_SEVERITY.INFO;
|
||||
|
||||
return store;
|
||||
});
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user