Skip to content

Commit

Permalink
fix profile response, mobile profile edit, new question ui
Browse files Browse the repository at this point in the history
  • Loading branch information
mmtftr committed Nov 25, 2024
1 parent 6b2d9c5 commit 6b8e7e7
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 32 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package com.group1.programminglanguagesforum.DTOs.Responses;

import com.group1.programminglanguagesforum.Entities.ExperienceLevel;
import lombok.*;

@Builder
Expand All @@ -19,4 +19,5 @@ public class SelfProfileResponseDto {
private int followersCount;
private int followingCount;
private int reputationPoints;
private ExperienceLevel experienceLevel;
}
4 changes: 2 additions & 2 deletions mobile/.expo/types/router.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ declare module 'expo-router' {
export namespace ExpoRouter {
export interface __routes<T extends string = string> extends Record<string, unknown> {
StaticRoutes: `/` | `/(tabs)` | `/(tabs)/` | `/(tabs)/profile` | `/(tabs)/search` | `/_sitemap` | `/home` | `/login` | `/logout` | `/profile` | `/question/new` | `/search` | `/signup`;
DynamicRoutes: `/question/${Router.SingleRoutePart<T>}` | `/tags/${Router.SingleRoutePart<T>}` | `/users/${Router.SingleRoutePart<T>}`;
DynamicRouteTemplate: `/question/[questionId]` | `/tags/[tagId]` | `/users/[userId]`;
DynamicRoutes: `/question/${Router.SingleRoutePart<T>}` | `/question/${Router.SingleRoutePart<T>}/answer` | `/tags/${Router.SingleRoutePart<T>}` | `/users/${Router.SingleRoutePart<T>}`;
DynamicRouteTemplate: `/question/[questionId]` | `/question/[questionId]/answer` | `/tags/[tagId]` | `/users/[userId]`;
}
}
}
44 changes: 41 additions & 3 deletions mobile/app/(tabs)/profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@ import {
Input,
InputField,
ScrollView,
Select,
SelectBackdrop,
SelectContent,
SelectDragIndicator,
SelectDragIndicatorWrapper,
SelectIcon,
SelectInput,
SelectItem,
SelectPortal,
SelectTrigger,
Text,
Textarea,
TextareaInput,
Expand All @@ -21,7 +31,7 @@ import {
} from "@/services/api/programmingForumComponents";
import useAuthStore from "@/services/auth";
import { Link } from "expo-router";
import { Plus } from "lucide-react-native";
import { ChevronDownIcon, Plus } from "lucide-react-native";
import { useEffect, useState } from "react";

export default function Profile() {
Expand All @@ -38,6 +48,8 @@ export function UserProfile({ userId }: { userId: string }) {

const [country, setCountry] = useState("");
const [bio, setBio] = useState("");
const [experienceLevel, setExperienceLevel] =
useState<ExperienceLevel>("BEGINNER");

useEffect(() => {
if (!me) {
Expand Down Expand Up @@ -72,6 +84,7 @@ export function UserProfile({ userId }: { userId: string }) {
if (data?.data) {
setCountry(data.data.country || "");
setBio(data.data.bio || "");
setExperienceLevel(data.data.experienceLevel || "BEGINNER");
}
}, [data?.data]);

Expand Down Expand Up @@ -146,6 +159,26 @@ export function UserProfile({ userId }: { userId: string }) {
placeholder="Bio"
/>
</Textarea>
<Select
selectedValue={experienceLevel}
onValueChange={setExperienceLevel}
>
<SelectTrigger variant="outline" size="md">
<SelectInput placeholder="Experience Level" />
<SelectIcon className="mr-3" as={ChevronDownIcon} />
</SelectTrigger>
<SelectPortal>
<SelectBackdrop />
<SelectContent>
<SelectDragIndicatorWrapper>
<SelectDragIndicator />
</SelectDragIndicatorWrapper>
<SelectItem label="Beginner" value="BEGINNER" />
<SelectItem label="Intermediate" value="INTERMEDIATE" />
<SelectItem label="Advanced" value="ADVANCED" />
</SelectContent>
</SelectPortal>
</Select>
</>
) : (
<>
Expand All @@ -155,6 +188,9 @@ export function UserProfile({ userId }: { userId: string }) {
>
{profile.bio ?? "Empty bio."}
</Text>
<Text>
Experience: {profile.experienceLevel?.toString() || "Unknown"}
</Text>
</>
)}

Expand All @@ -171,8 +207,10 @@ export function UserProfile({ userId }: { userId: string }) {
...profile,
country,
bio,
experienceLevel,
},
});
console.log(profile);
}}
>
<ButtonText>{isPending ? "Saving..." : "Save"}</ButtonText>
Expand All @@ -186,7 +224,7 @@ export function UserProfile({ userId }: { userId: string }) {
data?.data && <FollowButton profile={data?.data} />
)}
</VStack>

{/*
<HStack space="md">
<Button
variant={activeTab === "questions" ? "solid" : "outline"}
Expand All @@ -200,7 +238,7 @@ export function UserProfile({ userId }: { userId: string }) {
>
<ButtonText>Answers</ButtonText>
</Button>
</HStack>
</HStack> */}

