Skip to content

Commit

Permalink
feat: gnod the original post (#102)
Browse files Browse the repository at this point in the history
* feat: gnod on original post
* chore: reposting main post

---------

Signed-off-by: Iuri Pereira <[email protected]>
  • Loading branch information
iuricmp authored Jun 19, 2024
1 parent 0fa7d9a commit 86d04c0
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 13 deletions.
1 change: 0 additions & 1 deletion mobile/app/home/feed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { selectAccount, setPostToReply, useAppDispatch, useAppSelector } from "@
import Alert from "@gno/components/alert";
import { FeedView } from "@gno/components/view";
import { useGnoNativeContext } from "@gnolang/gnonative";
import base64 from "base-64";

export default function Page() {
const [totalPosts, setTotalPosts] = useState(0);
Expand Down
20 changes: 16 additions & 4 deletions mobile/components/feed/gnod-label.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,29 @@ import { colors } from "@gno/styles/colors";
import { MaterialCommunityIcons } from "@expo/vector-icons";
import Text from "../text";
import Icons from "../icons";
import { Post } from "@gno/types";

interface Props {
gnodsCount: number;
onPress?: () => void;
onGnod: (post: Post) => void;
post: Post;
style?: StyleProp<TextStyle> | undefined;
}

function GnodLabel({ gnodsCount, style, onPress }: Props) {
function GnodLabel({ post, style, onGnod }: Props) {
const isRepost = Boolean(post && post.parent_id > 0);
const gnodsCount = isRepost ? post.parent_post?.n_gnods : post.n_gnods;

const onPress = () => {
if (post.parent_post) {
onGnod(post.parent_post);
} else {
onGnod(post);
}
};

return (
<TouchableOpacity onPress={onPress} style={[style, { flexDirection: "row", gap: 4 }]}>
{gnodsCount > 0 ? <Icons.Gnoded /> : <Icons.Gnod />}
{gnodsCount && gnodsCount > 0 ? <Icons.Gnoded /> : <Icons.Gnod />}
<Text.Caption1 style={{ color: colors.text.secondary, marginTop: 2 }}>{gnodsCount} Gnods</Text.Caption1>
</TouchableOpacity>
);
Expand Down
19 changes: 13 additions & 6 deletions mobile/components/feed/repost-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,25 @@ import { StyleProp, TextStyle, TouchableOpacity } from "react-native";
import { colors } from "@gno/styles/colors";
import { MaterialCommunityIcons } from "@expo/vector-icons";
import Text from "../text";
import { Post } from "@gno/types";

interface Props {
style?: StyleProp<TextStyle> | undefined;
onPressRepost?: () => void;
onPressRepost: (post: Post) => void;
post: Post;
}

function RepostButton({ style, onPressRepost }: Props) {
function RepostButton({ style, onPressRepost, post }: Props) {
const onPress = () => {
if (post.parent_post) {
onPressRepost(post.parent_post);
} else {
onPressRepost(post);
}
};

return (
<TouchableOpacity
onPress={onPressRepost}
style={[style, { flexDirection: "row", paddingHorizontal: 12, alignItems: "center" }]}
>
<TouchableOpacity onPress={onPress} style={[style, { flexDirection: "row", paddingHorizontal: 12, alignItems: "center" }]}>
<MaterialCommunityIcons name="arrow-u-left-top" size={16} color={colors.text.secondary} />
<Text.Caption1 style={{ color: colors.text.secondary }}>Repost</Text.Caption1>
</TouchableOpacity>
Expand Down
4 changes: 2 additions & 2 deletions mobile/components/feed/tweet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ export function Tweet({ post, onPress = func, onGnod = func, showFooter = true }
</View>
{showFooter ? (
<View style={[styles.footer]}>
<GnodLabel style={styles.reply} gnodsCount={post.n_gnods} onPress={() => onGnod(post)} />
<RepostButton style={styles.reply} onPressRepost={() => onPressRepost(post)} />
<GnodLabel style={styles.reply} post={post} onGnod={onGnod} />
<RepostButton style={styles.reply} post={post} onPressRepost={onPressRepost} />
<RepliesLabel replyCount={post.n_replies} style={styles.reply} />
</View>
) : null}
Expand Down

0 comments on commit 86d04c0

Please sign in to comment.