Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

draft: route transition and global cover component #9

Merged
merged 29 commits into from
Jun 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
bbed5a5
draft: route transition and global cover component
TorstenDittmann May 18, 2022
d92e6ec
Merge branch 'main' of https://github.com/appwrite/appwrite-console-p…
TorstenDittmann May 18, 2022
8698f06
fix: user loading
TorstenDittmann May 18, 2022
25520c0
fix: store assignments
TorstenDittmann May 18, 2022
d219f21
chore: implemented new tabs into most layouts
ArmanNik May 18, 2022
98395e2
chore: modified last layout
ArmanNik May 18, 2022
0af6da8
fix: teams store type error
ArmanNik May 18, 2022
84d0f85
Merge branch 'main' of https://github.com/appwrite/appwrite-console-p…
TorstenDittmann May 18, 2022
8a6af22
fix: collection route
TorstenDittmann May 18, 2022
07d6864
Merge branch 'main' of https://github.com/appwrite/appwrite-console-p…
TorstenDittmann May 18, 2022
e69bd66
fix: double cover on home page (WIP)
ArmanNik May 19, 2022
8bb4921
feat: added scroll function
ArmanNik May 19, 2022
e837efa
fix: hide & show tabs automatically
TorstenDittmann May 20, 2022
29c9f7c
fix: throttle function
TorstenDittmann May 20, 2022
22d2cef
styles: fix some whitespace
TorstenDittmann May 20, 2022
6eb4658
Merge branch 'demo-various' of https://github.com/appwrite/appwrite-c…
TorstenDittmann May 20, 2022
214a934
Merge branch 'main' of https://github.com/appwrite/appwrite-console-p…
TorstenDittmann May 20, 2022
d10cd81
feat: cached users list
TorstenDittmann May 20, 2022
13720e4
chore: update ui library
TorstenDittmann May 20, 2022
91ba8df
chore: update ui library
TorstenDittmann May 20, 2022
3f144db
fix table for users
TorstenDittmann May 20, 2022
1398fad
fix: prevent unnecessary api call
TorstenDittmann May 20, 2022
be5470b
fix: teams table
TorstenDittmann May 20, 2022
afc2378
fix tables
TorstenDittmann May 20, 2022
509aff3
Merge branch 'main' of https://github.com/appwrite/appwrite-console-p…
TorstenDittmann May 20, 2022
ce25bc8
fix: refactored pagination function
ArmanNik May 30, 2022
41fd2a8
fix: now component visible when there aren't pages
ArmanNik May 30, 2022
d9261c4
Merge pull request #14 from appwrite/pagination
TorstenDittmann Jun 7, 2022
06f333b
tests: fix pagination
TorstenDittmann Jun 7, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions package-lock.json

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

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"e2e": "playwright test tests/e2e"
},
"dependencies": {
"@aw-labs/ui": "*"
"@aw-labs/ui": "^0.0.0-4",
"@aw-labs/icons": "^0.0.0-4"
},
"devDependencies": {
"@playwright/test": "^1.22.1",
Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/card.svelte
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<article class="card">
<article class="card common-section">
<slot />
</article>
17 changes: 8 additions & 9 deletions src/lib/components/empty.svelte
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
<script>
import { Card } from '.';
export let dashed = false;
export let centered = false;
</script>

<Card>
<b>
<slot name="header" />
</b>
<p>
<slot />
</p>
</Card>
<article
class="card common-section u-flex u-flex-vertical"
class:is-border-dashed={dashed}
class:u-cross-center={centered}>
<slot />
</article>
4 changes: 2 additions & 2 deletions src/lib/components/modal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@
aria-label="Close Modal"
title="Close Modal"
on:click={closeModal}>
<span class="icon-cancel" aria-hidden="true" />
<span class="icon-x" aria-hidden="true" />
</button>
</header>
<div class="modal-content">
<slot />
</div>
<div class="modal-footer">
<div class="u-flex u-gap-10">
<div class="u-flex u-main-space-end u-gap-12">
<slot name="footer" />
</div>
</div>
Expand Down
57 changes: 36 additions & 21 deletions src/lib/components/pagination.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
offset = limit * (page - 1);
currentPage = page;
dispatch('change');
pages = pagination(currentPage, totalPages);
}
}

Expand All @@ -21,36 +22,32 @@
currentPage += 1;
offset = limit * (currentPage - 1);
dispatch('change');
pages = pagination(currentPage, totalPages);
} else if (direction === 'prev' && currentPage > 1) {
currentPage -= 1;
offset = limit * (currentPage - 1);
dispatch('change');
pages = pagination(currentPage, totalPages);
}
}

let pages = pagination(currentPage, totalPages);

