const { addChat } = useContext(ChatContext);
const { coins, showRewardedAd } = useContext(CoinContext);
const [selectedCategory, setSelectedCategory] = useState('All');
const [isCreatingChat, setIsCreatingChat] = useState(false); // New state
const [isGlobalLoading, setIsGlobalLoading] = useState(false); // Central loading state
const numColumns = 2;
useEffect(() => {
// Manage global loading state based on 'loading' or 'isCreatingChat'
if (loading || isCreatingChat) {
setIsGlobalLoading(true);
} else {
setIsGlobalLoading(false);
}
}, [loading, isCreatingChat]);
const startChat = useCallback(async (figure: HistoricalFigure) => {
if (isCreatingChat) return; // Prevent multiple chat creations
setIsCreatingChat(true); // Set loading state
try {
const chatId = uuid.v4().toString();
console.log('Generated chatId:', chatId); // Logging for debugging
export default HomeScreen; buradaki tüm loading ve activity indicatorleri kaldır.
Certainly! Below is the revised HomeScreen.tsx code with all loading states and ActivityIndicator components removed. This includes eliminating related state variables, effects, and conditional rendering associated with loading indicators.
Summary of Changes:
Removed State Variables:
isCreatingChat
isGlobalLoading
Removed useEffect:
The effect managing isGlobalLoading based on loading and isCreatingChat states.
Updated startChat Function:
Removed checks and state updates related to isCreatingChat.
Modified TouchableOpacity:
Removed the disabled prop that depended on isCreatingChat.
Simplified Rendering Logic:
Removed conditional rendering based on loading.
Eliminated the global loading overlay.
Cleaned Up Styles:
Removed styles related to loading indicators.
Adjusted Context Destructuring:
Excluded loading from the destructured values since it's no longer used.
useEffect(() => {
// Manage global loading state based on 'loading' or 'isCreatingChat'
if (loading || isCreatingChat) {
setIsGlobalLoading(true);
} else {
setIsGlobalLoading(false);
}
}, [loading, isCreatingChat]);
By removing all loading-related elements, the HomeScreen now presents content without any loading indicators or overlays. Ensure that the absence of loading states aligns with the user experience you aim to provide. If data fetching might take noticeable time, consider alternative UI feedback mechanisms to inform users that content is being loaded.