Skip to content

Commit

Permalink
progress
Browse files Browse the repository at this point in the history
  • Loading branch information
gkasdorf committed Oct 15, 2023
1 parent d60af21 commit 251d1f9
Show file tree
Hide file tree
Showing 19 changed files with 94 additions and 26 deletions.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/components/Common/PostCard/PostDownvoteButton.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useCallback } from 'react';
import instance from '@api/Instance';
import instance from '@src/Instance';
import { usePostMyVote } from '@src/state/post/postStore';
import AnimatedIconButton from '@components/Common/Button/AnimatedIconButton';
import { ArrowDown } from '@tamagui/lucide-icons';
Expand Down
2 changes: 1 addition & 1 deletion src/components/Common/PostCard/PostUpvoteButton.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useCallback } from 'react';
import instance from '@api/Instance';
import instance from '@src/Instance';
import { usePostMyVote } from '@src/state/post/postStore';
import AnimatedIconButton from '@components/Common/Button/AnimatedIconButton';
import { ArrowUp } from '@tamagui/lucide-icons';
Expand Down
20 changes: 16 additions & 4 deletions src/components/Common/SwipeableRow/LeftOptions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ import { StyleSheet } from 'react-native';
import { playHaptic } from '@helpers/haptics';
import { SwipeableActionParams } from '@components/Common/SwipeableRow/actions';
import { useSwipeableRow } from '@components/Common/SwipeableRow/SwipeableRowProvider';
import { UsePostSwipeOptions } from '@components/Common/SwipeableRow/hooks/usePostSwipeOptions';
import { IconMap, IconType } from '@src/types/IconMap';
import { styled } from 'tamagui';
import { ISwipeableOptions } from '@components/Common/SwipeableRow/types';

type Stops = [first: number, second: number];
const DEFAULT_STOPS: Stops = [75, 150];
const [firstStop, secondStop] = DEFAULT_STOPS;

