Skip to content

Commit

Permalink
Add toggle for feature.
Browse files Browse the repository at this point in the history
  • Loading branch information
leighmacdonald committed Dec 20, 2024
1 parent 2faf922 commit 6f6bc96
Show file tree
Hide file tree
Showing 14 changed files with 168 additions and 112 deletions.
1 change: 1 addition & 0 deletions frontend/src/api/admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type General = {
reports_enabled: boolean;
chatlogs_enabled: boolean;
demos_enabled: boolean;
speedruns_enabled: boolean;
};

type Filters = {
Expand Down
1 change: 1 addition & 0 deletions frontend/src/api/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ export interface appInfoDetail {
reports_enabled: boolean;
chatlogs_enabled: boolean;
demos_enabled: boolean;
speedruns_enabled: boolean;
}

export const getAppInfo = async () => apiCall<appInfoDetail>('/api/info');
6 changes: 6 additions & 0 deletions frontend/src/component/LeftAlignButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import Button, { ButtonProps } from '@mui/material/Button';
import { styled } from '@mui/material/styles';

export const LeftAlignButton = styled(Button)<ButtonProps>(() => ({
justifyContent: 'space-between'
}));
3 changes: 2 additions & 1 deletion frontend/src/contexts/AppInfoCtx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ export const UseAppInfoCtx = createContext<AppInfoCtx>({
reports_enabled: false,
servers_enabled: true,
stats_enabled: false,
wiki_enabled: false
wiki_enabled: false,
speedruns_enabled: false
}
});

Expand Down
16 changes: 15 additions & 1 deletion frontend/src/routes/_admin.admin.settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,8 @@ const GeneralSection = ({ tab, settings, mutate }: { tab: tabs; settings: Config
servers_enabled: settings.general.servers_enabled,
reports_enabled: settings.general.reports_enabled,
chatlogs_enabled: settings.general.chatlogs_enabled,
demos_enabled: settings.general.demos_enabled
demos_enabled: settings.general.demos_enabled,
speedruns_enabled: settings.general.speedruns_enabled
}
});