{activeTab === "questions" ? (
<VStack space="md">
Expand Down
78 changes: 52 additions & 26 deletions mobile/app/question/new.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,33 @@
import { Input, InputField } from "@/components/ui/input";
import { FullscreenLoading } from "@/components/FullscreenLoading";
import ErrorAlert from "@/components/ErrorAlert";
import { useCreateQuestion, useSearchTags } from "@/services/api/programmingForumComponents";
import { useLocalSearchParams, useRouter } from "expo-router";
import useAuthStore from "@/services/auth";
import { useState } from "react";
import { FullscreenLoading } from "@/components/FullscreenLoading";
import {
Button,
ButtonText,
HStack,
Text,
View,
VStack,
Icon,
ScrollView,
Text,
Textarea,
TextareaInput,
View,
VStack,
} from "@/components/ui";
import { Input, InputField } from "@/components/ui/input";
import {
useCreateQuestion,
useSearchTags,
} from "@/services/api/programmingForumComponents";
import {
DifficultyLevel,
EASY,
HARD,
MEDIUM,
TagSummary,
} from "@/services/api/programmingForumSchemas";
import useAuthStore from "@/services/auth";
import { useLocalSearchParams, useRouter } from "expo-router";
import { X } from "lucide-react-native";
import { EASY, MEDIUM, HARD, DifficultyLevel, TagSummary } from "@/services/api/programmingForumSchemas";
import { useState } from "react";

export default function NewQuestionPage() {
const { tagId } = useLocalSearchParams<{ tagId: string }>();
Expand Down Expand Up @@ -46,7 +56,11 @@ export default function NewQuestionPage() {
);
}

const { data: searchResult, isLoading, error: searchError } = useSearchTags(
const {
data: searchResult,
isLoading,
error: searchError,
} = useSearchTags(
{
queryParams: { q: searchQuery },
},
Expand Down Expand Up @@ -80,10 +94,20 @@ export default function NewQuestionPage() {
console.log("Title:", title);
console.log("Content:", content);
console.log("Difficulty:", difficulty);
console.log("Selected Tags:", selectedTags.map((tag) => tag.name));
console.log(
"Selected Tags:",
selectedTags.map((tag) => tag.name)
);

await createQuestion({
body: { title, content, difficulty, tagIds: selectedTags.map((tag) => tag.id).filter((id): id is number => id !== undefined) },
body: {
title,
content,
difficulty,
tagIds: selectedTags
.map((tag) => tag.id)
.filter((id): id is number => id !== undefined),
},
});
alert("Question created successfully!");
router.push(`/tags/${tagId}`);
Expand All @@ -97,12 +121,14 @@ export default function NewQuestionPage() {
}

return (
<View style={{ padding: 32, flex: 1, marginVertical: 16 }}>
<ScrollView style={{ padding: 32, flex: 1, marginVertical: 16 }}>
<VStack style={{ gap: 16, flex: 1 }}>
<Text style={{ fontSize: 24, fontWeight: "bold" }}>Create New Question</Text>

<Text style={{ fontSize: 24, fontWeight: "bold" }}>
Create New Question
</Text>

{error && <ErrorAlert error={error} />}

{/* Title Input */}
<VStack style={{ gap: 8 }}>
<Text style={{ fontSize: 16 }}>Title</Text>
Expand Down Expand Up @@ -135,7 +161,7 @@ export default function NewQuestionPage() {
{contentLength} characters
</Text>
</VStack>

{searchError && <ErrorAlert error={searchError} />}

{/* Tag Search Input */}
Expand All @@ -154,11 +180,11 @@ export default function NewQuestionPage() {

{/* Display selected tags */}
<Text style={{ fontSize: 16 }}>
{selectedTags.length > 0
? `Selected tags:`
: "No tags selected"}
{selectedTags.length > 0 ? `Selected tags:` : "No tags selected"}
</Text>
<View style={{ flexDirection: "row", flexWrap: "wrap", marginVertical: 8 }}>
<View
style={{ flexDirection: "row", flexWrap: "wrap", marginVertical: 8 }}
>
{selectedTags.map((tag) => (
<HStack
key={tag.name}
Expand All @@ -183,7 +209,7 @@ export default function NewQuestionPage() {
</View>

{/* Tag List */}
{ (
{
<View style={{ marginVertical: 8 }}>
<Text style={{ fontSize: 16 }}>Matching Tags</Text>
<VStack style={{ gap: 8 }}>
Expand All @@ -198,7 +224,7 @@ export default function NewQuestionPage() {
))}
</VStack>
</View>
)}
}

{/* Difficulty Selector */}
<VStack style={{ gap: 8 }}>
Expand Down Expand Up @@ -234,6 +260,6 @@ export default function NewQuestionPage() {
</Button>
</HStack>
</VStack>
</View>
</ScrollView>
);
}
}

0 comments on commit 6b8e7e7

Please sign in to comment.