Skip to content
Snippets Groups Projects
Commit 80f7624d authored by xaralis's avatar xaralis
Browse files

wip

parent 81cb32ab
No related branches found
No related tags found
No related merge requests found
Pipeline #2744 failed
...@@ -8,15 +8,17 @@ import * as Sentry from "@sentry/react"; ...@@ -8,15 +8,17 @@ import * as Sentry from "@sentry/react";
import { Integrations } from "@sentry/tracing"; import { Integrations } from "@sentry/tracing";
import { loadAnnouncements } from "actions/announcements"; import { loadAnnouncements } from "actions/announcements";
import { loadConfig } from "actions/global-info"; import { loadConfig, loadEventList } from "actions/global-info";
import { loadPosts } from "actions/posts"; import { loadPosts } from "actions/posts";
import { loadProgram } from "actions/program"; import { loadProgram } from "actions/program";
import { loadMe, refreshAccessToken } from "actions/users"; import { loadMe, refreshAccessToken } from "actions/users";
import { initializeWSChannel } from "actions/ws"; import { initializeWSChannel } from "actions/ws";
import Footer from "components/Footer"; import Footer from "components/Footer";
import Navbar from "components/Navbar"; import Navbar from "components/Navbar";
import EventBoundRoute from "components/routing/EventBoundRoute";
import About from "pages/About"; import About from "pages/About";
import Home from "pages/Home"; import Home from "pages/Home";
import Index from "pages/Index";
import NotFound from "pages/NotFound"; import NotFound from "pages/NotFound";
import Program from "pages/Program"; import Program from "pages/Program";
import Protocol from "pages/Protocol"; import Protocol from "pages/Protocol";
...@@ -118,10 +120,15 @@ const BaseApp = () => { ...@@ -118,10 +120,15 @@ const BaseApp = () => {
</Helmet> </Helmet>
<Navbar /> <Navbar />
<Switch> <Switch>
<Route exact path="/" children={<Home />} /> <Route exact path="/" children={<Index />} />
<Route exact path="/program" children={<Program />} /> <EventBoundRoute exact path="/event/live" children={<Home />} />
<Route exact path="/protocol" children={<Protocol />} /> <EventBoundRoute exact path="/event/program" children={<Program />} />
<Route exact path="/about" children={<About />} /> <EventBoundRoute
exact
path="/event/protocol"
children={<Protocol />}
/>
<EventBoundRoute exact path="/event/about" children={<About />} />
<Route component={NotFound} /> <Route component={NotFound} />
</Switch> </Switch>
<Footer /> <Footer />
...@@ -132,10 +139,11 @@ const BaseApp = () => { ...@@ -132,10 +139,11 @@ const BaseApp = () => {
}; };
const ConfiguredApp = () => { const ConfiguredApp = () => {
loadConfig.read(); // loadConfig.read();
loadProgram.read(); // loadProgram.read();
loadAnnouncements.read(); // loadAnnouncements.read();
loadPosts.read(); // loadPosts.read();
loadEventList.read();
return ( return (
<Suspense fallback={LoadingComponent}> <Suspense fallback={LoadingComponent}>
......
...@@ -6,6 +6,33 @@ import { fetch } from "api"; ...@@ -6,6 +6,33 @@ import { fetch } from "api";
import { markdownConverter } from "markdown"; import { markdownConverter } from "markdown";
import { GlobalInfoStore } from "stores"; import { GlobalInfoStore } from "stores";
export const loadEventList = createAsyncAction(
async () => {
try {
const resp = await fetch("/events");
const payload = await resp.json();
if (!isArray(payload)) {
return errorResult([], "Unexpected response format");
}
return successResult(payload);
} catch (err) {
return errorResult([], err.toString());
}
},
{
postActionHook: ({ result }) => {
if (!result.error) {
GlobalInfoStore.update((state) => {
console.log(result.payload);
});
}
},
}
);
export const loadConfig = createAsyncAction( export const loadConfig = createAsyncAction(
async () => { async () => {
try { try {
......
import React from "react";
import { Redirect, Route } from "react-router-dom";
import PropTypes from "prop-types";
import { GlobalInfoStore } from "stores";
const EventBoundRoute = ({
component: Component,
children,
fallbackTo = "/",
...rest
}) => {
const { eventId } = GlobalInfoStore.useState();
return (
<Route
{...rest}
render={(props) =>
!!eventId ? (
children ? (
children
) : (
<Component {...props} />
)
) : (
<Redirect to={fallbackTo} />
)
}
/>
);
};
EventBoundRoute.propTypes = {
component: PropTypes.elementType,
children: PropTypes.node,
fallbackTo: PropTypes.string,
};
export default EventBoundRoute;
import React from "react";
const Index = () => {
return <div></div>;
};
export default Index;
...@@ -3,7 +3,9 @@ import { Store } from "pullstate"; ...@@ -3,7 +3,9 @@ import { Store } from "pullstate";
/** @type {CF2021.GlobalInfoStorePayload} */ /** @type {CF2021.GlobalInfoStorePayload} */
const globalInfoStoreInitial = { const globalInfoStoreInitial = {
connectionState: "connecting", currentEventId: null,
events: [],
connectionState: "offline",
onlineMembers: 0, onlineMembers: 0,
onlineUsers: 0, onlineUsers: 0,
groupSizeHalf: null, groupSizeHalf: null,
......
declare namespace CF2021 { declare namespace CF2021 {
interface EventDetails {
name: string;
type: 1 | 2 | 3;
description?: string;
start: Date;
stream: string;
banner: string;
}
export interface GlobalInfoStorePayload { export interface GlobalInfoStorePayload {
// Current event selection
currentEventId: string;
events: EventDetails[];
connectionState: "connected" | "offline" | "connecting"; connectionState: "connected" | "offline" | "connecting";
onlineMembers: number; onlineMembers: number;
onlineUsers: number; onlineUsers: number;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment