Skip to content

Commit a1dd103

Browse files
Merge pull request #2656 from appwrite/fix-copy-markdown
2 parents cde5a81 + 4959621 commit a1dd103

File tree

2 files changed

+76
-75
lines changed

2 files changed

+76
-75
lines changed

Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ RUN fc-cache -f -v
7878

7979
COPY --from=build /app/build/ build
8080
COPY --from=build /app/server/ server
81+
COPY --from=build /app/src/routes/ src/routes
8182
COPY --from=prod-deps /app/node_modules/ node_modules
8283

8384
CMD ["node", "server/main.js"]

src/lib/components/blog/copy-as-markdown.svelte

Lines changed: 75 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,40 @@
11
<script lang="ts">
2-
import { page } from '$app/stores';
2+
import { page } from '$app/state';
33
import { getPageMarkdown } from '$lib/remote/markdown.remote';
44
import { copyToClipboard } from '$lib/utils/copy';
5-
import { cn } from '$lib/utils/cn';
6-
import { writable } from 'svelte/store';
75
import { Button, Icon, SplitButton } from '$lib/components/ui';
86
import { Tooltip } from '$lib/components';
97
import { createDropdownMenu, melt } from '@melt-ui/svelte';
108
11-
interface CopyAsMarkdownProps {
9+
interface Props {
1210
class?: string;
1311
}
1412
15-
const { class: classNames }: CopyAsMarkdownProps = $props();
13+
const { class: classNames }: Props = $props();
1614
17-
const markdown = getPageMarkdown($page.route.id);
18-
const copied = writable(false);
15+
let copied = $state(false);
16+
let copying = $state(false);
1917
let timeout: ReturnType<typeof setTimeout> | undefined = undefined;
2018
21-
const copy = () => {
19+
async function copy() {
20+
copying = true;
2221
if (timeout) clearTimeout(timeout);
23-
copyToClipboard(markdown.current ?? '');
24-
copied.set(true);
25-
timeout = setTimeout(() => copied.set(false), 2000);
26-
};
22+
const markdown = await getPageMarkdown(page.route.id);
23+
copyToClipboard(markdown ?? '');
24+
timeout = setTimeout(() => (copied = false), 2000);
25+
copied = true;
26+
copying = false;
27+
}
2728
28-
const resetCopied = () => {
29+
function resetCopied() {
2930
if (timeout) clearTimeout(timeout);
30-
copied.set(false);
31-
};
31+
copied = false;
32+
}
3233
33-
const copyAndClose = () => {
34+
function copyAndClose() {
3435
copy();
3536
open.set(false);
36-
};
37+
}
3738
3839
const {
3940
elements: { trigger, menu },
@@ -50,66 +51,65 @@
5051
};
5152
</script>
5253

53-
{#if !markdown.loading && markdown.current}
54-
<div class={cn('copy-ctl inline-flex items-center', classNames)}>
55-
<SplitButton>
56-
<Tooltip disabled={!$copied}>
57-
<Button
58-
variant="secondary"
59-
onclick={copy}
60-
onmouseleave={resetCopied}
61-
aria-label="Copy page as Markdown"
62-
splitPosition="first"
63-
class="text-sm"
64-
>
65-
<Icon name="copy" aria-hidden="true" class="text-sm" />
66-
<span>Copy page</span>
67-
</Button>
68-
{#snippet tooltip()}
69-
Copied
70-
{/snippet}
71-
</Tooltip>
72-
73-
<button
74-
class="web-button is-secondary is-split is-split-last text-sm"
75-
use:melt={$trigger}
76-
aria-label="Open options"
54+
<div class={['copy-ctl inline-flex items-center', classNames]}>
55+
<SplitButton>
56+
<Tooltip disabled={!copied}>
57+
<Button
58+
variant="secondary"
59+
disabled={copying}
60+
onclick={copy}
61+
onmouseleave={resetCopied}
62+
aria-label="Copy page as Markdown"
63+
splitPosition="first"
64+
class="text-sm"
7765
>
78-
{#if $open}
79-
<span class="web-icon-chevron-up" aria-hidden="true"></span>
80-
{:else}
81-
<span class="web-icon-chevron-down" aria-hidden="true"></span>
82-
{/if}
83-
</button>
84-
</SplitButton>
66+
<Icon name="copy" aria-hidden="true" class="text-sm" />
67+
<span>Copy page</span>
68+
</Button>
69+
{#snippet tooltip()}
70+
Copied
71+
{/snippet}
72+
</Tooltip>
73+
74+
<button
75+
class="web-button is-secondary is-split is-split-last text-sm"
76+
use:melt={$trigger}
77+
aria-label="Open options"
78+
>
79+
{#if $open}
80+
<span class="web-icon-chevron-up" aria-hidden="true"></span>
81+
{:else}
82+
<span class="web-icon-chevron-down" aria-hidden="true"></span>
83+
{/if}
84+
</button>
85+
</SplitButton>
8586

86-
{#if $open}
87-
<div class="menu-wrapper web-select-menu is-normal menu z-1" use:melt={$menu}>
88-
<ul class="text-sub-body">
89-
<li>
90-
<button type="button" class="menu-btn text-sm" onclick={copyAndClose}>
91-
<Icon name="copy" aria-hidden="true" class="text-sm" />
92-
<span>Copy as Markdown</span>
93-
</button>
94-
</li>
95-
<li>
96-
<button
97-
type="button"
98-
class="menu-btn text-sm"
99-
onclick={() => {
100-
viewInNewTab();
101-
open.set(false);
102-
}}
103-
>
104-
<Icon name="external-icon" aria-hidden="true" class="text-sm" />
105-
<span>View as Markdown</span>
106-
</button>
107-
</li>
108-
</ul>
109-
</div>
110-
{/if}
111-
</div>
112-
{/if}
87+
{#if $open}
88+
<div class="menu-wrapper web-select-menu is-normal menu z-1" use:melt={$menu}>
89+
<ul class="text-sub-body">
90+
<li>
91+
<button type="button" class="menu-btn text-sm" onclick={copyAndClose}>
92+
<Icon name="copy" aria-hidden="true" class="text-sm" />
93+
<span>Copy as Markdown</span>
94+
</button>
95+
</li>
96+
<li>
97+
<button
98+
type="button"
99+
class="menu-btn text-sm"
100+
onclick={() => {
101+
viewInNewTab();
102+
open.set(false);
103+
}}
104+
>
105+
<Icon name="external-icon" aria-hidden="true" class="text-sm" />
106+
<span>View as Markdown</span>
107+
</button>
108+
</li>
109+
</ul>
110+
</div>
111+
{/if}
112+
</div>
113113

114114
<style>
115115
.copy-ctl {

0 commit comments

Comments
 (0)