Skip to content

Commit b515868

Browse files
committed
doc: add storage docs
1 parent b0ddfde commit b515868

File tree

7 files changed

+162
-6
lines changed

7 files changed

+162
-6
lines changed

Diff for: docs/src/components/SideNav.astro

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
<li><a href="/firestore/doc-component">&ltDoc&gt</a></li>
1919
<li><a href="/firestore/collection-component">&ltCollection&gt</a></li>
2020
<li class="heading">storage</li>
21-
<li><a href="/guide/todo">uploadTaskStore</a></li>
22-
<li><a href="/guide/todo">&ltFileUploader&gt</a></li>
23-
<li><a href="/guide/todo">&ltDownloadURL&gt</a></li>
21+
<li><a href="/storage/upload-task">&ltUploadTask&gt</a></li>
22+
<li><a href="/storage/download-url">&ltDownloadURL&gt</a></li>
23+
<li><a href="/storage/storage-list">&ltStorageList&gt</a></li>
2424
<li class="heading">analytics</li>
2525
<li><a href="/guide/todo">&ltPageView&gt</a></li>
2626
</ul>

Diff for: docs/src/pages/storage/download-url.md

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
---
2+
title: DownloadURL Component
3+
pubDate: 2023-07-23
4+
description: SvelteFire DownloadURL Component API reference
5+
layout: ../../layouts/MainLayout.astro
6+
---
7+
8+
# DownloadURL
9+
10+
Returns the download URL for a file in Firebase Storage.
11+
12+
### Props
13+
14+
- `ref` - A Firebase Storage reference or path string (e.g. `files/hi-mom.txt`)
15+
16+
### Slots
17+
18+
- `default` - Shown when the url is available
19+
- `loading` - Shown while the url is loading
20+
21+
### Slot Props
22+
23+
- `link` - The download URL
24+
- `ref` - Storage reference
25+
- `storage` - The Firestore instance
26+
27+
### Example
28+
29+
```svelte
30+
<script>
31+
import { DownloadURL } from "sveltefire";
32+
</script>
33+
34+
35+
<DownloadURL ref="images/pic.png" let:link let:ref>
36+
<!-- show img -->
37+
<img src={link} />
38+
39+
<!-- or download via link -->
40+
<a href={link} download>{ref?.name}</a>
41+
</DownloadURL>
42+
```

Diff for: docs/src/pages/storage/storage-list.md

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
---
2+
title: StorageList Component
3+
pubDate: 2023-07-23
4+
description: SvelteFire StorageList Component API reference
5+
layout: ../../layouts/MainLayout.astro
6+
---
7+
8+
# StorageList
9+
10+
Returns a list of files stored in Firebase Storage.
11+
12+
### Props
13+
14+
- `ref` - A Firebase Storage reference or path string (e.g. `files/hi-mom.txt`)
15+
16+
### Slots
17+
18+
- `default` - Shown when the list is available
19+
- `loading` - Shown while the list is loading
20+
21+
### Slot Props
22+
23+
- `list` - The list of files and prefixes
24+
- `ref` - Storage reference
25+
- `storage` - The Firestore instance
26+
27+
### Example
28+
29+
```svelte
30+
<script>
31+
import { StorageList } from "sveltefire";
32+
</script>
33+
34+
35+
<StorageList ref="images/uid" let:list>
36+
<ul>
37+
{#if list === null}
38+
<li>Loading...</li>
39+
{:else if list.prefixes.length === 0 && list.items.length === 0}
40+
<li>Empty</li>
41+
{:else}
42+
<!-- Listing the prefixes -->
43+
{#each list.prefixes as prefix}
44+
<li>
45+
{prefix.name}
46+
</li>
47+
{/each}
48+
<!-- Listing the objects in the given folder -->
49+
{#each list.items as item}
50+
<li>
51+
{item.name}
52+
</li>
53+
{/each}
54+
{/if}
55+
</ul>
56+
</StorageList>
57+
```

Diff for: docs/src/pages/storage/upload-task.md

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
---
2+
title: UploadTask Component
3+
pubDate: 2023-07-23
4+
description: SvelteFire UploadTask Component API reference
5+
layout: ../../layouts/MainLayout.astro
6+
---
7+
8+
# UploadTask
9+
10+
Uploads a file to a Firebase storage bucket.
11+
12+
### Props
13+
14+
- `ref` - A Firebase Storage reference or path string (e.g. `files/hi-mom.txt`)
15+
- `data` - the file data to be uploaded as `Blob | Uint8Array | ArrayBuffer`
16+
- `metadata` - (optional) file metadata
17+
18+
19+
### Slots
20+
21+
- `default`
22+
23+
### Slot Props
24+
25+
- `snapshot` - Firebase UploadTaskSnapshot
26+
- `task` - Firebase UploadTask
27+
- `progress` - Number as a percentage of the upload progress
28+
- `storage` - The Firestore instance
29+
30+
### Example
31+
32+
```svelte
33+
<script>
34+
import { DownloadURL, UploadTask } from "sveltefire";
35+
36+
let file;
37+
38+
function chooseFile(e) {
39+
file = e.target.files[0];
40+
}
41+
</script>
42+
43+
<input type="file" on:change={chooseFile} />
44+
45+
{#if file}
46+
<UploadTask ref="myFile.txt" data={file} let:progress let:snapshot>
47+
{#if snapshot?.state === "running"}
48+
{progress}% uploaded
49+
{/if}
50+
51+
{#if snapshot?.state === "success"}
52+
<DownloadURL ref={snapshot?.ref} let:link>
53+
<a href={link} download>Link</a>
54+
</DownloadURL>
55+
{/if}
56+
</UploadTask>
57+
{/if}
58+
```

Diff for: package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "sveltefire",
3-
"version": "0.4.1",
3+
"version": "0.4.2",
44
"scripts": {
55
"dev": "vite dev",
66
"build": "vite build && npm run package",

Diff for: src/lib/stores/sdk.ts

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { writable } from "svelte/store";
21
import type { Firestore } from "firebase/firestore";
32
import type { Auth } from "firebase/auth";
43
import { getContext, setContext } from "svelte";

Diff for: tests/storage.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ test('Renders download links', async ({ page }) => {
88
expect( linksCount ).toBeGreaterThan(0);
99
});
1010

11-
test.only('Uploads a file', async ({ page }) => {
11+
test('Uploads a file', async ({ page }) => {
1212
await page.goto('/storage-test');
1313
await page.getByRole('button', { name: 'Make File' }).click();
1414
await expect(page.getByTestId('progress')).toContainText('100% uploaded');

0 commit comments

Comments
 (0)