interface Props {
options: UsePostSwipeOptions;
options: ISwipeableOptions;
flipFlop?: boolean;
actionParams: SwipeableActionParams;
}
Expand All @@ -47,6 +47,18 @@ export function LeftOptions({

const [icon, setIcon] = useState<IconType | undefined>(icons.first);

// We need to do this because functions passed from a worklet using runOnJS are converted to objects
const runAction = useCallback(
(actionType: 'first' | 'second') => {
if (actionType === 'first' && actions.first != null) {
actions.first(actionParams);
} else if (actionType === 'second' && actions.second != null) {
actions.second(actionParams);
}
},
[options.actions],
);

const RenderIcon = useMemo(
() =>
icon != null
Expand Down Expand Up @@ -75,12 +87,12 @@ export function LeftOptions({
if (translateX.value >= secondStop) {
if (actions.second == null) return;

runOnJS(actions.second)(actionParams);
runOnJS(runAction)('second');
runOnJS(resetIcon)();
} else if (translateX.value >= firstStop) {
if (actions.first == null) return;

runOnJS(actions.first)(actionParams);
runOnJS(runAction)('first');
runOnJS(resetIcon)();
}
isFrozen.value = true;
Expand Down
21 changes: 17 additions & 4 deletions src/components/Common/SwipeableRow/RightOptions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ import { playHaptic } from '@helpers/haptics';
import { IconMap, IconType } from '@src/types/IconMap';
import { styled } from 'tamagui';
import { SwipeableActionParams } from '@components/Common/SwipeableRow/actions';
import { UsePostSwipeOptions } from '@components/Common/SwipeableRow/hooks/usePostSwipeOptions';
import { ISwipeableOptions } from '@components/Common/SwipeableRow/types';

type Stops = [first: number, second: number];
const DEFAULT_STOPS: Stops = [-75, -150];
const [firstStop, secondStop] = DEFAULT_STOPS;
const SCREEN_WIDTH = Dimensions.get('screen').width;

interface Props {
options: UsePostSwipeOptions;
options: ISwipeableOptions;
flipFlop?: boolean;
actionParams: SwipeableActionParams;
}
Expand All @@ -48,6 +48,18 @@ export function RightOptions({

const [icon, setIcon] = useState<IconType | undefined>(icons.first);

// We need to do this because functions passed from a worklet using runOnJS are converted to objects
const runAction = useCallback(
(actionType: 'first' | 'second') => {
if (actionType === 'first' && actions.first != null) {
actions.first(actionParams);
} else if (actionType === 'second' && actions.second != null) {
actions.second(actionParams);
}
},
[options.actions],
);

const RenderIcon = useMemo(
() =>
icon != null
Expand Down Expand Up @@ -76,12 +88,13 @@ export function RightOptions({
if (translateX.value <= secondStop) {
if (actions.second == null) return;

runOnJS(actions.second)(actionParams);
// runOnJS(actions.second)(actionParams);
runOnJS(runAction)('second');
runOnJS(resetIcon)();
} else if (translateX.value <= firstStop) {
if (actions.first == null) return;

runOnJS(actions.first)(actionParams);
runOnJS(runAction)('first');
runOnJS(resetIcon)();
}
isFrozen.value = true;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SwipeableActionParams } from '@components/Common/SwipeableRow/actions/swipeableActions';
import instance from '@api/Instance';
import instance from '@src/Instance';
import { playHaptic } from '@helpers/haptics';

export const downvoteCommentOption = ({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import instance from '@api/Instance';
import instance from '@src/Instance';
import { SwipeableActionParams } from '@components/Common/SwipeableRow/actions/swipeableActions';
import { playHaptic } from '@helpers/haptics';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SwipeableActionParams } from '@components/Common/SwipeableRow/actions/swipeableActions';
import instance from '@api/Instance';
import instance from '@src/Instance';
import { playHaptic } from '@helpers/haptics';

export const upvoteCommentOption = ({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import instance from '@api/Instance';
import instance from '@src/Instance';
import { SwipeableActionParams } from '@components/Common/SwipeableRow/actions/swipeableActions';
import { playHaptic } from '@helpers/haptics';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useCallback, useMemo, useState } from 'react';
import { useCommunitySubscribed } from '@src/state/community/communityStore';
import instance from '@api/Instance';
import instance from '@src/Instance';
import { isSubscribed } from '@helpers/lemmy';
import HStack from '@components/Common/Stack/HStack';
import ButtonOne from '@components/Common/Button/ButtonOne';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import CommunityTitle from '@components/Feed/components/Community/CommunityTitle
import { useNavigation, useRoute } from '@react-navigation/core';
import { useLoadData } from '@hooks/useLoadData';
import { GetCommunityResponse } from 'lemmy-js-client';
import instance from '@api/Instance';
import instance from '@src/Instance';
import { Spinner } from 'tamagui';
import {
useCommunityBanner,
Expand Down
9 changes: 4 additions & 5 deletions src/components/Feed/components/Feed/FeedItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,12 @@ function FeedItem({ itemId }: IProps): React.JSX.Element {
});
}, [itemId]);

const actionParams = useMemo(
() => ({
const actionParams = useMemo(() => {
return {
postId: itemId,
navigation,
}),
[itemId],
);
};
}, [itemId, navigation]);

return (
<Pressable onPress={onPress} style={styles.pressable}>
Expand Down
2 changes: 1 addition & 1 deletion src/components/Feed/components/MainFeed.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useCallback, useEffect, useMemo } from 'react';
import instance from '@api/Instance';
import instance from '@src/Instance';
import VStack from '@components/Common/Stack/VStack';
import { useRoute } from '@react-navigation/core';
import { useFeedNextPage, useFeedPostIds } from '@src/state/feed/feedStore';
Expand Down
2 changes: 1 addition & 1 deletion src/components/Feed/screens/FeedIndexScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useEffect, useRef, useState } from 'react';
import { useCurrentAccount } from '@src/state/account/accountStore';
import { IAccount } from '@src/types';
import instance from '@api/Instance';
import instance from '@src/Instance';
import LoadingScreen from '@components/Common/Loading/LoadingScreen';
import { Alert } from 'react-native';
import MainFeed from '@components/Feed/components/MainFeed';
Expand Down
12 changes: 12 additions & 0 deletions src/components/Navigation/MainScreens.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import FeedIndexScreen from '@components/Feed/screens/FeedIndexScreen';
import PostScreen from '@components/Post/screens/PostScreen';
import MainFeed from '@components/Feed/components/MainFeed';
import CommentChainScreen from '@components/Comment/screens/CommentChainScreen';
import ReplyScreen from '@components/Reply/screens/ReplyScreen';

export default function MainScreens(
stack: TypedNavigator<
Expand Down Expand Up @@ -63,6 +64,17 @@ export default function MainScreens(
}}
/>
</stack.Group>
<stack.Group
screenOptions={{
presentation: 'modal',
}}
>
<stack.Screen
name="Reply"
component={ReplyScreen}
options={{ headerShown: true }}
/>
</stack.Group>
</>
);
}
2 changes: 1 addition & 1 deletion src/components/Post/screens/PostScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
import LoadingScreen from '@components/Common/Loading/LoadingScreen';
import VStack from '@components/Common/Stack/VStack';
import Post from '@components/Post/components/Post';
import instance from '@api/Instance';
import instance from '@src/Instance';
import { ICommentInfo } from '@src/types';
import CommentChain from '@components/Comment/components/CommentChain';
import { FlatList } from 'react-native';
Expand Down
32 changes: 32 additions & 0 deletions src/components/Reply/screens/ReplyScreen.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import React, { useEffect } from 'react';
import { NativeStackNavigationProp } from '@react-navigation/native-stack';
import { usePostBody } from '@src/state/post/postStore';
import { useCommentContent } from '@src/state/comment/commentStore';
import { ScrollView, Text } from 'tamagui';

interface IProps {
navigation: NativeStackNavigationProp<any>;
route: any;
}

export default function ReplyScreen({
navigation,
route,
}: IProps): React.JSX.Element {
const { postId, commentId } = route.params;

const post = usePostBody(postId);
const comment = useCommentContent(commentId);

useEffect(() => {
navigation.setOptions({
headerTitle: comment != null ? 'Replying to Comment' : 'Replying to Post',
});
}, [post, comment]);

return (
<ScrollView flex={1}>
<Text>Hello!</Text>
</ScrollView>
);
}
2 changes: 1 addition & 1 deletion src/hooks/comments/useCommentVoting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
useCommentUpvotes,
} from '@src/state/comment/commentStore';
import { useCallback } from 'react';
import instance from '@api/Instance';
import instance from '@src/Instance';
import { playHaptic } from '@helpers/haptics';

interface UseCommentVoting {
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useLogin.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useState } from 'react';
import instance from '@api/Instance';
import instance from '@src/Instance';
import { addAccount } from '@src/state/account/actions';

interface DoLoginOptions {
Expand Down

0 comments on commit 251d1f9

Please sign in to comment.