-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from 2d-rpg/feature/room_list
ルーム作成・ルーム一覧/参加・websocketの実装
- Loading branch information
Showing
12 changed files
with
473 additions
and
236 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
declare module "@env"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
import React, { ReactElement } from "react"; | ||
import { | ||
StyleSheet, | ||
View, | ||
Text, | ||
Button, | ||
ScrollView, | ||
TextInput, | ||
} from "react-native"; | ||
import { StackNavigationProp } from "@react-navigation/stack"; | ||
import { RootStackParamList } from "../../../App"; | ||
import { gql, useMutation } from "@apollo/client"; | ||
import { Formik } from "formik"; | ||
import * as Yup from "yup"; | ||
import { ENDPOINT } from "@env"; | ||
|
||
const CREATE_ROOM = gql` | ||
mutation CreateRoom($name: String!, $player: String!) { | ||
createRoom(name: $name, player: $player) { | ||
id | ||
name | ||
players | ||
} | ||
} | ||
`; | ||
|
||
export default function CreateRoomScreen({ | ||
navigation, | ||
}: { | ||
navigation: CreateRoomScreenNavigationProp; | ||
}): ReactElement { | ||
const [createRoom] = useMutation(CREATE_ROOM, { | ||
onCompleted: (data) => { | ||
console.log(data.createRoom.id); | ||
navigation.navigate("Room", { id: data.createRoom.id }); // TODO | ||
}, | ||
}); | ||
|
||
const onSubmit = async (values: { name: string }) => { | ||
// データ送信 | ||
console.log(values); | ||
createRoom({ variables: { name: values.name, player: "piypiyo" } }); | ||
}; | ||
|
||
const schema = Yup.object().shape({ | ||
name: Yup.string() | ||
.min(3, "3文字以上で入力してください") | ||
.max(20, "20文字以内で入力してください") | ||
.required("ルーム名を入力してください"), | ||
}); | ||
return ( | ||
<ScrollView contentContainerStyle={styles.container}> | ||
<View> | ||
<Formik | ||
initialValues={{ | ||
name: "", | ||
}} | ||
validateOnMount | ||
validationSchema={schema} | ||
onSubmit={(values) => onSubmit(values)} | ||
> | ||
{({ | ||
handleSubmit, | ||
handleChange, | ||
handleBlur, | ||
isValid, | ||
isSubmitting, | ||
values, | ||
errors, | ||
touched, | ||
}) => ( | ||
<> | ||
<View> | ||
{errors.name && touched.name ? ( | ||
<Text>{errors.name}</Text> | ||
) : null} | ||
<TextInput | ||
value={values.name} | ||
onChangeText={handleChange("name")} | ||
onBlur={handleBlur("name")} | ||
placeholder="ルーム名を入力してください" | ||
/> | ||
</View> | ||
<Button | ||
title="Submit" | ||
onPress={() => handleSubmit()} | ||
disabled={!isValid || isSubmitting} | ||
/> | ||
</> | ||
)} | ||
</Formik> | ||
</View> | ||
</ScrollView> | ||
); | ||
} | ||
|
||
type CreateRoomScreenNavigationProp = StackNavigationProp< | ||
RootStackParamList, | ||
"CreateRoom" | ||
>; | ||
|
||
const styles = StyleSheet.create({ | ||
container: { | ||
flex: 1, | ||
backgroundColor: "#fff", | ||
alignItems: "center", | ||
justifyContent: "center", | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.