mirror of
https://git.srhtnin.garden/sarah/SaraView.git
synced 2026-10-14 18:38:11 +02:00
New/Upload buttons with the file tree, above or below
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
6750f7927f
commit
0450fee42b
6 files changed
+27
-100
No files matched your search
@@ -1,9 +1,7 @@
|
||||
import React, { useEffect, useRef, useState } from "react";
|
||||
import React, { useEffect, useState } from "react";
|
||||
|
||||
import {
|
||||
CreateEntry,
|
||||
DeleteEntry,
|
||||
FetchInheritedLock,
|
||||
FetchLock,
|
||||
FetchTree,
|
||||
GetDownloadUrl,
|
||||
@@ -35,7 +33,6 @@ export default function DirectoryPane({
|
||||
const [ModalConfig, SetModalConfig] = useState(null);
|
||||
const [ErrorMessage, SetErrorMessage] = useState(null);
|
||||
const [IsDraggingOver, SetIsDraggingOver] = useState(false);
|
||||
const FileInputRef = useRef(null);
|
||||
|
||||
async function Reload() {
|
||||
try {
|
||||
@@ -58,30 +55,6 @@ export default function DirectoryPane({
|
||||
return DirectoryPath ? `${DirectoryPath}/${Name}` : Name;
|
||||
}
|
||||
|
||||
async function OpenCreateFileModal() {
|
||||
const Inherited = await FetchInheritedLock(RootName, DirectoryPath).catch(() => ({}));
|
||||
SetModalConfig({
|
||||
Mode: "createFile",
|
||||
InheritedUsers: Inherited.Users || [],
|
||||
InheritedGroups: Inherited.Groups || [],
|
||||
});
|
||||
}
|
||||
|
||||
async function OpenCreateDirectoryModal() {
|
||||
const Inherited = await FetchInheritedLock(RootName, DirectoryPath).catch(() => ({}));
|
||||
SetModalConfig({
|
||||
Mode: "createDirectory",
|
||||
InheritedUsers: Inherited.Users || [],
|
||||
InheritedGroups: Inherited.Groups || [],
|
||||
});
|
||||
}
|
||||
|
||||
function SetsEqual(FirstList, SecondList) {
|
||||
if (FirstList.length !== SecondList.length) return false;
|
||||
const FirstSet = new Set(FirstList);
|
||||
return SecondList.every((Item) => FirstSet.has(Item));
|
||||
}
|
||||
|
||||
async function HandleRequestLockEdit(Event, Entry) {
|
||||
Event.stopPropagation();
|
||||
const FullPath = JoinPath(Entry.Name);
|
||||
@@ -151,23 +124,7 @@ export default function DirectoryPane({
|
||||
|
||||
async function HandleModalConfirm(Name, Users, Groups) {
|
||||
try {
|
||||
if (ModalConfig.Mode === "createFile" || ModalConfig.Mode === "createDirectory") {
|
||||
if (!Name || !Name.trim()) return;
|
||||
|
||||
const IsDirectory = ModalConfig.Mode === "createDirectory";
|
||||
const FullPath = JoinPath(Name.trim());
|
||||
await CreateEntry(RootName, FullPath, IsDirectory);
|
||||
|
||||
const MatchesInherited =
|
||||
SetsEqual(Users, ModalConfig.InheritedUsers) && SetsEqual(Groups, ModalConfig.InheritedGroups);
|
||||
|
||||
if (!MatchesInherited && (Users.length > 0 || Groups.length > 0)) {
|
||||
await SetLockApi(RootName, FullPath, Users, Groups);
|
||||
}
|
||||
|
||||
await Reload();
|
||||
OnEntryCreated();
|
||||
} else if (ModalConfig.Mode === "editLock") {
|
||||
if (ModalConfig.Mode === "editLock") {
|
||||
await SetLockApi(RootName, ModalConfig.TargetPath, Users, Groups);
|
||||
await Reload();
|
||||
}
|
||||
@@ -190,15 +147,6 @@ export default function DirectoryPane({
|
||||
OnEntryCreated();
|
||||
}
|
||||
|
||||
function HandleUploadButtonClick() {
|
||||
FileInputRef.current?.click();
|
||||
}
|
||||
|
||||
function HandleFileInputChange(Event) {
|
||||
HandleUpload(Event.target.files);
|
||||
Event.target.value = "";
|
||||
}
|
||||
|
||||
function HandleDragOver(Event) {
|
||||
if (IsGuest) return;
|
||||
Event.preventDefault();
|
||||
@@ -219,20 +167,6 @@ export default function DirectoryPane({
|
||||
|
||||
return (
|
||||
<div className="DirectoryPane">
|
||||
{!IsGuest && (
|
||||
<div className="PreviewToolbar">
|
||||
<button onClick={OpenCreateFileModal}>New File</button>
|
||||
<button onClick={OpenCreateDirectoryModal}>New Directory</button>
|
||||
<button onClick={HandleUploadButtonClick}>Upload</button>
|
||||
<input
|
||||
ref={FileInputRef}
|
||||
type="file"
|
||||
multiple
|
||||
style={{ display: "none" }}
|
||||
onChange={HandleFileInputChange}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
{LoadError && <div className="SidebarError">{LoadError}</div>}
|
||||
<div
|
||||
className={`DirectoryList${IsDraggingOver ? " DraggingOver" : ""}`}
|
||||
@@ -296,30 +230,6 @@ export default function DirectoryPane({
|
||||
)}
|
||||
</div>
|
||||
|
||||
{ModalConfig && ModalConfig.Mode === "createFile" && (
|
||||
<AccessModal
|
||||
Title={`New file in ${DirectoryPath || "root"}`}
|
||||
ShowNameField
|
||||
NamePlaceholder="Notes.md"
|
||||
InitialUsers={ModalConfig.InheritedUsers}
|
||||
InitialGroups={ModalConfig.InheritedGroups}
|
||||
ConfirmLabel="Create"
|
||||
OnConfirm={HandleModalConfirm}
|
||||
OnCancel={() => SetModalConfig(null)}
|
||||
/>
|
||||
)}
|
||||
{ModalConfig && ModalConfig.Mode === "createDirectory" && (
|
||||
<AccessModal
|
||||
Title={`New directory in ${DirectoryPath || "root"}`}
|
||||
ShowNameField
|
||||
NamePlaceholder="MyFolder"
|
||||
InitialUsers={ModalConfig.InheritedUsers}
|
||||
InitialGroups={ModalConfig.InheritedGroups}
|
||||
ConfirmLabel="Create"
|
||||
OnConfirm={HandleModalConfirm}
|
||||
OnCancel={() => SetModalConfig(null)}
|
||||
/>
|
||||
)}
|
||||
{ModalConfig && ModalConfig.Mode === "editLock" && (
|
||||
<AccessModal
|
||||
Title={`Access for "${ModalConfig.EntryName}"`}
|
||||
|
||||
Reference in new issue
Block a user