Skip to content

Commit

Permalink
progress
Browse files Browse the repository at this point in the history
  • Loading branch information
ddusichka committed Dec 4, 2024
1 parent 3045234 commit 1b5227a
Show file tree
Hide file tree
Showing 5 changed files with 306 additions and 304 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package reviews

import (
"github.com/gofiber/fiber/v2"
)

func (h *Handler) GetUserFollowingReviewsOfMedia(c *fiber.Ctx) error {

userId := c.Params("userId")
mediaId := c.Params("mediaId")
typeString := c.Query("media_type")

review, _ := h.reviewRepository.GetUserFollowingReviewsOfMedia(c.Context(), typeString, mediaId, userId)

return c.Status(fiber.StatusOK).JSON(review)
}
358 changes: 179 additions & 179 deletions frontend/app/CreateReview.tsx
Original file line number Diff line number Diff line change
@@ -1,179 +1,179 @@
import React, { useState, useEffect } from "react";
import {
View,
TextInput,
ScrollView,
StyleSheet,
TouchableWithoutFeedback,
Keyboard,
KeyboardAvoidingView,
Platform,
} from "react-native";
import axios from "axios";
import { useLocalSearchParams } from "expo-router";
import HeaderComponent from "@/components/HeaderComponent";
import DraftButton from "@/components/DraftButton";
import PublishButton from "@/components/PublishButton";
import { usePublishReview } from "@/hooks/usePublishReview";
import TagSelector from "@/components/media/TagSelector";
import Divider from "@/components/Divider";
import NudgePage from "@/components/NudgePage";
import MediaCard from "@/components/media/MediaCard";
import { useAuthContext } from "@/components/AuthProvider";

const CreateReview = () => {
const { mediaType, mediaId, rating } = useLocalSearchParams<{
mediaType: string;
mediaId: string;
rating: string;
}>();
const userId = useAuthContext().userId;
const BASE_URL = process.env.EXPO_PUBLIC_BASE_URL;

const [media, setMedia] = useState<Media>();
const [title, setTitle] = useState("");
const [comment, setComment] = useState("");

const [selectedTags, setSelectedTags] = useState<string[]>([]);
const [showNudges, setShowNudges] = useState(false);

const { publishReview } = usePublishReview();

const handleTagSelect = (tag: string) => {
if (selectedTags.includes(tag)) {
const newTags = selectedTags.filter((selectedTag) => selectedTag !== tag);
setSelectedTags(newTags);
} else {
setSelectedTags([...selectedTags, tag]);
}
};

const handleSubmit = (draft: boolean) => {
const request = {
user_id: userId,
media_type: mediaType,
media_id: parseInt(mediaId),
rating: parseInt(rating),
tags: selectedTags,
title,
comment,
draft,
};
publishReview(request);
if (!draft) {
setShowNudges(true);
}
};

useEffect(() => {
axios
.get(`${BASE_URL}/media/${mediaType}/${mediaId}`)
.then((response) => setMedia(response.data))
.catch((error) => console.error(error));
}, []);

return (
media && (
<TouchableWithoutFeedback onPress={Keyboard.dismiss}>
<View style={styles.container}>
<KeyboardAvoidingView
behavior={Platform.OS === "ios" ? "padding" : "height"}
style={styles.keyboardAvoidingView}
keyboardVerticalOffset={Platform.OS === "ios" ? 64 : 0} // Adjust this value as needed
>
<HeaderComponent title="Log Song" centered />
<View style={styles.inner}>
<ScrollView keyboardShouldPersistTaps="handled">
<MediaCard
media={media}
showTopBar={false}
showRateButton={false}
/>
<View style={styles.scrollview}>
<View>
<TextInput
style={styles.titleInput}
multiline={true}
placeholderTextColor="#434343"
placeholder="Add a title..."
value={title}
onChangeText={setTitle}
/>
</View>
<TextInput
style={styles.textInput}
multiline={true}
placeholderTextColor="#434343"
placeholder="What do you want to talk about?"
value={comment}
onChangeText={setComment}
/>
<Divider />
<TagSelector
tags={selectedTags}
handleTagSelect={handleTagSelect}
/>
<View style={styles.buttonContainer}>
<DraftButton handleClick={() => handleSubmit(true)} />
<PublishButton handleClick={() => handleSubmit(false)} />
</View>
</View>
</ScrollView>
{showNudges && (
<NudgePage
media_type={mediaType}
media_id={mediaId}
title={media.title}
artist_name={media.artist_name}
cover={media.cover}
/>
)}
</View>
</KeyboardAvoidingView>
</View>
</TouchableWithoutFeedback>
)
);
};