function pagination(current: number, total: number) {
let delta = 2,
left = current - delta,
right = current + delta + 1,
range = [],
rangeWithDots = [];

for (let i = 1; i <= total; i++) {
if (i == 1 || i == total || (i >= left && i < right)) {
range.push(i);
}
}

rangeWithDots = range.reduce((prev, current, index) => {
if (current - prev[index - 1] > delta) {
prev.push('...');
}
prev.push(current);
return prev;
}, []);
return rangeWithDots;
function pagination(page: number, total: number) {
const pagesShown = 5;
const start = Math.max(
1,
Math.min(page - Math.floor((pagesShown - 3) / 2), total - pagesShown + 2)
);
const end = Math.min(
total,
Math.max(page + Math.floor((pagesShown - 2) / 2), pagesShown - 1)
);
return [
...(start > 2 ? [1, '...'] : start > 1 ? [1] : []),
...Array.from({ length: end + 1 - start }, (_, i) => i + start),
...(end < total - 1 ? ['...', total] : end < total ? [total] : [])
];
}
</script>

Expand Down Expand Up @@ -93,4 +90,22 @@
<span class="icon-cheveron-right" aria-hidden="true" />
</button>
</nav>
{:else}
<nav class="pagination">
<button class="button is-text is-disabled" aria-label="prev page">
<span class="icon-cheveron-left" aria-hidden="true" />
<span class="text">Prev</span>
</button>
<ol class="pagination-list is-only-desktop">
<li class="pagination-item">
<button class="button is-disabled" aria-label="page">
<span class="text">1</span>
</button>
</li>
</ol>
<button class="button is-text is-disabled" aria-label="next page">
<span class="text">Next</span>
<span class="icon-cheveron-right" aria-hidden="true" />
</button>
</nav>
{/if}
3 changes: 3 additions & 0 deletions src/lib/elements/forms/button.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
export let outline = false;
export let danger = false;
export let disabled = false;
export let round = false;
export let href: string = null;
</script>

Expand All @@ -12,6 +13,7 @@
{disabled}
{href}
class="button"
class:is-only-icon={round}
class:is-secondary={secondary}
class:is-outline={outline}
class:is-danger={danger}>
Expand All @@ -22,6 +24,7 @@
on:click
{disabled}
class="button"
class:is-only-icon={round}
class:is-secondary={secondary}
class:is-outline={outline}
class:is-danger={danger}
Expand Down
6 changes: 6 additions & 0 deletions src/lib/elements/table/cellHead.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,9 @@
<slot />
</span>
</th>

<style>
th {
text-transform: uppercase;
}
</style>
13 changes: 13 additions & 0 deletions src/lib/helpers/date.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,16 @@ export const toLocaleDate = (timestamp: number) => {

return date.toLocaleDateString('en', options);
};

export const toLocaleDateTime = (timestamp: number) => {
const date = new Date(timestamp * 1000);
const options: Intl.DateTimeFormatOptions = {
year: 'numeric',
month: 'long',
day: 'numeric',
hour: 'numeric',
minute: 'numeric'
};

return date.toLocaleDateString('en', options);
};
2 changes: 1 addition & 1 deletion src/lib/layout/cover.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<div class="top-cover" class:is-adjust-content-to-cover={adjustContentToCover}>
<div class="container">
<h1 class="heading-level-1">
<h1 class="heading-level-2">
<slot name="title" />
</h1>
<slot />
Expand Down
93 changes: 91 additions & 2 deletions src/lib/layout/shell.svelte
Original file line number Diff line number Diff line change
@@ -1,13 +1,59 @@
<script lang="ts">
import { navigating } from '$app/stores';
import { navigating, page } from '$app/stores';
import { tabs, title } from '$lib/stores/layout';
import { fade } from 'svelte/transition';
import { Cover } from '.';

export let isOpen = false;

$: base = `/console/${$page.params.project}`;

let tabsList: HTMLUListElement;
let showLeft = false;
let showRight = false;

navigating.subscribe(() => {
if (isOpen) isOpen = false;
});

const slide = (direction: 'left' | 'right') => {
let scrollCompleted = 0;
let slideVar = setInterval(() => {
if (direction == 'left') {
tabsList.scrollLeft -= 10;
} else {
tabsList.scrollLeft += 10;
}
scrollCompleted += 10;
if (scrollCompleted >= 100) {
clearInterval(slideVar);
}
}, 10);
};

const onScroll = () => {
const { offsetWidth, scrollLeft, scrollWidth } = tabsList;
showLeft = scrollLeft > 10;
showRight = scrollLeft < scrollWidth - offsetWidth - 10;
};

//TODO: implement this directly into onScroll
const throttle = (fn: () => void, delay: number) => {
let timeout = false;
return () => {
if (!timeout) {
timeout = true;
fn.apply(this);
setTimeout(() => {
timeout = false;
}, delay);
}
};
};
</script>

<svelte:window on:resize={throttle(onScroll, 25)} />

<main class="grid-with-side" class:is-open={isOpen}>
<header class="main-header">
<button
Expand All @@ -22,7 +68,50 @@
<slot name="side" />
</nav>
<section class="main-content">
<slot />
<Cover>
<svelte:fragment slot="title">{$title}</svelte:fragment>
{#if $tabs.length}
<div class="tabs">
{#if showLeft}
<button
class="tabs-button-scroll is-start"
aria-label="Show items in start side"
on:click={() => slide('left')}>
<span class="icon-cheveron-left" aria-hidden="true" />
</button>
{/if}
{#if showRight}
<button
class="tabs-button-scroll is-end"
aria-label="Show items in end side"
on:click={() => slide('right')}>
<span class="icon-cheveron-right" aria-hidden="true" />
</button>
{/if}
<ul
class="tabs-list scroll-shadow-horizontal"
bind:this={tabsList}
on:scroll={throttle(onScroll, 25)}>
{#each $tabs as tab}
<li class="tabs-item">
<a
class="tabs-button"
href={`${base}/${tab.href}`}
class:is-selected={$page.url.pathname ===
`${base}/${tab.href}`}>
<span class="text">{tab.title}</span>
</a>
</li>
{/each}
</ul>
</div>
{/if}
</Cover>
{#key $page.routeId}
<div in:fade>
<slot />
</div>
{/key}
</section>
</main>

Expand Down
9 changes: 5 additions & 4 deletions src/lib/stores/layout.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { writable } from 'svelte/store';

export type Breadcrumb = {
name: string;
link?: string;
export type Tab = {
href: string;
title: string;
};

export const breadcrumbs = writable<Breadcrumb[]>([]);
export const title = writable<string>('');
export const tabs = writable<Tab[]>([]);
Loading