Skip to content

Commit

Permalink
Implemented a spectator system and resolved #10 and #9
Browse files Browse the repository at this point in the history
  • Loading branch information
big213 committed May 23, 2020
1 parent f9f0609 commit 48b7310
Show file tree
Hide file tree
Showing 13 changed files with 327 additions and 42 deletions.
6 changes: 3 additions & 3 deletions components/interface/viewCuberRoomsInterface.vue
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ export default {
}
},
async loadData() {
this.loading.loadData = true
//this.loading.loadData = true
try {
let { data } = await this.$apollo.query({
query: CUBER_ROOMS_QUERY,
Expand All @@ -294,11 +294,11 @@ export default {
} catch (err) {
sharedService.handleError(err, this.$root)
}
this.loading.loadData = false
//this.loading.loadData = false
},
reset(initialLoad = false) {
if (!this.status) return
if (!this.status || !this.cuber) return
if (initialLoad) this.options.initialLoad = true
this.loadData()
Expand Down
13 changes: 12 additions & 1 deletion components/popover/previewCuberPopover.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@
offset-x
>
<template v-slot:activator="{ on }">
<a v-if="selectedItem" v-on="on">
<v-chip v-if="chip && selectedItem" v-on="on">
<v-avatar left>
<v-img v-if="selectedItem.avatar" :src="selectedItem.avatar" />
<v-icon v-else>mdi-account</v-icon>
</v-avatar>
{{ selectedItem.name }}
</v-chip>
<a v-else-if="selectedItem" v-on="on">
<v-avatar size="24" class="mr-1">
<v-img v-if="selectedItem.avatar" :src="selectedItem.avatar" />
<v-icon v-else>mdi-account</v-icon>
Expand Down Expand Up @@ -91,6 +98,10 @@ import {
export default {
props: {
selectedItem: {},
chip: {
type: Boolean,
default: false,
},
},
data() {
return {
Expand Down
23 changes: 21 additions & 2 deletions gql/mutation/room.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,16 @@ export const DELETE_ROOM_MUTATION = gql`
`

export const JOIN_ROOM_MUTATION = gql`
mutation joinRoom($room_id: ID!, $secret: String) {
joinRoom(id: $room_id, secret: $secret) {
mutation joinRoom(
$room_id: ID!
$secret: String
$participationType: CuberRoomRelationTypeEnum
) {
joinRoom(
id: $room_id
secret: $secret
participationType: $participationType
) {
id
}
}
Expand Down Expand Up @@ -181,3 +189,14 @@ export const UPDATE_SOLVE_MUTATION = gql`
${solveFragment}
${cuberBasicFragment}
`

export const CHANGE_ROOM_STATUS_MUTATION = gql`
mutation changeRoomStatus(
$room_id: ID!
$participationType: CuberRoomRelationTypeEnum
) {
changeRoomStatus(room_id: $room_id, participationType: $participationType) {
id
}
}
`
11 changes: 11 additions & 0 deletions gql/query/room.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@ export const ROOM_QUERY = gql`
...CuberBasic
}
active_cubers(first: 10) {
data {
...CuberBasic
pivot {
type
}
}
}
spectating_cubers(first: 10) {
paginatorInfo {
total
}
data {
...CuberBasic
}
Expand Down
3 changes: 3 additions & 0 deletions gql/query/round.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ export const ROUNDS_QUERY = gql`
...Solve
cuber {
...CuberBasic
pivot {
type
}
}
}
accumulated_results {
Expand Down
40 changes: 38 additions & 2 deletions gql/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ type Cuber {
first: Int!
page: Int
): CuberPaginator
pivot: CuberRoomPivot
created_at: DateTime!
updated_at: DateTime
}
Expand All @@ -355,6 +356,20 @@ type CuberRoom {
room: Room!
}

type CuberRoomPivot {
type: CuberRoomRelationTypeEnum!
last_activity_at: DateTime!
cuber: Cuber!
room: Room!
}

enum CuberRoomRelationTypeEnum {
VISITED
PARTICIPATING
IDLING
SPECTATING
}

scalar Date

scalar DateTime
Expand Down Expand Up @@ -418,13 +433,20 @@ scalar Milliseconds
type Mutation {
sendRoomChatMessage(room_id: ID!, message: String!): RoomChatMessage!
updateCuber(input: UpdateCuberInput): Cuber!
idle: Cuber
followCuber(id: ID): Cuber
unfollowCuber(id: ID): Cuber
inviteCuber(room_id: ID!, cuber_id: ID!): CuberRoom!
createRoom(input: CreateRoomInput!): Room!
updateRoom(input: UpdateRoomInput!): Room!
joinRoom(id: ID!, secret: String): Room!
joinRoom(
id: ID!
secret: String
participationType: CuberRoomRelationTypeEnum
): Room!
changeRoomStatus(
room_id: ID!
participationType: CuberRoomRelationTypeEnum
): Room!
leaveRoom(id: ID!): Room!
deleteRoom(id: ID!): Room!
untrackSolvesFromRoom(room_id: ID!): [Solve!]
Expand Down Expand Up @@ -573,6 +595,18 @@ type Room {
first: Int!
page: Int
): CuberPaginator
participating_cubers(
first: Int!
page: Int
): CuberPaginator
idling_cubers(
first: Int!
page: Int
): CuberPaginator
spectating_cubers(
first: Int!
page: Int
): CuberPaginator
active_cubers(
first: Int!
page: Int
Expand All @@ -592,6 +626,7 @@ type Room {
is_full: Boolean!
creator: Cuber!
accumulators: [Accumulator!]
pivot: CuberRoomPivot
manager: Cuber
created_at: DateTime!
updated_at: DateTime
Expand Down Expand Up @@ -720,6 +755,7 @@ type Subscription {
roomChatMessageReceived(room_id: ID!): RoomChatMessage
cuberNotificationReceived: CuberNotification
roomMembersUpdated(room_id: ID!): [Cuber!]
roomMemberStatusUpdated(room_id: ID!): CuberRoomPivot
roomUpdated(room_id: ID!): Room
roundStarted(room_id: ID!): Round
roundFinished(room_id: ID!): Round
Expand Down
22 changes: 22 additions & 0 deletions gql/subscription/room.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ export const ROOM_MEMBERS_UPDATED_SUBSCRIPTION = gql`
subscription roomMembersUpdated($room_id: ID!) {
roomMembersUpdated(room_id: $room_id) {
...CuberBasic
pivot {
type
last_activity_at
}
}
}
${cuberBasicFragment}
Expand Down Expand Up @@ -57,6 +61,10 @@ export const ROUND_STARTED_SUBSCRIPTION = gql`
...Solve
cuber {
...CuberBasic
pivot {
type
last_activity_at
}
}
}
accumulated_results {
Expand Down Expand Up @@ -101,3 +109,17 @@ export const SOLVE_UPDATED_SUBSCRIPTION = gql`
${solveFragment}
${cuberBasicFragment}
`

//not real subscription
export const ROOM_MEMBER_STATUS_UPDATED_SUBSCRIPTION = gql`
subscription roomMemberStatusUpdated($room_id: ID!) {
roomMemberStatusUpdated(room_id: $room_id) {
type
last_activity_at
cuber {
...CuberBasic
}
}
}
${cuberBasicFragment}
`
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"randomstring": "^1.1.5",
"scramble-display": "^0.1.0",
"stackmat": "^1.0.0",
"stackmat-signal-processor": "^0.1.0",
"vue-tour": "^1.3.0"
},
"devDependencies": {
Expand Down
9 changes: 6 additions & 3 deletions pages/my-rooms.vue
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ import AddRoomDialog from '~/components/dialog/room/addRoomDialog.vue'
import { mapGetters } from 'vuex'
export default {
middleware: 'router-auth',
components: {
ViewCuberRoomsInterface,
AddRoomDialog,
Expand All @@ -76,7 +74,12 @@ export default {
}),
},
mounted() {},
mounted() {
//login required, else redirect to home
if (!this.$store.getters['auth/user']) {
this.$router.push('/')
}
},
methods: {
openAddRoomDialog() {
Expand Down
Loading

0 comments on commit 48b7310

Please sign in to comment.