Skip to content

Commit

Permalink
added toggles to user object and tracked state
Browse files Browse the repository at this point in the history
  • Loading branch information
Zorten committed Oct 24, 2024
1 parent 52ea8b5 commit b58a5bd
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 13 deletions.
7 changes: 4 additions & 3 deletions components/profile/settings/field.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import { Href, Link } from "expo-router";
import { View, Text } from "react-native";
import Icon from "@/components/Icon";

interface props {
field: string;
value: string;
icon: string;
link: Href<string>;
}

const Field = ({ field, value, link }: props) => {
const Field = ({ field, icon, link }: props) => {
return (
<Link href={link} className="flex flex-row items-center justify-center">
<View className="flex w-full flex-row justify-between py-4">
<Text className="text-lg">{field}</Text>
<Text className="text-lg text-beatdrop-profile-secondary">{value}</Text>
<Icon name={icon} size={24} />
</View>
</Link>
);
Expand Down
32 changes: 22 additions & 10 deletions components/profile/settings/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@ import { Switch } from "react-native-gesture-handler";
import { router } from "expo-router";

const Settings = () => {
const { email, dummyPassword, setAllUndefined } = useUser();

const [postActivity, setPostActivity] = useState(false);
const [friendPosts, setFriendPosts] = useState(true);
const [taggedPosts, setTaggedPosts] = useState(true);
const {
email,
postActivity,
friendPosts,
taggedPosts,
setAttribute,
setAllUndefined,
} = useUser();

const onSignOut = () => {
setAllUndefined();
Expand Down Expand Up @@ -44,8 +47,8 @@ const Settings = () => {
</View>
<View className="border-[0.5px] border-beatdrop-border" />
<Field
field="Password"
value={dummyPassword}
field="Change Password"
icon="Chevron_Right"
link="/profile/password"
/>
<View className="border-[0.5px] border-beatdrop-border" />
Expand All @@ -57,19 +60,28 @@ const Settings = () => {

<View className="my-4 flex flex-row items-center justify-between">
<Text className="text-lg"> Post Activity</Text>
<Switch value={postActivity} onValueChange={setPostActivity} />
<Switch
value={postActivity}
onValueChange={(value) => setAttribute("postActivity", value)}
/>
</View>
<View className="border-[0.5px] border-beatdrop-border" />

<View className="my-4 flex flex-row items-center justify-between">
<Text className="text-lg"> Friend Posts</Text>
<Switch value={friendPosts} onValueChange={setFriendPosts} />
<Switch
value={friendPosts}
onValueChange={(value) => setAttribute("friendPosts", value)}
/>
</View>
<View className="border-[0.5px] border-beatdrop-border" />

<View className="my-4 flex flex-row items-center justify-between">
<Text className="text-lg"> Tagged Posts</Text>
<Switch value={taggedPosts} onValueChange={setTaggedPosts} />
<Switch
value={taggedPosts}
onValueChange={(value) => setAttribute("taggedPosts", value)}
/>
</View>
<View className="border-[0.5px] border-beatdrop-border" />

Expand Down
2 changes: 2 additions & 0 deletions components/profile/settings/password.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ const Password = () => {
const onCurrentPasswordChange = (text: string) => {
if (text === dummyPassword) {
setHasEnteredCorrectPassword(true);
} else {
setHasEnteredCorrectPassword(false);
}
};

Expand Down
9 changes: 9 additions & 0 deletions hooks/useUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ interface User {
following: number;
email: string;
dummyPassword: string;
postActivity: boolean;
friendPosts: boolean;
taggedPosts: boolean;
setAttribute: (attribute: string, value: any) => void; // Updated to `any` to allow more flexible types
resetAttributes: () => void;
setAllUndefined: () => void;
Expand All @@ -34,6 +37,9 @@ const initialState: Omit<
following: 21,
email: "[email protected]",
dummyPassword: "password",
postActivity: true,
friendPosts: true,
taggedPosts: true,
};

export const useUser = create<User>()((set) => ({
Expand All @@ -60,5 +66,8 @@ export const useUser = create<User>()((set) => ({
following: undefined,
email: undefined,
dummyPassword: undefined,
postActivity: undefined,
friendPosts: undefined,
taggedPosts: undefined,
})),
}));

0 comments on commit b58a5bd

Please sign in to comment.