Commit cafd1254 authored by Emmanuel Raviart's avatar Emmanuel Raviart

Add restitutions and remove websocket updates from servers in admin mode.

parent 52829601
......@@ -49,10 +49,15 @@
title: "Pitches",
urlPath: "/admin/pitches",
},
// {
// slug: "slideshow",
// title: "Diaporama",
// urlPath: "/admin/slideshow",
// },
{
slug: "slideshow",
title: "Diaporama",
urlPath: "/admin/slideshow",
slug: "restitutions",
title: "Restitutions",
urlPath: "/admin/restitutions",
},
],
},
......
......@@ -241,6 +241,7 @@
// This fires when the component has been rendered to the DOM (=> client-only).
// cf https://github.com/sveltejs/sapper/issues/222
let firstMessage = true
const ws = this.ws = new Sockette(`${config.appWsUrl}/admin`, {
// timeout: 5e3,
// maxAttempts: 10,
......@@ -249,8 +250,11 @@
onmaximum: event => console.log("Admin Défis Stop Attempting!", event),
onmessage: event => {
// console.log("Admin Défis Received:", event)
const {acceptedProjectsId, rejectedProjectsId} = JSON.parse(event.data)
this.set({acceptedProjectsId, rejectedProjectsId})
if (firstMessage) {
const {acceptedProjectsId, rejectedProjectsId} = JSON.parse(event.data)
this.set({acceptedProjectsId, rejectedProjectsId})
firstMessage = false
}
},
onopen: (/* event */) => {
// console.log("Admin Défis Connected!", event)
......@@ -265,7 +269,7 @@
// query,
}) {
try {
const projectsCategory = await fetchCategory(this, categoryConfig)
const projectsCategory = await fetchCategory(this.fetch, categoryConfig)
return {
projectsCategory: {
...projectsCategory,
......
......@@ -64,6 +64,7 @@
// This fires when the component has been rendered to the DOM (=> client-only).
// cf https://github.com/sveltejs/sapper/issues/222
let firstMessage = true
this.ws = new Sockette(`${config.appWsUrl}/admin`, {
// timeout: 5e3,
// maxAttempts: 10,
......@@ -72,8 +73,11 @@
onmaximum: event => console.log("Admin Index Stop Attempting!", event),
onmessage: event => {
// console.log("Admin Index Received:", event)
const {nowPlaying} = JSON.parse(event.data)
this.set({nowPlaying})
if (firstMessage) {
const {nowPlaying} = JSON.parse(event.data)
this.set({nowPlaying})
firstMessage = false
}
},
onopen: (/* event */) => {
// console.log("Admin Index Connected!", event)
......
......@@ -251,6 +251,7 @@
// This fires when the component has been rendered to the DOM (=> client-only).
// cf https://github.com/sveltejs/sapper/issues/222
let firstMessage = true
const ws = this.ws = new Sockette(`${config.appWsUrl}/admin`, {
// timeout: 5e3,
// maxAttempts: 10,
......@@ -259,8 +260,11 @@
onmaximum: event => console.log("Admin Messages Stop Attempting!", event),
onmessage: event => {
// console.log("Admin Messages Received:", event)
const {acceptedMessagesId, playingTopicId, rejectedMessagesId} = JSON.parse(event.data)
this.set({acceptedMessagesId, playingTopicId, rejectedMessagesId})
if (firstMessage) {
const {acceptedMessagesId, playingTopicId, rejectedMessagesId} = JSON.parse(event.data)
this.set({acceptedMessagesId, playingTopicId, rejectedMessagesId})
firstMessage = false
}
},
onopen: (/* event */) => {
// console.log("Admin Messages Connected!", event)
......@@ -275,7 +279,7 @@
// query,
}) {
try {
const messagesCategory = await fetchCategory(this, categoryConfig)
const messagesCategory = await fetchCategory(this.fetch, categoryConfig)
return {
messagesCategory: {
...messagesCategory,
......
......@@ -207,6 +207,7 @@
// This fires when the component has been rendered to the DOM (=> client-only).
// cf https://github.com/sveltejs/sapper/issues/222
let firstMessage = true
this.ws = new Sockette(`${config.appWsUrl}/admin`, {
// timeout: 5e3,
// maxAttempts: 10,
......@@ -215,22 +216,34 @@
onmaximum: event => console.log("Admin Pitches Stop Attempting!", event),
onmessage: event => {
// console.log("Admin Pitches Received:", event)
const {
acceptedProjectsId,
duration,
playingTopicId,
projectsCategory,
seconds,
secondsRunning,
} = JSON.parse(event.data)
this.set({
acceptedProjectsId,
duration,
playingTopicId,
projectsCategory,
seconds,
secondsRunning,
})
if (firstMessage) {
const {
acceptedProjectsId,
duration,
playingTopicId,
projectsCategory,
seconds,
secondsRunning,
} = JSON.parse(event.data)
let newDuration = duration.toString()
this.set({
acceptedProjectsId,
duration,
newDuration,
playingTopicId,
projectsCategory,
seconds,
secondsRunning,
})
firstMessage = false
} else {
const {
seconds,
} = JSON.parse(event.data)
this.set({
seconds,
})
}
},
onopen: (/* event */) => {
// console.log("Admin Pitches Connected!", event)
......
This diff is collapsed.
import urlResolve from "url-resolve"
import config from "./config.js"
export async function fetchCategory(component, { showId, slug }) {
export async function fetchCategory(fetch, { showId, slug }) {
let category = null
for (let page = 0; ; page++) {
const url = urlResolve(config.apiUrl, `/c/${slug}.json?page=${page}`)
let response = null
try {
response = await component.fetch(url)
response = await fetch(url)
} catch (error) {
throw `Error while fetching category at ${url}: ${error}`
}
......@@ -34,6 +34,21 @@ export async function fetchCategory(component, { showId, slug }) {
}
}
export async function fetchTopic(fetch, id) {
const url = urlResolve(config.apiUrl, `/t/${id}.json`)
let response = null
try {
response = await fetch(url)
} catch (error) {
throw `Error while fetching topic at ${url}: ${error}`
}
try {
return await response.json()
} catch (error) {
throw `Error while converting topic at ${url} to JSON: ${error}`
}
}
export function toMinutesSeconds(seconds) {
let sign = ""
if (seconds < 0) {
......
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