mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-04-25 00:36:31 +02:00
feat: no login experience and prem tokens
Some checks are pending
Build and Push Docker Images / tag_release (push) Waiting to run
Build and Push Docker Images / build (./surfsense_backend, ./surfsense_backend/Dockerfile, backend, surfsense-backend, ubuntu-24.04-arm, linux/arm64, arm64) (push) Blocked by required conditions
Build and Push Docker Images / build (./surfsense_backend, ./surfsense_backend/Dockerfile, backend, surfsense-backend, ubuntu-latest, linux/amd64, amd64) (push) Blocked by required conditions
Build and Push Docker Images / build (./surfsense_web, ./surfsense_web/Dockerfile, web, surfsense-web, ubuntu-24.04-arm, linux/arm64, arm64) (push) Blocked by required conditions
Build and Push Docker Images / build (./surfsense_web, ./surfsense_web/Dockerfile, web, surfsense-web, ubuntu-latest, linux/amd64, amd64) (push) Blocked by required conditions
Build and Push Docker Images / create_manifest (backend, surfsense-backend) (push) Blocked by required conditions
Build and Push Docker Images / create_manifest (web, surfsense-web) (push) Blocked by required conditions
Some checks are pending
Build and Push Docker Images / tag_release (push) Waiting to run
Build and Push Docker Images / build (./surfsense_backend, ./surfsense_backend/Dockerfile, backend, surfsense-backend, ubuntu-24.04-arm, linux/arm64, arm64) (push) Blocked by required conditions
Build and Push Docker Images / build (./surfsense_backend, ./surfsense_backend/Dockerfile, backend, surfsense-backend, ubuntu-latest, linux/amd64, amd64) (push) Blocked by required conditions
Build and Push Docker Images / build (./surfsense_web, ./surfsense_web/Dockerfile, web, surfsense-web, ubuntu-24.04-arm, linux/arm64, arm64) (push) Blocked by required conditions
Build and Push Docker Images / build (./surfsense_web, ./surfsense_web/Dockerfile, web, surfsense-web, ubuntu-latest, linux/amd64, amd64) (push) Blocked by required conditions
Build and Push Docker Images / create_manifest (backend, surfsense-backend) (push) Blocked by required conditions
Build and Push Docker Images / create_manifest (web, surfsense-web) (push) Blocked by required conditions
This commit is contained in:
parent
87452bb315
commit
ff4e0f9b62
68 changed files with 5914 additions and 121 deletions
74
surfsense_web/contexts/anonymous-mode.tsx
Normal file
74
surfsense_web/contexts/anonymous-mode.tsx
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
"use client";
|
||||
|
||||
import { createContext, type ReactNode, useContext, useEffect, useMemo, useState } from "react";
|
||||
import { anonymousChatApiService } from "@/lib/apis/anonymous-chat-api.service";
|
||||
|
||||
export interface AnonymousModeContextValue {
|
||||
isAnonymous: true;
|
||||
modelSlug: string;
|
||||
setModelSlug: (slug: string) => void;
|
||||
uploadedDoc: { filename: string; sizeBytes: number } | null;
|
||||
setUploadedDoc: (doc: { filename: string; sizeBytes: number } | null) => void;
|
||||
resetKey: number;
|
||||
resetChat: () => void;
|
||||
}
|
||||
|
||||
interface AuthenticatedContextValue {
|
||||
isAnonymous: false;
|
||||
}
|
||||
|
||||
type ContextValue = AnonymousModeContextValue | AuthenticatedContextValue;
|
||||
|
||||
const DEFAULT_VALUE: AuthenticatedContextValue = { isAnonymous: false };
|
||||
|
||||
const AnonymousModeContext = createContext<ContextValue>(DEFAULT_VALUE);
|
||||
|
||||
export function AnonymousModeProvider({
|
||||
initialModelSlug,
|
||||
children,
|
||||
}: {
|
||||
initialModelSlug: string;
|
||||
children: ReactNode;
|
||||
}) {
|
||||
const [modelSlug, setModelSlug] = useState(initialModelSlug);
|
||||
const [uploadedDoc, setUploadedDoc] = useState<{ filename: string; sizeBytes: number } | null>(
|
||||
null
|
||||
);
|
||||
const [resetKey, setResetKey] = useState(0);
|
||||
|
||||
const resetChat = () => setResetKey((k) => k + 1);
|
||||
|
||||
useEffect(() => {
|
||||
anonymousChatApiService
|
||||
.getDocument()
|
||||
.then((doc) => {
|
||||
if (doc) {
|
||||
setUploadedDoc({ filename: doc.filename, sizeBytes: doc.size_bytes });
|
||||
}
|
||||
})
|
||||
.catch(() => {});
|
||||
}, []);
|
||||
|
||||
const value = useMemo<AnonymousModeContextValue>(
|
||||
() => ({
|
||||
isAnonymous: true,
|
||||
modelSlug,
|
||||
setModelSlug,
|
||||
uploadedDoc,
|
||||
setUploadedDoc,
|
||||
resetKey,
|
||||
resetChat,
|
||||
}),
|
||||
[modelSlug, uploadedDoc, resetKey]
|
||||
);
|
||||
|
||||
return <AnonymousModeContext.Provider value={value}>{children}</AnonymousModeContext.Provider>;
|
||||
}
|
||||
|
||||
export function useAnonymousMode(): ContextValue {
|
||||
return useContext(AnonymousModeContext);
|
||||
}
|
||||
|
||||
export function useIsAnonymous(): boolean {
|
||||
return useContext(AnonymousModeContext).isAnonymous;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue