mirror of
https://github.com/QwenLM/qwen-code.git
synced 2025-12-19 09:33:53 +00:00
Add guards
This commit is contained in:
@@ -41,7 +41,7 @@ export function ResumeSessionDialog({
|
||||
: 5;
|
||||
|
||||
const picker = useSessionPicker({
|
||||
sessionService: sessionServiceRef.current!,
|
||||
sessionService: sessionServiceRef.current,
|
||||
currentBranch,
|
||||
onSelect,
|
||||
onCancel,
|
||||
|
||||
@@ -23,7 +23,7 @@ export interface SessionState {
|
||||
}
|
||||
|
||||
export interface UseSessionPickerOptions {
|
||||
sessionService: SessionService;
|
||||
sessionService: SessionService | null;
|
||||
currentBranch?: string;
|
||||
onSelect: (sessionId: string) => void;
|
||||
onCancel: () => void;
|
||||
@@ -92,7 +92,9 @@ export function useSessionPicker({
|
||||
// Calculate scroll offset based on mode
|
||||
const scrollOffset = centerSelection
|
||||
? (() => {
|
||||
if (filteredSessions.length <= maxVisibleItems) return 0;
|
||||
if (filteredSessions.length <= maxVisibleItems) {
|
||||
return 0;
|
||||
}
|
||||
const halfVisible = Math.floor(maxVisibleItems / 2);
|
||||
let offset = selectedIndex - halfVisible;
|
||||
offset = Math.max(0, offset);
|
||||
@@ -111,6 +113,11 @@ export function useSessionPicker({
|
||||
|
||||
// Load initial sessions
|
||||
useEffect(() => {
|
||||
// Guard: don't load if sessionService is not ready
|
||||
if (!sessionService) {
|
||||
return;
|
||||
}
|
||||
|
||||
const loadInitialSessions = async () => {
|
||||
try {
|
||||
const result: ListSessionsResult = await sessionService.listSessions({
|
||||
@@ -130,7 +137,9 @@ export function useSessionPicker({
|
||||
|
||||
// Load more sessions
|
||||
const loadMoreSessions = useCallback(async () => {
|
||||
if (!sessionState.hasMore || isLoadingMoreRef.current) return;
|
||||
if (!sessionService || !sessionState.hasMore || isLoadingMoreRef.current) {
|
||||
return;
|
||||
}
|
||||
|
||||
isLoadingMoreRef.current = true;
|
||||
try {
|
||||
@@ -229,7 +238,9 @@ export function useSessionPicker({
|
||||
|
||||
// Navigation down
|
||||
if (key.downArrow || input === 'j') {
|
||||
if (filteredSessions.length === 0) return;
|
||||
if (filteredSessions.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
setSelectedIndex((prev) => {
|
||||
const newIndex = Math.min(filteredSessions.length - 1, prev + 1);
|
||||
|
||||
@@ -15,8 +15,12 @@ export const SESSION_PAGE_SIZE = 20;
|
||||
* Truncates text to fit within a given width, adding ellipsis if needed.
|
||||
*/
|
||||
export function truncateText(text: string, maxWidth: number): string {
|
||||
if (text.length <= maxWidth) return text;
|
||||
if (maxWidth <= 3) return text.slice(0, maxWidth);
|
||||
if (text.length <= maxWidth) {
|
||||
return text;
|
||||
}
|
||||
if (maxWidth <= 3) {
|
||||
return text.slice(0, maxWidth);
|
||||
}
|
||||
return text.slice(0, maxWidth - 3) + '...';
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user