Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/glacials/splits-io. a speedrunning data store and analysis engine splits.io
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455import { getAccessToken } from '../token'
export default { data: () => ({ error: null, loading: false, }), methods: { createPublic: async function() { return this.create('public') }, createSecret: async function() { return this.create('secret') }, createInviteOnly: async function() { return this.create('invite_only') }, create: async function(visibility) { try { this.loading = true this.error = null
const headers = new Headers() headers.append('Content-Type', 'application/json') const accessToken = getAccessToken() if (accessToken) { headers.append('Authorization', `Bearer ${accessToken}`) }
const response = await fetch(`/api/v4/races`, { method: 'POST', headers: headers, body: JSON.stringify({ game_id: this.gameId, category_id: this.categoryId, visibility: visibility, }) })
if (!response.ok) { throw (await response.json()).error || response.statusText }
Turbolinks.visit((await response.json()).race.path) } catch(error) { this.error = `Error: ${error}` } finally { this.loading = false } }, }, name: 'race-create', props: ['game-id', 'category-id'],}