Commit 16633fca authored by Malsha Rathnasiri's avatar Malsha Rathnasiri

fix issues mobile app

parent 7c5f12fd
...@@ -165,7 +165,7 @@ export default function ChatScreen({ navigation }) { ...@@ -165,7 +165,7 @@ export default function ChatScreen({ navigation }) {
useEffect(() => { useEffect(() => {
const interval = setInterval(() => { const interval = setInterval(() => {
loadChats(); loadChats();
}, 1000); }, 2000);
return () => { return () => {
clearInterval(interval); clearInterval(interval);
}; };
...@@ -206,7 +206,7 @@ export default function ChatScreen({ navigation }) { ...@@ -206,7 +206,7 @@ export default function ChatScreen({ navigation }) {
}).then((response) => { }).then((response) => {
// console.log(response) // console.log(response)
}); });
setTimeout(() => {
addChats({ addChats({
message: item.A, message: item.A,
from_user: chatDetails.to_user, from_user: chatDetails.to_user,
...@@ -215,7 +215,6 @@ export default function ChatScreen({ navigation }) { ...@@ -215,7 +215,6 @@ export default function ChatScreen({ navigation }) {
}).then((response) => { }).then((response) => {
// console.log(response) // console.log(response)
}); });
}, 500);
setLoading(true); setLoading(true);
setInput(""); setInput("");
...@@ -282,11 +281,11 @@ export default function ChatScreen({ navigation }) { ...@@ -282,11 +281,11 @@ export default function ChatScreen({ navigation }) {
<EditScreenInfo path="/screens/TabOneScreen.tsx" /> */} <EditScreenInfo path="/screens/TabOneScreen.tsx" /> */}
<View style={{ flex: 1, width: "100%" }}> <View style={{ flex: 1, width: "100%", justifyContent: "space-between" }}>
<View <View
style={{ style={{
display: "flex", display: "flex",
flex: 0.9, flex: 1,
justifyContent: "space-between", justifyContent: "space-between",
}} }}
> >
...@@ -296,6 +295,7 @@ export default function ChatScreen({ navigation }) { ...@@ -296,6 +295,7 @@ export default function ChatScreen({ navigation }) {
<ActivityIndicator /> <ActivityIndicator />
) : ( ) : (
<SectionList <SectionList
style={{ flex: 1 }}
refreshing={loading} refreshing={loading}
onRefresh={() => { onRefresh={() => {
// loadChatDetails() //remove // loadChatDetails() //remove
...@@ -408,11 +408,18 @@ export default function ChatScreen({ navigation }) { ...@@ -408,11 +408,18 @@ export default function ChatScreen({ navigation }) {
) )
}} /> */} }} /> */}
</View> </View>
<View>
<Divider /> <Divider />
<View style={{ flex: 0.05, padding: 0, backgroundColor: "white" }}>
<View <View
style={{ flexDirection: "row", display: "flex", height: "100%" }} style={{
padding: 0,
backgroundColor: "white",
minHeight: 20,
justifyContent: "flex-end",
}}
> >
<View style={{ flexDirection: "row", display: "flex" }}>
<ScrollView horizontal={true}> <ScrollView horizontal={true}>
{QandAs.map((item) => ( {QandAs.map((item) => (
<TouchableOpacity <TouchableOpacity
...@@ -426,6 +433,7 @@ export default function ChatScreen({ navigation }) { ...@@ -426,6 +433,7 @@ export default function ChatScreen({ navigation }) {
alignSelf: "center", alignSelf: "center",
padding: 5, padding: 5,
}} }}
key={item.Q}
> >
<Text <Text
style={{ justifyContent: "center", alignSelf: "center" }} style={{ justifyContent: "center", alignSelf: "center" }}
...@@ -438,10 +446,8 @@ export default function ChatScreen({ navigation }) { ...@@ -438,10 +446,8 @@ export default function ChatScreen({ navigation }) {
</View> </View>
</View> </View>
<Divider /> <Divider />
<View style={{ flex: 0.05, padding: 0, backgroundColor: "white" }}> <View style={{ padding: 0, backgroundColor: "white", minHeight: 30 }}>
<View <View style={{ flexDirection: "row", display: "flex" }}>
style={{ flexDirection: "row", display: "flex", height: "100%" }}
>
<SafeAreaView <SafeAreaView
style={{ style={{
flex: 0.8, flex: 0.8,
...@@ -465,12 +471,12 @@ export default function ChatScreen({ navigation }) { ...@@ -465,12 +471,12 @@ export default function ChatScreen({ navigation }) {
<View <View
style={{ style={{
flex: 0.2, flex: 0.2,
height: "100%", // height: "100%",
flexDirection: "column-reverse", flexDirection: "column-reverse",
}} }}
> >
<Button <Button
style={{ width: "100%", height: "100%" }} style={{ width: "100%" }}
title="Send" title="Send"
onPress={onSendPress} onPress={onSendPress}
/> />
...@@ -490,5 +496,6 @@ export default function ChatScreen({ navigation }) { ...@@ -490,5 +496,6 @@ export default function ChatScreen({ navigation }) {
</View> </View>
</View> </View>
</View> </View>
</View>
); );
} }
...@@ -13,6 +13,7 @@ export const styles = StyleSheet.create({ ...@@ -13,6 +13,7 @@ export const styles = StyleSheet.create({
container: { container: {
flex: 1, flex: 1,
backgroundColor: COLOR1, backgroundColor: COLOR1,
height: '100%'
}, },
loginContainer: { loginContainer: {
alignItems: 'center', alignItems: 'center',
......
...@@ -32,11 +32,12 @@ from pydub import AudioSegment ...@@ -32,11 +32,12 @@ from pydub import AudioSegment
import numpy as np import numpy as np
#Custom Viewset to get auth token # Custom Viewset to get auth token
class ObtainTokenPairWithUserView(TokenObtainPairView): class ObtainTokenPairWithUserView(TokenObtainPairView):
permission_classes = (permissions.AllowAny,) permission_classes = (permissions.AllowAny,)
serializer_class = MyTokenObtainPairSerializer serializer_class = MyTokenObtainPairSerializer
class UserViewSet(viewsets.ModelViewSet): class UserViewSet(viewsets.ModelViewSet):
""" """
API endpoint that allows users to be viewed or edited. API endpoint that allows users to be viewed or edited.
...@@ -71,7 +72,7 @@ class MlModelViewSet(viewsets.ViewSet): ...@@ -71,7 +72,7 @@ class MlModelViewSet(viewsets.ViewSet):
permission_classes = [permissions.AllowAny] permission_classes = [permissions.AllowAny]
parser_classes = [MultiPartParser] parser_classes = [MultiPartParser]
#Custom api to add sample chats # Custom api to add sample chats
@action(detail=False) @action(detail=False)
def addChats(*args, **kwargs): def addChats(*args, **kwargs):
admin = User.objects.get(username='admin') admin = User.objects.get(username='admin')
...@@ -107,7 +108,7 @@ class MlModelViewSet(viewsets.ViewSet): ...@@ -107,7 +108,7 @@ class MlModelViewSet(viewsets.ViewSet):
conversation=convo, from_user_id=chat['from'], to_user_id=chat['to'], messsage=chat['message']) conversation=convo, from_user_id=chat['from'], to_user_id=chat['to'], messsage=chat['message'])
object.save() object.save()
#Custom api to train the model # Custom api to train the model
@action(detail=False) @action(detail=False)
def train(*args, **kwargs): def train(*args, **kwargs):
print('Function ran') print('Function ran')
...@@ -115,7 +116,7 @@ class MlModelViewSet(viewsets.ViewSet): ...@@ -115,7 +116,7 @@ class MlModelViewSet(viewsets.ViewSet):
print(results) print(results)
return Response({'success': True}) return Response({'success': True})
#Custom api to convert audio to text # Custom api to convert audio to text
@action(detail=False, methods=["POST"]) @action(detail=False, methods=["POST"])
def detect(self, request, *args, **kwargs): def detect(self, request, *args, **kwargs):
print('Function ran') print('Function ran')
...@@ -151,12 +152,13 @@ class MlModelViewSet(viewsets.ViewSet): ...@@ -151,12 +152,13 @@ class MlModelViewSet(viewsets.ViewSet):
print(results) print(results)
return Response({'success': True, 'result': results}) return Response({'success': True, 'result': results})
class ChatViewSet(viewsets.ModelViewSet): class ChatViewSet(viewsets.ModelViewSet):
queryset = Chat.objects.all().order_by('-timestamp') queryset = Chat.objects.all().order_by('-timestamp')
serializer_class = ChatSerializer serializer_class = ChatSerializer
permission_classes = [permissions.IsAuthenticated] permission_classes = [permissions.IsAuthenticated]
#ovveride defualt list action to get chats of specific user conversation # ovveride defualt list action to get chats of specific user conversation
def list(self, request, pk=None): def list(self, request, pk=None):
if pk == None: if pk == None:
chats = Chat.objects \ chats = Chat.objects \
...@@ -193,15 +195,17 @@ class ChatViewSet(viewsets.ModelViewSet): ...@@ -193,15 +195,17 @@ class ChatViewSet(viewsets.ModelViewSet):
item = ChatSerializer(data=request.data) item = ChatSerializer(data=request.data)
# validating for already existing data # validating for already existing data
if Chat.objects.filter(**request.data).exists(): # if Chat.objects.filter(**request.data).exists():
raise serializers.ValidationError('This data already exists') # raise serializers.ValidationError('This data already exists')
print(item)
if item.is_valid(): if item.is_valid() or True:
item.save() item.save()
return Response(item.data) return Response(item.data)
else: else:
return Response(status=Status.HTTP_404_NOT_FOUND) return Response(status=Status.HTTP_404_NOT_FOUND)
class ConversationViewSet(viewsets.ModelViewSet): class ConversationViewSet(viewsets.ModelViewSet):
queryset = Conversation.objects.all().order_by('id') queryset = Conversation.objects.all().order_by('id')
serializer_class = ConversationSerializer serializer_class = ConversationSerializer
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment