feat: unauthenticated tab
This commit is contained in:
@@ -30,6 +30,7 @@ import { getArtistDisplayName } from '../../utils/artistName';
|
||||
import { Palette } from '../../styles';
|
||||
import { FONT_FAMILY } from '../../styles/Fonts';
|
||||
import ProfilePicture from '../ProfilePicture';
|
||||
import { ensureAuthenticated } from '../../utils/authRedirect';
|
||||
|
||||
let externalOpen;
|
||||
let externalClose;
|
||||
@@ -72,6 +73,16 @@ const CommentsBottomSheet = () => {
|
||||
const [text, setText] = useState('');
|
||||
const [typing, setTyping] = useState(false);
|
||||
|
||||
const requireAuth = useCallback(() => {
|
||||
return ensureAuthenticated(currentUID, {
|
||||
onIntercept: () => {
|
||||
try {
|
||||
modalRef.current?.dismiss?.();
|
||||
} catch (_error) {}
|
||||
},
|
||||
});
|
||||
}, [currentUID]);
|
||||
|
||||
useEffect(() => {
|
||||
externalOpen = (pid) => {
|
||||
setProjectId(pid || null);
|
||||
@@ -127,7 +138,8 @@ const CommentsBottomSheet = () => {
|
||||
|
||||
const onSend = async () => {
|
||||
const value = (text || '').trim();
|
||||
if (!value || !projectId || !currentUID) return;
|
||||
if (!value || !projectId) return;
|
||||
if (!requireAuth()) return;
|
||||
try {
|
||||
setText('');
|
||||
const docRef = await projectsRef
|
||||
@@ -354,11 +366,23 @@ const CommentsBottomSheet = () => {
|
||||
placeholderTextColor='#FFFFFFAA'
|
||||
value={text}
|
||||
onChangeText={(t) => {
|
||||
if (!currentUID && !requireAuth()) {
|
||||
return;
|
||||
}
|
||||
setText(t);
|
||||
}}
|
||||
onFocus={() => {
|
||||
if (!requireAuth()) {
|
||||
setTyping(false);
|
||||
return;
|
||||
}
|
||||
setTyping(true);
|
||||
}}
|
||||
onPressIn={() => {
|
||||
if (!requireAuth()) {
|
||||
setTyping(false);
|
||||
}
|
||||
}}
|
||||
onBlur={() => setTyping(false)}
|
||||
style={{
|
||||
flex: 1,
|
||||
|
||||
@@ -12,6 +12,7 @@ import useNavigateToMusicDetails from "../../hooks/useNavigateToMusicDetails";
|
||||
import { useUser } from "../../providers/UserDataProvider";
|
||||
import { gutters, Palette } from "../../styles";
|
||||
import { FONT_FAMILY } from "../../styles/Fonts";
|
||||
import { ensureAuthenticated } from "../../utils/authRedirect";
|
||||
|
||||
const formatDuration = (ms) => {
|
||||
const totalSeconds = Math.max(0, Math.floor((ms || 0) / 1000));
|
||||
@@ -82,22 +83,34 @@ const GlobalAudioPlayer = () => {
|
||||
}
|
||||
}, [pendingLike, likedFromDoc]);
|
||||
|
||||
const handleToggleLike = useCallback(async (event) => {
|
||||
event?.stopPropagation?.();
|
||||
if (!projectId || !currentUID || isLikeProcessing) return;
|
||||
const next = !effectiveIsLiked;
|
||||
setPendingLike(next);
|
||||
try {
|
||||
await projectsRef.doc(projectId).set(
|
||||
{
|
||||
likedBy: next ? arrayUnion(currentUID) : arrayRemove(currentUID),
|
||||
},
|
||||
{ merge: true }
|
||||
);
|
||||
} catch (_error) {
|
||||
setPendingLike(null);
|
||||
}
|
||||
}, [currentUID, effectiveIsLiked, isLikeProcessing, projectId]);
|
||||
const handleToggleLike = useCallback(
|
||||
async (event) => {
|
||||
event?.stopPropagation?.();
|
||||
if (!projectId || isLikeProcessing) return;
|
||||
if (
|
||||
!ensureAuthenticated(currentUID, {
|
||||
onIntercept: () => {
|
||||
setPendingLike(null);
|
||||
},
|
||||
})
|
||||
) {
|
||||
return;
|
||||
}
|
||||
const next = !effectiveIsLiked;
|
||||
setPendingLike(next);
|
||||
try {
|
||||
await projectsRef.doc(projectId).set(
|
||||
{
|
||||
likedBy: next ? arrayUnion(currentUID) : arrayRemove(currentUID),
|
||||
},
|
||||
{ merge: true }
|
||||
);
|
||||
} catch (_error) {
|
||||
setPendingLike(null);
|
||||
}
|
||||
},
|
||||
[currentUID, effectiveIsLiked, isLikeProcessing, projectId]
|
||||
);
|
||||
|
||||
const insets = useSafeAreaInsets();
|
||||
|
||||
@@ -199,11 +212,11 @@ const GlobalAudioPlayer = () => {
|
||||
<Pressable
|
||||
onPress={handleToggleLike}
|
||||
hitSlop={12}
|
||||
disabled={!projectId || !currentUID || isLikeProcessing}
|
||||
disabled={!projectId || isLikeProcessing}
|
||||
style={[
|
||||
styles.actionButton,
|
||||
styles.likeButton,
|
||||
(!projectId || !currentUID || isLikeProcessing) &&
|
||||
(!projectId || isLikeProcessing) &&
|
||||
styles.disabledAction,
|
||||
]}
|
||||
>
|
||||
|
||||
Reference in New Issue
Block a user