const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: "#ffffff",
},
inner: {
flex: 1,
paddingTop: 20,
},
scrollview: {
flexGrow: 1,
paddingTop: 24,
paddingHorizontal: 16,
},
keyboardAvoidingView: {
flex: 1,
},
buttonContainer: {
flexDirection: "row",
justifyContent: "space-between",
paddingBottom: 30,
paddingTop: 15,
},
titleInput: {
backgroundColor: "#ffffff",
color: "#434343",
fontWeight: "bold",
fontSize: 16,
},
textInput: {
height: 80,
backgroundColor: "#ffffff",
fontFamily: "Roboto",
color: "#434343",
fontSize: 16,
textAlignVertical: "top",
justifyContent: "flex-end",
},
});

export default CreateReview;
import React, { useState, useEffect } from "react";
import {
View,
TextInput,
ScrollView,
StyleSheet,
TouchableWithoutFeedback,
Keyboard,
KeyboardAvoidingView,
Platform,
} from "react-native";
import axios from "axios";
import { useLocalSearchParams } from "expo-router";
import HeaderComponent from "@/components/HeaderComponent";
import DraftButton from "@/components/DraftButton";
import PublishButton from "@/components/PublishButton";
import { usePublishReview } from "@/hooks/usePublishReview";
import TagSelector from "@/components/media/TagSelector";
import Divider from "@/components/Divider";
import NudgePage from "@/components/NudgePage";
import MediaCard from "@/components/media/MediaCard";
import { useAuthContext } from "@/components/AuthProvider";

const CreateReview = () => {
const { mediaType, mediaId, rating } = useLocalSearchParams<{
mediaType: string;
mediaId: string;
rating: string;
}>();
const userId = useAuthContext().userId;
const BASE_URL = process.env.EXPO_PUBLIC_BASE_URL;

const [media, setMedia] = useState<Media>();
const [title, setTitle] = useState("");
const [comment, setComment] = useState("");

const [selectedTags, setSelectedTags] = useState<string[]>([]);
const [showNudges, setShowNudges] = useState(false);

const { publishReview } = usePublishReview();

const handleTagSelect = (tag: string) => {
if (selectedTags.includes(tag)) {
const newTags = selectedTags.filter((selectedTag) => selectedTag !== tag);
setSelectedTags(newTags);
} else {
setSelectedTags([...selectedTags, tag]);
}
};

const handleSubmit = (draft: boolean) => {
const request = {
user_id: userId,
media_type: mediaType,
media_id: parseInt(mediaId),
rating: parseInt(rating),
tags: selectedTags,
title,
comment,
draft,
};
publishReview(request);
if (!draft) {
setShowNudges(true);
}
};

useEffect(() => {
axios
.get(`${BASE_URL}/media/${mediaType}/${mediaId}`)
.then((response) => setMedia(response.data))
.catch((error) => console.error(error));
}, []);

return (
media && (
<TouchableWithoutFeedback onPress={Keyboard.dismiss}>
<View style={styles.container}>
<KeyboardAvoidingView
behavior={Platform.OS === "ios" ? "padding" : "height"}
style={styles.keyboardAvoidingView}
keyboardVerticalOffset={Platform.OS === "ios" ? 64 : 0} // Adjust this value as needed
>
<HeaderComponent title="Log Song" centered />
<View style={styles.inner}>
<ScrollView keyboardShouldPersistTaps="handled">
<MediaCard
media={media}
showTopBar={false}
showRateButton={false}
/>
<View style={styles.scrollview}>
<View>
<TextInput
style={styles.titleInput}
multiline={true}
placeholderTextColor="#434343"
placeholder="Add a title..."
value={title}
onChangeText={setTitle}
/>
</View>
<TextInput
style={styles.textInput}
multiline={true}
placeholderTextColor="#434343"
placeholder="What do you want to talk about?"
value={comment}
onChangeText={setComment}
/>
<Divider />
<TagSelector
tags={selectedTags}
handleTagSelect={handleTagSelect}
/>
<View style={styles.buttonContainer}>
<DraftButton handleClick={() => handleSubmit(true)} />
<PublishButton handleClick={() => handleSubmit(false)} />
</View>
</View>
</ScrollView>
{showNudges && (
<NudgePage
media_type={mediaType}
media_id={mediaId}
title={media.title}
artist_name={media.artist_name}
cover={media.cover}
/>
)}
</View>
</KeyboardAvoidingView>
</View>
</TouchableWithoutFeedback>
)
);
};

const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: "#ffffff",
},
inner: {
flex: 1,
paddingTop: 20,
},
scrollview: {
flexGrow: 1,
paddingTop: 24,
paddingHorizontal: 16,
},
keyboardAvoidingView: {
flex: 1,
},
buttonContainer: {
flexDirection: "row",
justifyContent: "space-between",
paddingBottom: 30,
paddingTop: 15,
},
titleInput: {
backgroundColor: "#ffffff",
color: "#434343",
fontWeight: "bold",
fontSize: 16,
},
textInput: {
height: 80,
backgroundColor: "#ffffff",
fontFamily: "Roboto",
color: "#434343",
fontSize: 16,
textAlignVertical: "top",
justifyContent: "flex-end",
},
});

export default CreateReview;
Loading

0 comments on commit 1b5227a

Please sign in to comment.