mirror of
https://git.srhtnin.garden/sarah/SaraView.git
synced 2026-10-15 02:43:17 +02:00
Added guests.
This commit is contained in:
1 parent
6743dd7626
commit
9736a55e00
10 files changed
+200
-84
No files matched your search
+29
-4
@@ -53,6 +53,8 @@ function ParseLocationPath(Pathname) {
|
||||
return { RootName: RootName || null, Path: RestSegments.join("/"), IsDirectory };
|
||||
}
|
||||
|
||||
const GuestUser = { Username: null, IsAdmin: false, IsGuest: true, Colour: "Purple" };
|
||||
|
||||
export default function App() {
|
||||
const [AuthState, SetAuthState] = useState("Loading");
|
||||
const [CurrentUser, SetCurrentUser] = useState(null);
|
||||
@@ -84,8 +86,10 @@ export default function App() {
|
||||
});
|
||||
}, []);
|
||||
|
||||
const IsUsable = AuthState === "LoggedIn" || AuthState === "Guest";
|
||||
|
||||
useEffect(() => {
|
||||
if (AuthState !== "LoggedIn") return;
|
||||
if (!IsUsable) return;
|
||||
|
||||
FetchRoots().then((Fetched) => {
|
||||
SetRoots(Fetched);
|
||||
@@ -100,7 +104,7 @@ export default function App() {
|
||||
}, [AuthState]);
|
||||
|
||||
useEffect(() => {
|
||||
if (AuthState !== "LoggedIn" || !ActiveRoot) return;
|
||||
if (!IsUsable || !ActiveRoot) return;
|
||||
|
||||
const Url = BuildLocationPath(ActiveRoot, ViewPath, ViewIsDirectory);
|
||||
if (window.location.pathname !== Url) {
|
||||
@@ -109,7 +113,7 @@ export default function App() {
|
||||
}, [AuthState, ActiveRoot, ViewPath, ViewIsDirectory]);
|
||||
|
||||
useEffect(() => {
|
||||
if (AuthState !== "LoggedIn") return;
|
||||
if (!IsUsable) return;
|
||||
|
||||
function HandlePopState() {
|
||||
RestoreFromLocation(Roots);
|
||||
@@ -174,6 +178,16 @@ export default function App() {
|
||||
SetAuthState("LoggedOut");
|
||||
}
|
||||
|
||||
function HandleContinueAsGuest() {
|
||||
SetCurrentUser(GuestUser);
|
||||
SetAuthState("Guest");
|
||||
}
|
||||
|
||||
function HandleRequestLogin() {
|
||||
SetCurrentUser(null);
|
||||
SetAuthState("LoggedOut");
|
||||
}
|
||||
|
||||
function HandleProfileUpdated(UpdatedUser) {
|
||||
SetCurrentUser((Existing) => ({ ...Existing, ...UpdatedUser }));
|
||||
}
|
||||
@@ -272,9 +286,16 @@ export default function App() {
|
||||
}
|
||||
|
||||
if (AuthState === "LoggedOut") {
|
||||
return <LoginScreen IsBootstrap={false} OnAuthenticated={HandleAuthenticated} />;
|
||||
return (
|
||||
<LoginScreen
|
||||
IsBootstrap={false}
|
||||
OnAuthenticated={HandleAuthenticated}
|
||||
OnContinueAsGuest={HandleContinueAsGuest}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
const IsGuest = AuthState === "Guest";
|
||||
const ShowTopBar = (Settings && Settings.ShowBreadcrumbs) || Roots.length > 1;
|
||||
const ConfirmBeforeDelete = Settings ? Settings.ConfirmBeforeDelete : true;
|
||||
|
||||
@@ -286,6 +307,7 @@ export default function App() {
|
||||
SelectedFile={ViewIsDirectory ? null : ViewPath}
|
||||
CurrentDirectoryPath={CurrentDirectoryPath}
|
||||
CurrentUser={CurrentUser}
|
||||
IsGuest={IsGuest}
|
||||
OnSelectFile={HandleSelectFile}
|
||||
OnSelectDirectory={OpenDirectoryNote}
|
||||
OnNavigateDirectory={HandleNavigateDirectory}
|
||||
@@ -293,6 +315,7 @@ export default function App() {
|
||||
OnEntryRenamed={HandleEntryRenamed}
|
||||
OnEntryDeleted={HandleEntryDeleted}
|
||||
OnOpenSettings={() => SetIsSettingsOpen(true)}
|
||||
OnRequestLogin={HandleRequestLogin}
|
||||
OnEntryCreated={RefreshSidebar}
|
||||
UseHyphenBullets={Settings ? Settings.UseHyphenBullets : true}
|
||||
UseAsciiFolderIcons={Settings ? Settings.UseAsciiFolderIcons : true}
|
||||
@@ -340,6 +363,7 @@ export default function App() {
|
||||
UseHyphenBullets={Settings ? Settings.UseHyphenBullets : true}
|
||||
UseAsciiFolderIcons={Settings ? Settings.UseAsciiFolderIcons : true}
|
||||
ConfirmBeforeDelete={ConfirmBeforeDelete}
|
||||
IsGuest={IsGuest}
|
||||
/>
|
||||
) : (
|
||||
<PreviewPane
|
||||
@@ -350,6 +374,7 @@ export default function App() {
|
||||
ShowGitBlame={Settings ? Settings.ShowGitBlame : false}
|
||||
ShowBlameAvatars={Settings ? Settings.ShowBlameAvatars : false}
|
||||
StickyToolbar={Settings ? Settings.StickyToolbar : true}
|
||||
IsGuest={IsGuest}
|
||||
/>
|
||||
)}
|
||||
{!ViewIsDirectory && !ViewNoteFilePath && (
|
||||
|
||||
Reference in new issue
Block a user