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.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100import raceNav from './race-nav.js'import { getAccessToken } from '../token'
export default { components: { raceNav, }, computed: { categories: function() { if (!this.game) { return [] }
return [{id: null, name: '<N/A / Race-specific category>'}, ...this.game.categories] }, category: function() { return this.categories.find(category => category.id === this.categoryId) }, game: function() { return this.games.find(game => game.id === this.gameId) }, title: function() { if (this.race === null) { return '' } if (this.race.game === null && this.race.category === null && this.race.notes === null) { return 'Untitled race' } return `${(this.race.game || {name: ''}).name} ${(this.race.category || {name: ''}).name} ${(this.race.notes || '').split('\n')[0]}` }, }, created: async function() { this.notes = this.race.notes this.games = (await (fetch('/api/v4/games').then(response => response.json()))).games
this.gameId = (this.race.game || {id: null}).id this.categoryId = (this.race.category || {id: null}).id }, data: () => ({ categoryId: null, editing: false, error: null, gameId: null, games: [], loading: false, notes: '', }), methods: { cancel: function() { this.editing = false }, edit: async function() { this.editing = true }, save: async function() { this.error = false this.loading = true this.editing = false
const headers = new Headers() headers.append('Content-Type', 'application/json') const accessToken = getAccessToken() if (accessToken) { headers.append('Authorization', `Bearer ${accessToken}`) }
try { const response = fetch(`/api/v4/races/${this.race.id}`, { method: 'PATCH', headers: headers, body: JSON.stringify({ category_id: this.categoryId, game_id: (this.game || {}).id, notes: this.notes, }) })
if (!(await response).ok) { throw (await response.json()).error || response.statusText }
} catch(error) { this.error = error } finally { this.loading = false document.getElementById('input-chat-text').focus() } }, }, name: 'race-title', props: ['race'], watch: { gameId: function() { if (this.game.categories.find(category => category.id === this.categoryId) === undefined) { this.categoryId = null } }, },}