Expand Down Expand Up @@ -492,6 +493,19 @@ const GeneralSection = ({ tab, settings, mutate }: { tab: tabs; settings: Config
<SubHeading>Enable showing the searchable chatlogs.</SubHeading>
</Grid>

<Grid xs={12}>
<Field
name={'speedruns_enabled'}
validators={{
onChange: z.boolean()
}}
children={(props) => {
return <CheckboxSimple {...props} label={'Enable Speedruns support'} />;
}}
/>
<SubHeading>Enables the 1000 uncles speedruns tracking support.</SubHeading>
</Grid>

<Grid xs={12}>
<Subscribe
selector={(state) => [state.canSubmit, state.isSubmitting]}
Expand Down
87 changes: 44 additions & 43 deletions frontend/src/routes/_guest.index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Title } from '@mui/icons-material';
import AttachMoneyIcon from '@mui/icons-material/AttachMoney';
import ChatIcon from '@mui/icons-material/Chat';
import ElectricBoltIcon from '@mui/icons-material/ElectricBolt';
Expand All @@ -9,14 +10,14 @@ import PieChartIcon from '@mui/icons-material/PieChart';
import StorageIcon from '@mui/icons-material/Storage';
import SupportIcon from '@mui/icons-material/Support';
import VideocamIcon from '@mui/icons-material/Videocam';
import Button from '@mui/material/Button';
import Link from '@mui/material/Link';
import Stack from '@mui/material/Stack';
import Grid from '@mui/material/Unstable_Grid2';
import { useNavigate, useRouteContext, createFileRoute } from '@tanstack/react-router';
import { PermissionLevel } from '../api';
import { LeftAlignButton } from '../component/LeftAlignButton.tsx';
import { NewsView } from '../component/NewsView';
import RouterLink from '../component/RouterLink.tsx';
import { Title } from '../component/Title.tsx';
import { useAppInfoCtx } from '../contexts/AppInfoCtx.ts';

export const Route = createFileRoute('/_guest/')({
Expand All @@ -32,13 +33,13 @@ function Index() {
<>
<Title />
<Grid container spacing={3}>
<Grid xs={12} sm={12} md={9}>
<Grid xs={12} sm={12} md={10}>
<NewsView itemsPerPage={3} />
</Grid>
<Grid xs={12} sm={12} md={3}>
<Grid xs={12} sm={12} md={2}>
<Stack spacing={3}>
{profile && profile.ban_id == 0 && appInfo.servers_enabled && (
<Button
<LeftAlignButton
startIcon={<StorageIcon />}
fullWidth
color={'success'}
Expand All @@ -48,10 +49,10 @@ function Index() {
}}
>
Play Now!
</Button>
</LeftAlignButton>
)}
{profile && profile.ban_id != 0 && appInfo.reports_enabled && (
<Button
<LeftAlignButton
startIcon={<SupportIcon />}
fullWidth
color={'success'}
Expand All @@ -63,107 +64,107 @@ function Index() {
}}
>
Appeal Ban
</Button>
</LeftAlignButton>
)}
{appInfo.wiki_enabled && (
<>
<Button
<LeftAlignButton
component={RouterLink}
startIcon={<GavelIcon />}
fullWidth
color={'primary'}
variant={'contained'}
to={`/wiki/Rules`}
href={`/wiki/Rules`}
>
Rules
</Button>
</LeftAlignButton>

<Button
<LeftAlignButton
component={RouterLink}
startIcon={<EventIcon />}
fullWidth
color={'primary'}
variant={'contained'}
to={'/wiki/Events'}
href={'/wiki/Events'}
>
Events
</Button>
</LeftAlignButton>
</>
)}
{appInfo.patreon_enabled && (
<Button
<LeftAlignButton
component={RouterLink}
startIcon={<AttachMoneyIcon />}
fullWidth
color={'primary'}
variant={'contained'}
to={`/patreon`}
href={`/patreon`}
>
Donate
</Button>
</LeftAlignButton>
)}
{appInfo.contests_enabled && (
<Button
<LeftAlignButton
component={RouterLink}
startIcon={<EmojiEventsIcon />}
fullWidth
color={'primary'}
variant={'contained'}
to={`/contests`}
href={`/contests`}
>
Contests
</Button>
</LeftAlignButton>
)}
{appInfo.chatlogs_enabled && (
<Button
<LeftAlignButton
component={RouterLink}
startIcon={<ChatIcon />}
fullWidth
color={'primary'}
variant={'contained'}
to={`/chatlogs`}
href={`/chatlogs`}
>
Chat Logs
</Button>
</LeftAlignButton>
)}
{appInfo.demos_enabled && (
<Button
<LeftAlignButton
component={RouterLink}
startIcon={<VideocamIcon />}
fullWidth
color={'primary'}
variant={'contained'}
to={`/stv`}
href={`/stv`}
>
SourceTV
</Button>
</LeftAlignButton>
)}
{appInfo.stats_enabled && (
<Button
<LeftAlignButton
component={RouterLink}
startIcon={<PieChartIcon />}
fullWidth
color={'primary'}
variant={'contained'}
to={`/stats`}
href={`/stats`}
>
Stats (Beta)
</Button>
</LeftAlignButton>
)}
{appInfo.speedruns_enabled && profile.permission_level >= PermissionLevel.Moderator && (
<LeftAlignButton
component={RouterLink}
startIcon={<ElectricBoltIcon />}
fullWidth
color={'primary'}
variant={'contained'}
href={'/speedruns'}
>
Speedruns
</LeftAlignButton>
)}

<Button
component={RouterLink}
startIcon={<ElectricBoltIcon />}
fullWidth
color={'primary'}
variant={'contained'}
to={'/speedruns'}
>
Speedruns
</Button>

{appInfo.discord_enabled && appInfo.link_id != '' && (
<Button
<LeftAlignButton
component={Link}
startIcon={<MarkUnreadChatAltIcon />}
fullWidth
Expand All @@ -172,7 +173,7 @@ function Index() {
href={`https://discord.gg/${appInfo.link_id}`}
>
Join Discord
</Button>
</LeftAlignButton>
)}
</Stack>
</Grid>
Expand Down
5 changes: 3 additions & 2 deletions internal/config/config_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func (c *configRepository) Read(ctx context.Context) (domain.Config, error) {
const query = `
SELECT general_site_name, general_mode, general_file_serve_mode, general_srcds_log_addr, general_asset_url,
general_default_route, general_news_enabled, general_forums_enabled, general_contests_enabled, general_wiki_enabled,
general_stats_enabled, general_servers_enabled, general_reports_enabled,general_chatlogs_enabled, general_demos_enabled,
general_stats_enabled, general_servers_enabled, general_reports_enabled,general_chatlogs_enabled, general_demos_enabled, general_speedruns_enabled,
filters_enabled, filters_dry, filters_ping_discord, filters_max_weight, filters_warning_timeout, filters_check_timeout, filters_match_timeout,
Expand Down Expand Up @@ -67,7 +67,7 @@ func (c *configRepository) Read(ctx context.Context) (domain.Config, error) {
err := c.db.QueryRow(ctx, query).
Scan(&cfg.General.SiteName, &cfg.General.Mode, &cfg.General.FileServeMode, &cfg.General.SrcdsLogAddr, &cfg.General.AssetURL,
&cfg.General.DefaultRoute, &cfg.General.NewsEnabled, &cfg.General.ForumsEnabled, &cfg.General.ContestsEnabled, &cfg.General.WikiEnabled,
&cfg.General.StatsEnabled, &cfg.General.ServersEnabled, &cfg.General.ReportsEnabled, &cfg.General.ChatlogsEnabled, &cfg.General.DemosEnabled,
&cfg.General.StatsEnabled, &cfg.General.ServersEnabled, &cfg.General.ReportsEnabled, &cfg.General.ChatlogsEnabled, &cfg.General.DemosEnabled, &cfg.General.SpeedrunsEnabled,
&cfg.Filters.Enabled, &cfg.Filters.Dry, &cfg.Filters.PingDiscord, &cfg.Filters.MaxWeight, &cfg.Filters.WarningTimeout, &cfg.Filters.CheckTimeout, &cfg.Filters.MatchTimeout,
&cfg.Demo.DemoCleanupEnabled, &cfg.Demo.DemoCleanupStrategy, &cfg.Demo.DemoCleanupMinPct, &cfg.Demo.DemoCleanupMount, &cfg.Demo.DemoCountLimit,
&cfg.Patreon.Enabled, &cfg.Patreon.ClientID, &cfg.Patreon.ClientSecret, &cfg.Patreon.CreatorAccessToken, &cfg.Patreon.CreatorRefreshToken, &cfg.Patreon.IntegrationsEnabled,
Expand Down Expand Up @@ -132,6 +132,7 @@ func (c *configRepository) Write(ctx context.Context, config domain.Config) erro
"general_reports_enabled": config.General.ReportsEnabled,
"general_chatlogs_enabled": config.General.ChatlogsEnabled,
"general_demos_enabled": config.General.DemosEnabled,
"general_speedruns_enabled": config.General.SpeedrunsEnabled,
"filters_enabled": config.Filters.Enabled,
"filters_dry": config.Filters.Dry,
"filters_ping_discord": config.Filters.PingDiscord,
Expand Down
78 changes: 40 additions & 38 deletions internal/config/config_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,50 +55,52 @@ func (c configHandler) onAPIPutConfig() gin.HandlerFunc {

func (c configHandler) onAppInfo(buildInfo domain.BuildInfo) gin.HandlerFunc {
type appInfo struct {
SiteName string `json:"site_name"`
AssetURL string `json:"asset_url"`
LinkID string `json:"link_id"`
AppVersion string `json:"app_version"`
DocumentPolicy string `json:"document_policy"`
PatreonClientID string `json:"patreon_client_id"`
DiscordClientID string `json:"discord_client_id"`
DiscordEnabled bool `json:"discord_enabled"`
PatreonEnabled bool `json:"patreon_enabled"`
DefaultRoute string `json:"default_route"`
NewsEnabled bool `json:"news_enabled"`
ForumsEnabled bool `json:"forums_enabled"`
ContestsEnabled bool `json:"contests_enabled"`
WikiEnabled bool `json:"wiki_enabled"`
StatsEnabled bool `json:"stats_enabled"`
ServersEnabled bool `json:"servers_enabled"`
ReportsEnabled bool `json:"reports_enabled"`
ChatlogsEnabled bool `json:"chatlogs_enabled"`
DemosEnabled bool `json:"demos_enabled"`
SiteName string `json:"site_name"`
AssetURL string `json:"asset_url"`
LinkID string `json:"link_id"`
AppVersion string `json:"app_version"`
DocumentPolicy string `json:"document_policy"`
PatreonClientID string `json:"patreon_client_id"`
DiscordClientID string `json:"discord_client_id"`
DiscordEnabled bool `json:"discord_enabled"`
PatreonEnabled bool `json:"patreon_enabled"`
DefaultRoute string `json:"default_route"`
NewsEnabled bool `json:"news_enabled"`
ForumsEnabled bool `json:"forums_enabled"`
ContestsEnabled bool `json:"contests_enabled"`
WikiEnabled bool `json:"wiki_enabled"`
StatsEnabled bool `json:"stats_enabled"`
ServersEnabled bool `json:"servers_enabled"`
ReportsEnabled bool `json:"reports_enabled"`
ChatlogsEnabled bool `json:"chatlogs_enabled"`
DemosEnabled bool `json:"demos_enabled"`
SpeedrunsEnabled bool `json:"speedruns_enabled"`
}

return func(ctx *gin.Context) {
conf := c.config.Config()

ctx.JSON(http.StatusOK, appInfo{
SiteName: conf.General.SiteName,
AssetURL: conf.General.AssetURL,
LinkID: conf.Discord.LinkID,
AppVersion: buildInfo.BuildVersion,
DocumentPolicy: "",
PatreonClientID: conf.Patreon.ClientID,
DiscordClientID: conf.Discord.AppID,
DiscordEnabled: conf.Discord.IntegrationsEnabled && conf.Discord.Enabled,
PatreonEnabled: conf.Patreon.IntegrationsEnabled && conf.Patreon.Enabled,
DefaultRoute: conf.General.DefaultRoute,
NewsEnabled: conf.General.NewsEnabled,
ForumsEnabled: conf.General.ForumsEnabled,
ContestsEnabled: conf.General.ContestsEnabled,
WikiEnabled: conf.General.WikiEnabled,
StatsEnabled: conf.General.StatsEnabled,
ServersEnabled: conf.General.ServersEnabled,
ReportsEnabled: conf.General.ReportsEnabled,
ChatlogsEnabled: conf.General.ChatlogsEnabled,
DemosEnabled: conf.General.DemosEnabled,
SiteName: conf.General.SiteName,
AssetURL: conf.General.AssetURL,
LinkID: conf.Discord.LinkID,
AppVersion: buildInfo.BuildVersion,
DocumentPolicy: "",
PatreonClientID: conf.Patreon.ClientID,
DiscordClientID: conf.Discord.AppID,
DiscordEnabled: conf.Discord.IntegrationsEnabled && conf.Discord.Enabled,
PatreonEnabled: conf.Patreon.IntegrationsEnabled && conf.Patreon.Enabled,
DefaultRoute: conf.General.DefaultRoute,
NewsEnabled: conf.General.NewsEnabled,
ForumsEnabled: conf.General.ForumsEnabled,
ContestsEnabled: conf.General.ContestsEnabled,
WikiEnabled: conf.General.WikiEnabled,
StatsEnabled: conf.General.StatsEnabled,
ServersEnabled: conf.General.ServersEnabled,
ReportsEnabled: conf.General.ReportsEnabled,
ChatlogsEnabled: conf.General.ChatlogsEnabled,
DemosEnabled: conf.General.DemosEnabled,
SpeedrunsEnabled: conf.General.SpeedrunsEnabled,
})
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@ DROP TABLE IF EXISTS speedrun_round;
DROP TABLE IF EXISTS speedrun_runners;
DROP TABLE IF EXISTS speedrun;

ALTER TABLE config
DROP COLUMN IF EXISTS general_speedruns_enabled;

COMMIT;
Loading

0 comments on commit 6f6bc96

Please sign in to comment.