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

Collection editing revamp #2332

Merged
merged 140 commits into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
140 commits
Select commit Hold shift + click to select a range
dd7bc75
wip
emma-sg Jan 21, 2025
6fbcbb2
name/summary/description editor (part 1)
emma-sg Jan 21, 2025
0e97d1b
share dialog
emma-sg Jan 22, 2025
56605de
track dirty state
emma-sg Jan 22, 2025
63c13b4
tweaks
emma-sg Jan 22, 2025
21539cc
more little fixes
emma-sg Jan 22, 2025
3ffbfcd
wip uploads
emma-sg Jan 22, 2025
f8798d2
allow aborting uploads
emma-sg Jan 22, 2025
3588e27
merge homepage editing & updates into editing dialog
emma-sg Jan 22, 2025
151a4e2
refactor logic into separate files
emma-sg Jan 22, 2025
fd2d4d8
more refactors
emma-sg Jan 22, 2025
e94bbf5
allow opening to a specific tab
emma-sg Jan 23, 2025
f5dbcd3
tun off page url autocomplete (it has its own)
emma-sg Jan 23, 2025
f78e1ac
fix thumbnail & snapshot state passing
emma-sg Jan 23, 2025
5f5ba02
improve editing ux
emma-sg Jan 23, 2025
e8016f5
ux tweaks
emma-sg Jan 23, 2025
00f17c3
add edit icon button to header
emma-sg Jan 24, 2025
cd5f0db
allow editing collection from collection grid
emma-sg Jan 24, 2025
e824a67
use edit collection in collection list, and lots of small fixes
emma-sg Jan 24, 2025
dd28fce
Merge remote-tracking branch 'origin/main' into frontend-collection-e…
emma-sg Jan 27, 2025
ae9a217
wip remove homepage & move thumbnail selector to general section
emma-sg Jan 27, 2025
52e8433
wip
emma-sg Jan 27, 2025
cd004fe
get most aspects of dialog working!
emma-sg Jan 28, 2025
8efb176
get thumbnail selection working
emma-sg Jan 28, 2025
3288af2
first pass at backend update to allow thumbnail src to be saved
emma-sg Jan 28, 2025
5d38d73
redo thumbnail source as separate field on collection model
emma-sg Jan 29, 2025
5685b0c
fix lint issue
emma-sg Jan 29, 2025
a94230f
fix missed type change
emma-sg Jan 29, 2025
fa55e44
pass thumbnail source into thumbnail source update fn
emma-sg Jan 29, 2025
917dc7f
fix search param names
emma-sg Jan 29, 2025
9560add
wip
emma-sg Jan 29, 2025
1e2a590
feat: Update references to org public profile -> gallery (#2330)
SuaYoo Jan 27, 2025
4b627e3
Remove duplicate dialogue actions from collections
Shrinks99 Jan 28, 2025
012b9d3
Add remaining icon buttons
Shrinks99 Jan 28, 2025
e07922d
Remove share item from menu
Shrinks99 Jan 28, 2025
cb9dc7f
Remove button group
Shrinks99 Jan 28, 2025
57c4089
Move edit button for logged in users
Shrinks99 Jan 28, 2025
9f27135
fix eslint error
Shrinks99 Jan 28, 2025
a0d5035
Add dashboard link
Shrinks99 Jan 28, 2025
4a5ed2f
Simplify collection grid action dropdown → edit button
Shrinks99 Jan 28, 2025
8cf56fd
Button casing & consistency fixes
Shrinks99 Jan 28, 2025
e36a67f
Align pageHeader actions to bottom of container
Shrinks99 Jan 28, 2025
e663c0f
Adds org description and url to dashboard
Shrinks99 Jan 28, 2025
4458ae9
Re-remove duped menu item
Shrinks99 Jan 28, 2025
756eebd
Restore pencil and fix primary action buttons
Shrinks99 Jan 28, 2025
e866ca4
Remove view public button from share-collection
Shrinks99 Jan 29, 2025
d18339d
feat: Update references to org public profile -> gallery (#2330)
SuaYoo Jan 27, 2025
24ae991
Remove duplicate dialogue actions from collections
Shrinks99 Jan 28, 2025
f687ba9
Add remaining icon buttons
Shrinks99 Jan 28, 2025
8d34347
hook up edit button to edit dialog
emma-sg Jan 29, 2025
4944dd9
wip: broken logic for moving public collection view to top right
Shrinks99 Jan 29, 2025
1b0802e
refactor shareLink into separate fn
emma-sg Jan 29, 2025
3ca6726
Remove view public from share-collection controls
Shrinks99 Jan 29, 2025
594569b
temp: Move collection gallery link to icon button
Shrinks99 Jan 29, 2025
2eb4881
lint & format
emma-sg Jan 29, 2025
67e8664
Merge pull request #2344 from webrecorder/frontend-collection-control…
emma-sg Jan 29, 2025
92ef192
update button text
Shrinks99 Jan 29, 2025
15a0a62
Removes dropdown, moves controls to icon buttons
Shrinks99 Jan 29, 2025
e58ee98
make explicit that this code isn't doing anything
Shrinks99 Jan 29, 2025
27a22aa
swap summary textarea for input
emma-sg Jan 29, 2025
b2dbdf3
Merge branch 'frontend-collection-editing-dialog' of https://github.c…
emma-sg Jan 29, 2025
9064a6f
clean up clipboard button value
emma-sg Jan 29, 2025
d2b101a
fix layout shift issues on collection detail page
emma-sg Jan 29, 2025
ee6050e
dash → en dash on collection thumbnail badge
Shrinks99 Jan 29, 2025
24f9e57
fix a whole bunch of small-ish issues
emma-sg Jan 30, 2025
8f6f1a8
Merge branch 'frontend-collection-editing-dialog' of https://github.c…
emma-sg Jan 30, 2025
03301a1
polish - more consistent spacing & wording, small bugfixes, etc
emma-sg Jan 30, 2025
6e6fd48
reset all things when resetting dialog
emma-sg Jan 30, 2025
ad25b84
tweak snapshot preview help text
emma-sg Jan 30, 2025
074077f
simplify logic for allowing selecting page thumbnail
emma-sg Jan 30, 2025
8937464
remove console logs
emma-sg Jan 30, 2025
bcd66e3
Merge branch 'main' into frontend-collection-editing-dialog
emma-sg Jan 30, 2025
ffb69a4
change collection metadata dialog into just collection create dialog
emma-sg Jan 30, 2025
0850e8a
clean up missed extra attr
emma-sg Jan 30, 2025
132bd1a
remove extra `/` in api.upload method
emma-sg Jan 30, 2025
9afc69c
fix missed renames
emma-sg Jan 30, 2025
405b37e
remove name field customization
emma-sg Jan 30, 2025
f146c3e
exit early out of blob task if snapshot fields aren't defined
emma-sg Jan 30, 2025
1bc2ab3
fix missing type conversions
emma-sg Jan 30, 2025
df14c5e
tweak text rendering
emma-sg Jan 30, 2025
c58fa0d
fix some edge cases
emma-sg Jan 30, 2025
828e92b
allow resetting thumbnail source
emma-sg Jan 30, 2025
e32eeb4
fix a couple issues with state management
emma-sg Jan 30, 2025
8eb179d
clean up sharing dialog
emma-sg Jan 30, 2025
77a47ec
allow closing the dialog with the top right x icon, and fix an issue …
emma-sg Jan 30, 2025
32078be
clean up thumbnail selector & add better error handling & informing
emma-sg Jan 30, 2025
1b6186e
Merge branch 'main' into frontend-collection-editing-dialog
emma-sg Feb 3, 2025
e0391b6
Changes metadata → details
Shrinks99 Feb 3, 2025
d593559
metadata → details (public view)
Shrinks99 Feb 3, 2025
1915639
rename select collection page file
emma-sg Feb 4, 2025
83a179f
use click handler on button rather than icon
emma-sg Feb 4, 2025
f5a4828
Unify initial view naming
Shrinks99 Feb 5, 2025
f0350aa
Edit Collection → Collection Settings
Shrinks99 Feb 5, 2025
97245c5
Update workflow edit icon button
Shrinks99 Feb 5, 2025
c9cdd98
Update collection editing icons and tab names
Shrinks99 Feb 5, 2025
5847976
Revert one of the gear updates
Shrinks99 Feb 5, 2025
65f3b4b
fix the thing!!! thank you sua
emma-sg Feb 5, 2025
53d02c3
Merge branch 'frontend-collection-editing-dialog' of https://github.c…
emma-sg Feb 5, 2025
7b5051e
allow thumbnail list to scroll
emma-sg Feb 5, 2025
35db154
tweak min widths & add sticky header
emma-sg Feb 6, 2025
c3ef9ff
fix download url
emma-sg Feb 6, 2025
ef8e0a7
Remove share options from collection list actions
Shrinks99 Feb 6, 2025
dd01e4e
add "set initial view to this page" checkbox to edit dialog
emma-sg Feb 6, 2025
de42f0c
Merge branch 'frontend-collection-editing-dialog' of https://github.c…
emma-sg Feb 6, 2025
423f2e1
clean up
emma-sg Feb 6, 2025
40c74eb
Merge branch 'main' into frontend-collection-editing-dialog
emma-sg Feb 6, 2025
3131678
resolve layout issues
emma-sg Feb 6, 2025
9b69b6a
remove download button from private detail view
emma-sg Feb 6, 2025
5f5b102
small bugfixes
emma-sg Feb 6, 2025
4e2f402
don't allow actually selecting page thumbnail until there's a page th…
emma-sg Feb 6, 2025
10bc5ac
fix a couple subtle page selection indicator bugs
emma-sg Feb 6, 2025
d0cdcb1
remove a few `console.log`s
emma-sg Feb 6, 2025
0e22179
fix update ordering
emma-sg Feb 6, 2025
a61aa08
update error to warning rather than error when thumbnail isnt actuall…
emma-sg Feb 6, 2025
e422855
remove more `console.log`s
emma-sg Feb 6, 2025
c103123
fix uploading logic & pass correct params in initial view selection d…
emma-sg Feb 10, 2025
4c2a16c
changes from code review
emma-sg Feb 10, 2025
86784da
reset page selector on dialog reset
emma-sg Feb 10, 2025
b233321
Merge branch 'main' into frontend-collection-editing-dialog
emma-sg Feb 10, 2025
a2de997
hide collection share buttons when collection is private
emma-sg Feb 10, 2025
5b8bfd8
update copy
SuaYoo Feb 10, 2025
522d96c
move "visit public collections gallery" button down to public collect…
emma-sg Feb 10, 2025
9db4e46
Merge branch 'frontend-collection-editing-dialog' of https://github.c…
emma-sg Feb 10, 2025
916e713
add "select initial view" and "edit description" to action menu
emma-sg Feb 10, 2025
4dcad80
change edit button to icon button
emma-sg Feb 10, 2025
c635871
ensure "edit collection settings" is used everywhere
emma-sg Feb 10, 2025
6888787
update "change org settings" to "edit org settings"
emma-sg Feb 10, 2025
cee0936
make summary clickable
SuaYoo Feb 11, 2025
69df059
fix & add tests for thumbnail upload
emma-sg Feb 11, 2025
b8c1dd1
Merge branch 'frontend-collection-editing-dialog' of https://github.c…
emma-sg Feb 11, 2025
f71caf6
make set initial view checkbox not checked by default
emma-sg Feb 11, 2025
1157d62
rename "general" to "presentation" to better match tab titles
emma-sg Feb 11, 2025
92d3923
fix issue where collection caption isn't always null when empty
emma-sg Feb 11, 2025
5bcb7ec
handle no pages
SuaYoo Feb 11, 2025
07f6760
add delay to closing combobox in page selection component
emma-sg Feb 11, 2025
2c7bdef
Merge branch 'frontend-collection-editing-dialog' of https://github.c…
emma-sg Feb 11, 2025
8ca8c87
fix test
emma-sg Feb 11, 2025
6f17063
add comment about why timeout in page selector is useful
emma-sg Feb 11, 2025
a1b599c
revert unused change to md editor event
emma-sg Feb 11, 2025
3daccd9
remove console log
SuaYoo Feb 11, 2025
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
34 changes: 31 additions & 3 deletions backend/btrixcloud/colls.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""

# pylint: disable=too-many-lines

from datetime import datetime
from collections import Counter
from uuid import UUID, uuid4
from typing import Optional, List, TYPE_CHECKING, cast, Dict, Tuple, Any, Union
Expand All @@ -20,10 +20,12 @@

from .pagination import DEFAULT_PAGE_SIZE, paginated_format
from .models import (
AnyHttpUrl,
Collection,
CollIn,
CollOut,
CollIdName,
CollectionThumbnailSource,
UpdateColl,
AddRemoveCrawlList,
BaseCrawl,
Expand Down Expand Up @@ -843,8 +845,17 @@ async def set_home_url(

return {"updated": True}

# pylint: disable=too-many-locals
async def upload_thumbnail_stream(
self, stream, filename: str, coll_id: UUID, org: Organization, user: User
self,
stream,
filename: str,
coll_id: UUID,
org: Organization,
user: User,
source_url: Optional[AnyHttpUrl] = None,
source_ts: Optional[datetime] = None,
source_page_id: Optional[UUID] = None,
) -> Dict[str, bool]:
"""Upload file as stream to use as collection thumbnail"""
coll = await self.get_collection(coll_id)
Expand Down Expand Up @@ -903,6 +914,13 @@ async def stream_iter():

coll.thumbnail = thumbnail_file

if source_url and source_ts and source_page_id:
coll.thumbnailSource = CollectionThumbnailSource(
url=source_url,
urlTs=source_ts,
urlPageId=source_page_id,
)

# Update entire document to avoid bson.errors.InvalidDocument exception
await self.collections.find_one_and_update(
{"_id": coll_id, "oid": org.id},
Expand Down Expand Up @@ -1226,11 +1244,21 @@ async def upload_thumbnail_stream(
request: Request,
filename: str,
coll_id: UUID,
sourceUrl: Optional[AnyHttpUrl],
sourceTs: Optional[datetime],
sourcePageId: Optional[UUID],
org: Organization = Depends(org_crawl_dep),
user: User = Depends(user_dep),
):
return await colls.upload_thumbnail_stream(
request.stream(), filename, coll_id, org, user
request.stream(),
filename,
coll_id,
org,
user,
sourceUrl,
sourceTs,
sourcePageId,
)

@app.delete(
Expand Down
12 changes: 12 additions & 0 deletions backend/btrixcloud/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1236,6 +1236,15 @@ class CollAccessType(str, Enum):
PUBLIC = "public"


# ============================================================================
class CollectionThumbnailSource(BaseModel):
"""The page source for a thumbnail"""

url: AnyHttpUrl
urlTs: datetime
urlPageId: UUID


# ============================================================================
class Collection(BaseMongoModel):
"""Org collection structure"""
Expand Down Expand Up @@ -1268,6 +1277,7 @@ class Collection(BaseMongoModel):
homeUrlPageId: Optional[UUID] = None

thumbnail: Optional[ImageFile] = None
thumbnailSource: Optional[CollectionThumbnailSource] = None
defaultThumbnailName: Optional[str] = None

allowPublicDownload: Optional[bool] = True
Expand Down Expand Up @@ -1323,6 +1333,7 @@ class CollOut(BaseMongoModel):

resources: List[CrawlFileOut] = []
thumbnail: Optional[ImageFileOut] = None
thumbnailSource: Optional[CollectionThumbnailSource] = None
defaultThumbnailName: Optional[str] = None

allowPublicDownload: bool = True
Expand Down Expand Up @@ -1372,6 +1383,7 @@ class UpdateColl(BaseModel):
access: Optional[CollAccessType] = None
defaultThumbnailName: Optional[str] = None
allowPublicDownload: Optional[bool] = None
thumbnailSource: Optional[CollectionThumbnailSource] = None


# ============================================================================
Expand Down
16 changes: 14 additions & 2 deletions backend/test/test_collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -1030,9 +1030,10 @@ def test_collection_url_list(crawler_auth_headers, default_org_id):


def test_upload_collection_thumbnail(crawler_auth_headers, default_org_id):
# https://dev.browsertrix.com/api/orgs/c69247f4-415e-4abc-b449-e85d2f26c626/collections/b764fbe1-baab-4dc5-8dca-2db6f82c250b/thumbnail?filename=page-thumbnail_47fe599e-ed62-4edd-b078-93d4bf281e0f.jpeg&sourceUrl=https%3A%2F%2Fspecs.webrecorder.net%2F&sourceTs=2024-08-16T08%3A00%3A21.601000Z&sourcePageId=47fe599e-ed62-4edd-b078-93d4bf281e0f
with open(os.path.join(curr_dir, "data", "thumbnail.jpg"), "rb") as fh:
r = requests.put(
f"{API_PREFIX}/orgs/{default_org_id}/collections/{_public_coll_id}/thumbnail?filename=thumbnail.jpg",
f"{API_PREFIX}/orgs/{default_org_id}/collections/{_public_coll_id}/thumbnail?filename=thumbnail.jpg&sourceUrl=https%3A%2F%2Fexample.com%2F&sourceTs=2024-08-16T08%3A00%3A21.601000Z&sourcePageId=1bba4aba-d5be-4943-ad48-d6710633d754",
headers=crawler_auth_headers,
data=read_in_chunks(fh),
)
Expand All @@ -1044,7 +1045,8 @@ def test_upload_collection_thumbnail(crawler_auth_headers, default_org_id):
headers=crawler_auth_headers,
)
assert r.status_code == 200
thumbnail = r.json()["thumbnail"]
collection = r.json()
thumbnail = collection["thumbnail"]

assert thumbnail["name"]
assert thumbnail["path"]
Expand All @@ -1057,6 +1059,16 @@ def test_upload_collection_thumbnail(crawler_auth_headers, default_org_id):
assert thumbnail["userName"]
assert thumbnail["created"]

thumbnailSource = collection["thumbnailSource"]

assert thumbnailSource["url"]
assert thumbnailSource["urlTs"]
assert thumbnailSource["urlPageId"]

assert thumbnailSource["url"] == "https://example.com/"
assert thumbnailSource["urlTs"] == "2024-08-16T08:00:21.601000Z"
assert thumbnailSource["urlPageId"] == "1bba4aba-d5be-4943-ad48-d6710633d754"


def test_set_collection_default_thumbnail(crawler_auth_headers, default_org_id):
default_thumbnail_name = "orange-default.avif"
Expand Down
4 changes: 2 additions & 2 deletions frontend/docs/docs/user-guide/org-settings.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Change Org Settings
# Edit Org Settings

Settings that apply to the entire organization are found in the **Settings** page. If you're an org admin, you'll see the link to _Settings_ in the org navigation bar.

Expand All @@ -13,7 +13,7 @@ The org URL is where you and other org members will go to view the dashboard, co
Org name and URLs are unique to each Browsertrix instance (for example, on `app.browsertrix.com`) and you may be prompted to change the org name or URL if either are already in use by another org.

??? info "What information will be visible to the public?"
All org information is private until you make the org visible. Once your org is made visible to the public, the org name, description, and website will appear on the org's public gallery page. You can preview how information appears to the public by clicking **View as public**.
All org information is private until you make the org visible. Once your org is made visible to the public, the org name, description, and website will appear on the org's public collections gallery page. You can preview how information appears to the public by visiting the linked public collections gallery page.

### Public Collections Gallery

Expand Down
3 changes: 2 additions & 1 deletion frontend/src/components/ui/button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ export class Button extends TailwindElement {
small: tw`min-h-6 min-w-6 rounded-md text-base`,
medium: tw`min-h-8 min-w-8 rounded-sm text-lg`,
}[this.size],
this.raised && tw`shadow ring-1 ring-neutral-200`,
this.raised &&
tw`shadow ring-1 ring-stone-500/20 hover:shadow-stone-800/20 hover:ring-stone-800/20`,
this.filled
? [
tw`text-white`,
Expand Down
33 changes: 24 additions & 9 deletions frontend/src/components/ui/navigation/navigation-button.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-disable lit/binding-positions */
/* eslint-disable lit/no-invalid-html */
import clsx from "clsx";
import { css, type PropertyValueMap } from "lit";
import { customElement, property } from "lit/decorators.js";
import { ifDefined } from "lit/directives/if-defined.js";
Expand All @@ -26,6 +27,9 @@ export class NavigationButton extends TailwindElement {
@property({ type: String })
type: "submit" | "button" = "button";

@property({ type: String })
variant: "primary" | "error" = "primary"; // TODO expand if necessary

@property({ type: String })
label?: string;

Expand Down Expand Up @@ -76,8 +80,9 @@ export class NavigationButton extends TailwindElement {
return html`<${tag}
type=${this.type === "submit" ? "submit" : "button"}
part="button"
class=${[
tw`flex w-full cursor-pointer items-center gap-2 rounded font-medium leading-[16px] outline-primary-600 transition hover:transition-none focus-visible:outline focus-visible:outline-3 focus-visible:outline-offset-1 disabled:cursor-not-allowed disabled:bg-transparent disabled:opacity-50`,
class=${clsx([
tw`flex w-full cursor-pointer items-center gap-2 rounded font-medium leading-[16px] transition hover:transition-none focus-visible:outline focus-visible:outline-3 focus-visible:outline-offset-1 disabled:cursor-not-allowed disabled:bg-transparent disabled:opacity-50`,

this.icon ? tw`min-h-6 min-w-6` : tw``,
{
small: this.icon ? tw`min-h-6 p-0` : tw`min-h-6 px-2 py-0`,
Expand All @@ -89,17 +94,27 @@ export class NavigationButton extends TailwindElement {
center: "justify-center",
right: "justify-end",
}[this.align],
this.active
? tw`bg-primary-100/80 text-primary-800 shadow-sm shadow-primary-900/20`
: tw`text-neutral-700 hover:bg-primary-50`,
]
.filter(Boolean)
.join(" ")}
this.active && "shadow-sm",
{
primary: [
tw`outline-primary-600`,
this.active
? tw`bg-primary-100/80 text-primary-800 shadow-primary-900/20`
: tw`text-neutral-700 hover:bg-primary-50`,
],
error: [
tw`outline-red-600`,
this.active
? tw`bg-red-100/80 text-red-800 shadow-red-900/20`
: tw`text-red-700 ring-1 ring-red-300 hover:bg-red-50`,
],
}[this.variant],
])}
?disabled=${this.disabled}
href=${ifDefined(this.href)}
aria-label=${ifDefined(this.label)}
@click=${this.handleClick}

>
<slot></slot>
</${tag}>`;
Expand Down
7 changes: 7 additions & 0 deletions frontend/src/components/ui/tab-group/tab-group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { TailwindElement } from "@/classes/TailwindElement";
import { pageSectionsWithNav } from "@/layouts/pageSectionsWithNav";

/**
* @fires btrix-tab-change
* @example Usage:
* ```ts
* <btrix-tab-group>
Expand Down Expand Up @@ -145,5 +146,11 @@ export class TabGroup extends TailwindElement {
private onSelectTab(e: CustomEvent<TabClickDetail>) {
e.stopPropagation();
this.active = e.detail.panel;
this.dispatchEvent(
new CustomEvent<string>("btrix-tab-change", {
detail: this.active,
bubbles: true,
}),
);
}
}
7 changes: 7 additions & 0 deletions frontend/src/context/view-state.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { createContext } from "@lit/context";

import { type ViewState } from "@/utils/APIRouter";

export type ViewStateContext = ViewState | null;

export const viewStateContext = createContext<ViewStateContext>("viewState");
11 changes: 10 additions & 1 deletion frontend/src/controllers/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ export class APIController implements ReactiveController {
async upload(
path: string,
file: File,
abortSignal?: AbortSignal,
): Promise<{ id: string; added: boolean; storageQuotaReached: boolean }> {
const auth = appState.auth;

Expand All @@ -185,9 +186,12 @@ export class APIController implements ReactiveController {
}

return new Promise((resolve, reject) => {
if (abortSignal?.aborted) {
reject(AbortReason.UserCancel);
}
const xhr = new XMLHttpRequest();

xhr.open("PUT", `/api/${path}`);
xhr.open("PUT", `/api${path}`);
xhr.setRequestHeader("Content-Type", "application/octet-stream");
Object.entries(auth.headers).forEach(([k, v]) => {
xhr.setRequestHeader(k, v);
Expand Down Expand Up @@ -221,6 +225,11 @@ export class APIController implements ReactiveController {

xhr.send(file);

abortSignal?.addEventListener("abort", () => {
xhr.abort();
reject(AbortReason.UserCancel);
});

this.uploadRequest = xhr;
});
}
Expand Down
1 change: 1 addition & 0 deletions frontend/src/decorators/needLogin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ describe("needLogin", () => {
}

const Element = needLogin(
// @ts-expect-error not stubbing full BtrixElement
class TestElement extends LiteElementMock {
appState = appState;
} as unknown as {
Expand Down
Loading
Loading