All files / frontend/src/containers/Prefs PrefsHugo.tsx

0% Statements 0/23
0% Branches 0/8
0% Functions 0/7
0% Lines 0/23

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94                                                                                                                                                                                           
import Typography from '@mui/material/Typography';
import Switch from '@mui/material/Switch';
import FormControlLabel from '@mui/material/FormControlLabel';
import Box from '@mui/material/Box';
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
import { instanceSettingsQueryOptions, instanceSettingsMutationOptions } from '../../queries/options';
import { useSnackbar } from '../../contexts/SnackbarContext';
 
function PrefsHugo() {
  const queryClient = useQueryClient();
  const { addSnackMessage } = useSnackbar();
 
  // Query: Fetch Hugo-specific instance settings using unified config API
  const { data: serveDraftMode } = useQuery(instanceSettingsQueryOptions.get('hugo.serveDraftMode'));
  const { data: disableAutoHugoServe } = useQuery(instanceSettingsQueryOptions.get('hugo.disableAutoHugoServe'));
 
  // Mutation: Save instance setting using unified config API
  const saveInstanceSettingMutation = useMutation({
    ...instanceSettingsMutationOptions.set(queryClient),
    onSuccess: (data, variables) => {
      // Invalidate queries
      queryClient.invalidateQueries({ queryKey: ['getInstanceSettings'] });
      queryClient.invalidateQueries({ queryKey: ['getInstanceSetting'] });
 
      // Add snackbar feedback
      if (variables.path === 'hugo.serveDraftMode') {
        const state = variables.value ? 'enabled' : 'disabled';
        addSnackMessage(`Hugo draft mode ${state}`, { severity: 'success' });
      } else if (variables.path === 'hugo.disableAutoHugoServe') {
        const state = variables.value ? 'disabled' : 'enabled';
        addSnackMessage(`Hugo auto serve ${state}`, { severity: 'success' });
      }
    },
    onError: (error: Error, variables) => {
      addSnackMessage(`Failed to update Hugo setting: ${error.message}`, { severity: 'error' });
    }
  });
 
  const serveDraftModeEnabled = Boolean(serveDraftMode);
  const disableAutoHugoServeEnabled = Boolean(disableAutoHugoServe);
 
  const handleServeDraftModeChange = (checked: boolean) => {
    saveInstanceSettingMutation.mutate({ path: 'hugo.serveDraftMode', value: checked });
  };
 
  const handleDisableAutoHugoServeChange = (checked: boolean) => {
    saveInstanceSettingMutation.mutate({ path: 'hugo.disableAutoHugoServe', value: checked });
  };
 
  return (
    <Box sx={{ padding: '20px', height: '100%' }}>
      <Typography variant="h4">Hugo Settings</Typography>
      <Typography variant="body2" color="text.secondary" sx={{ mt: 1, mb: 3 }}>
        Hugo-specific configuration for static site generation and serving.
      </Typography>
 
      <Box my={2}>
        <FormControlLabel
          control={
            <Switch
              checked={serveDraftModeEnabled}
              onChange={(e) => handleServeDraftModeChange(e.target.checked)}
              disabled={saveInstanceSettingMutation.isPending}
            />
          }
          label="Serve Draft Content"
        />
        <Typography variant="caption" color="text.secondary" sx={{ ml: 4, display: 'block' }}>
          When enabled, Hugo serve processes will include draft content. Changes take effect on next serve start.
        </Typography>
      </Box>
 
      <Box my={2}>
        <FormControlLabel
          control={
            <Switch
              checked={disableAutoHugoServeEnabled}
              onChange={(e) => handleDisableAutoHugoServeChange(e.target.checked)}
              disabled={saveInstanceSettingMutation.isPending}
            />
          }
          label="Disable Auto Hugo Serve"
        />
        <Typography variant="caption" color="text.secondary" sx={{ ml: 4, display: 'block' }}>
          When enabled, Hugo will NOT automatically start serve processes when opening workspaces.
        </Typography>
      </Box>
 
    </Box>
  );
}
 
export default PrefsHugo;