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

fix: proper drive space header button logic #5642

Merged
merged 1 commit into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,13 @@
const client = getClient()
const query = createQuery()

const me = getCurrentAccount()

let loading = true
let hasTeamspace = false
query.query(
document.class.Teamspace,
{ archived: false },
{ archived: false, members: me._id },
(res) => {
hasTeamspace = res.length > 0
loading = false
Expand Down Expand Up @@ -73,7 +75,7 @@
}
}

const dropdownItems = hasAccountRole(getCurrentAccount(), AccountRole.User)
const dropdownItems = hasAccountRole(me, AccountRole.User)
? [
{ id: document.string.CreateDocument, label: document.string.CreateDocument },
{ id: document.string.CreateTeamspace, label: document.string.CreateTeamspace }
Expand Down
10 changes: 7 additions & 3 deletions plugins/drive-resources/src/components/CreateFolder.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
return name === ''
}

export let space: Ref<Drive>
export let parent: Ref<Folder>
export let space: Ref<Drive> | undefined
export let parent: Ref<Folder> | undefined

const id: Ref<Folder> = generateId()

Expand All @@ -48,6 +48,10 @@
}

async function create (): Promise<void> {
if (_space === undefined) {
return
}

let path: Ref<Folder>[] = []

if (_parent != null && _parent !== drive.ids.Root) {
Expand All @@ -60,7 +64,7 @@

await client.createDoc(
drive.class.Folder,
space,
_space,
{
name: getTitle(name),
parent: _parent ?? drive.ids.Root,
Expand Down
10 changes: 5 additions & 5 deletions plugins/drive-resources/src/components/DriveSpaceHeader.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@
export let currentSpace: Ref<Drive> | undefined
export let currentFragment: string | undefined

const me = getCurrentAccount()

const query = createQuery()

let loading = true
let hasDrive = false
query.query(
drive.class.Drive,
{ archived: false },
{ archived: false, members: me._id },
(res) => {
hasDrive = res.length > 0
loading = false
Expand All @@ -56,9 +58,7 @@
}

async function handleCreateFolder (): Promise<void> {
if (currentSpace !== undefined) {
await createFolder(currentSpace, parent, true)
}
await createFolder(currentSpace, parent, true)
}

async function handleUploadFile (): Promise<void> {
Expand All @@ -67,7 +67,7 @@
}
}

const dropdownItems = hasAccountRole(getCurrentAccount(), AccountRole.User)
const dropdownItems = hasAccountRole(me, AccountRole.User)
? [
{ id: drive.string.CreateDrive, label: drive.string.CreateDrive, icon: drive.icon.Drive },
{ id: drive.string.CreateFolder, label: drive.string.CreateFolder, icon: drive.icon.Folder },
Expand Down
2 changes: 1 addition & 1 deletion plugins/drive-resources/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ async function navigateToDoc (_id: Ref<Doc>, _class: Ref<Class<Doc>>): Promise<v
}
}

export async function createFolder (space: Ref<Drive>, parent: Ref<Folder>, open = false): Promise<void> {
export async function createFolder (space: Ref<Drive> | undefined, parent: Ref<Folder>, open = false): Promise<void> {
showPopup(CreateFolder, { space, parent }, 'top', async (id) => {
if (open && id !== undefined && id !== null) {
await navigateToDoc(id, drive.class.Folder)
Expand Down