feat: enhance document loading and state management in doc-content component
- Introduced a loading state (`loadingChunks`) to manage document chunk loading more effectively. - Updated the scroll handling logic to prevent multiple requests while loading chunks. - Adjusted the pagination logic to ensure correct page increments based on the total document count. This update improves the user experience by ensuring smoother document loading and better state management during scrolling interactions.
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
package types
|
||||
|
||||
import "context"
|
||||
|
||||
// TenantIDFromContext extracts the tenant ID from ctx.
|
||||
// Returns (0, false) when the key is absent or the value is not uint64.
|
||||
func TenantIDFromContext(ctx context.Context) (uint64, bool) {
|
||||
v, ok := ctx.Value(TenantIDContextKey).(uint64)
|
||||
return v, ok
|
||||
}
|
||||
|
||||
// MustTenantIDFromContext extracts the tenant ID from ctx, panicking if missing.
|
||||
func MustTenantIDFromContext(ctx context.Context) uint64 {
|
||||
v, ok := TenantIDFromContext(ctx)
|
||||
if !ok {
|
||||
panic("types.TenantIDContextKey not set in context")
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// TenantInfoFromContext extracts the *Tenant from ctx.
|
||||
func TenantInfoFromContext(ctx context.Context) (*Tenant, bool) {
|
||||
v, ok := ctx.Value(TenantInfoContextKey).(*Tenant)
|
||||
return v, ok && v != nil
|
||||
}
|
||||
|
||||
// RequestIDFromContext extracts the request ID string from ctx.
|
||||
func RequestIDFromContext(ctx context.Context) (string, bool) {
|
||||
v, ok := ctx.Value(RequestIDContextKey).(string)
|
||||
return v, ok && v != ""
|
||||
}
|
||||
|
||||
// UserIDFromContext extracts the user ID string from ctx.
|
||||
func UserIDFromContext(ctx context.Context) (string, bool) {
|
||||
v, ok := ctx.Value(UserIDContextKey).(string)
|
||||
return v, ok && v != ""
|
||||
}
|
||||
|
||||
// SessionTenantIDFromContext extracts the session-owner tenant ID from ctx.
|
||||
// Falls back to TenantIDFromContext when the session key is absent.
|
||||
func SessionTenantIDFromContext(ctx context.Context) (uint64, bool) {
|
||||
v, ok := ctx.Value(SessionTenantIDContextKey).(uint64)
|
||||
if ok && v != 0 {
|
||||
return v, true
|
||||
}
|
||||
return TenantIDFromContext(ctx)
|
||||
}
|
||||
Reference in New Issue
Block a user