Skip to content

Commit

Permalink
Merge pull request #246 from appwrite/feat/in-progress-execution-timer
Browse files Browse the repository at this point in the history
Feat: function execution timer
  • Loading branch information
TorstenDittmann authored Feb 10, 2023
2 parents 279f195 + 5eb6f85 commit ccf53ea
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 14 deletions.
40 changes: 40 additions & 0 deletions src/lib/actions/timer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { calculateTime } from '$lib/helpers/timeConversion';
import type { Action } from 'svelte/action';

type Props = {
start?: string;
enabled?: boolean;
};

const defaultProps: Props = {
enabled: true
};

export const timer: Action<HTMLElement, Props> = (node, props) => {
let startDate: Date;
let frame: number;

function init(props: Props) {
const { start, enabled } = { ...defaultProps, ...props };
startDate = start ? new Date(start) : new Date();
frame = enabled ? window.requestAnimationFrame(step) : null;
}

function step() {
const diffInSeconds = Math.floor((new Date().getTime() - startDate.getTime()) / 1000);
node.textContent = calculateTime(diffInSeconds);
frame = window.requestAnimationFrame(step);
}

init(props);

return {
update(props) {
window.cancelAnimationFrame(frame);
init(props);
},
destroy() {
window.cancelAnimationFrame(frame);
}
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import { page } from '$app/stores';
import Output from '$lib/components/output.svelte';
import { calculateTime } from '$lib/helpers/timeConversion';
import { timer } from '$lib/actions/timer';
export let data: PageData;
Expand Down Expand Up @@ -188,7 +189,9 @@
</TableCell>

<TableCellText title="Build Time">
{#if deployment.status === 'ready'}
{#if ['processing', 'building'].includes(deployment.status)}
<span use:timer={{ start: deployment.$createdAt }} />
{:else}
{calculateTime(deployment.buildTime)}
{/if}
</TableCellText>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
<script lang="ts">
import { Container } from '$lib/layout';
import { invalidate } from '$app/navigation';
import { page } from '$app/stores';
import { Copy, EmptySearch, Heading, Pagination, Status } from '$lib/components';
import { Dependencies, PAGE_LIMIT } from '$lib/constants';
import { Pill } from '$lib/elements';
import { Copy, Status, Heading, Pagination, EmptySearch } from '$lib/components';
import { Button } from '$lib/elements/forms';
import {
TableHeader,
TableBody,
TableCellHead,
TableCell,
TableCellHead,
TableCellText,
TableHeader,
TableRow,
TableScroll
} from '$lib/elements/table';
import { toLocaleDateTime } from '$lib/helpers/date';
import { calculateTime } from '$lib/helpers/timeConversion';
import { Container } from '$lib/layout';
import { log } from '$lib/stores/logs';
import { func } from '../../store';
import type { PageData } from './$types';
import { Dependencies, PAGE_LIMIT } from '$lib/constants';
import { page } from '$app/stores';
import { onDestroy, onMount } from 'svelte';
import { sdkForConsole } from '$lib/stores/sdk';
import { invalidate } from '$app/navigation';
import { Button } from '$lib/elements/forms';
import { onDestroy, onMount } from 'svelte';
import CreateDeployment from '../../create.svelte';
import { func } from '../../store';
import type { PageData } from './$types';
export let data: PageData;
let showCreate = false;
Expand Down Expand Up @@ -83,7 +83,8 @@
</Pill>
</TableCellText>
<TableCellText title="Duration">
{calculateTime(execution.duration)}</TableCellText>
{calculateTime(execution.duration)}
</TableCellText>
<TableCell>
<Button
secondary
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"extends": "./.svelte-kit/tsconfig.json",
"compilerOptions": {
"lib": ["webworker", "ES2016", "DOM"],
"lib": ["webworker", "DOM", "ESNext"],
"module": "ESNext",
"moduleResolution": "Node",
"importsNotUsedAsValues": "error",
Expand Down

1 comment on commit ccf53ea

@vercel
Copy link

@vercel vercel bot commented on ccf53ea Feb 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.