Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .github/workflows/typescript.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ jobs:
type-check:
name: TypeScript Type Check
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./app

steps:
- name: Checkout code
Expand All @@ -22,17 +25,14 @@ jobs:
with:
node-version: "22"
cache: "npm"
cache-dependency-path: "./app/package-lock.json"

- name: Install dependencies
run: npm ci
working-directory: ./app

- name: Run TypeScript type check
run: npm run type-check
working-directory: ./app

# Optional: Run ESLint if you have it configured
- name: Run ESLint
run: npm run lint
working-directory: ./app
continue-on-error: true # Make this optional for now
continue-on-error: true
37 changes: 33 additions & 4 deletions app/src/api/api.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
import { refreshToken } from './auth';

/**
* Gets the CSRF token from cookies
* @returns {string} The CSRF token or an empty string if not found
*/
const getCsrfToken = (): string => {
const cookies = document.cookie.split(';');
let csrfToken = '';
for (const cookie of cookies) {
const [name, value] = cookie.trim().split('=');
if (name === 'csrf_token' && value) {
csrfToken = decodeURIComponent(value);
break;
}
}
return csrfToken;
};

/**
* Makes an API call with proper cookie handling and error handling
*/
Expand All @@ -9,14 +26,26 @@ export const apiCall = async (
): Promise<Response> => {
console.debug(`Making API call to: ${url}`);
try {
// Set up headers with CSRF token for non-GET requests
const method = options.method || 'GET';
const headers: Record<string, string> = {
'Content-Type': 'application/json',
...(options.headers as Record<string, string>),
};

// Add CSRF token for non-GET methods
if (method !== 'GET') {
const csrfToken = getCsrfToken();
if (csrfToken) {
headers['X-CSRF-Token'] = csrfToken;
}
}

const response = await fetch(url, {
...options,
// Include credentials to send/receive cookies
credentials: 'include',
headers: {
'Content-Type': 'application/json',
...options.headers,
},
headers,
});
console.debug(`Response status: ${response.status} for URL: ${url}`);

Expand Down
2 changes: 1 addition & 1 deletion app/src/components/editor/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { EditorView, keymap } from '@codemirror/view';
import { markdown } from '@codemirror/lang-markdown';
import { defaultKeymap } from '@codemirror/commands';
import { oneDark } from '@codemirror/theme-one-dark';
import { useWorkspace } from '../../contexts/WorkspaceContext';
import { useWorkspace } from '../../hooks/useWorkspace';

interface EditorProps {
content: string;
Expand Down
2 changes: 1 addition & 1 deletion app/src/components/editor/MarkdownPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import rehypePrism from 'rehype-prism';
import * as prod from 'react/jsx-runtime';
import { notifications } from '@mantine/notifications';
import { remarkWikiLinks } from '../../utils/remarkWikiLinks';
import { useWorkspace } from '../../contexts/WorkspaceContext';
import { useWorkspace } from '../../hooks/useWorkspace';

interface MarkdownPreviewProps {
content: string;
Expand Down
2 changes: 1 addition & 1 deletion app/src/components/files/FileActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
IconGitCommit,
} from '@tabler/icons-react';
import { useModalContext } from '../../contexts/ModalContext';
import { useWorkspace } from '../../contexts/WorkspaceContext';
import { useWorkspace } from '../../hooks/useWorkspace';

interface FileActionsProps {
handlePullChanges: () => Promise<boolean>;
Expand Down
2 changes: 1 addition & 1 deletion app/src/components/layout/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Sidebar from './Sidebar';
import MainContent from './MainContent';
import { useFileNavigation } from '../../hooks/useFileNavigation';
import { useFileList } from '../../hooks/useFileList';
import { useWorkspace } from '../../contexts/WorkspaceContext';
import { useWorkspace } from '../../hooks/useWorkspace';

const Layout: React.FC = () => {
const { currentWorkspace, loading: workspaceLoading } = useWorkspace();
Expand Down
2 changes: 1 addition & 1 deletion app/src/components/layout/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Box } from '@mantine/core';
import FileActions from '../files/FileActions';
import FileTree from '../files/FileTree';
import { useGitOperations } from '../../hooks/useGitOperations';
import { useWorkspace } from '../../contexts/WorkspaceContext';
import { useWorkspace } from '../../hooks/useWorkspace';
import type { FileNode } from '@/types/models';

interface SidebarProps {
Expand Down
5 changes: 4 additions & 1 deletion app/src/components/navigation/UserMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,10 @@ const UserMenu: React.FC = () => {
)}

<UnstyledButton
onClick={() => void handleLogout}
onClick={() => {
void handleLogout();
setOpened(false);
}}
px="sm"
py="xs"
color="red"
Expand Down
2 changes: 1 addition & 1 deletion app/src/components/navigation/WorkspaceSwitcher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
useMantineTheme,
} from '@mantine/core';
import { IconFolders, IconSettings, IconFolderPlus } from '@tabler/icons-react';
import { useWorkspace } from '../../contexts/WorkspaceContext';
import { useWorkspace } from '../../hooks/useWorkspace';
import { useModalContext } from '../../contexts/ModalContext';
import { listWorkspaces } from '../../api/workspace';
import CreateWorkspaceModal from '../modals/workspace/CreateWorkspaceModal';
Expand Down
4 changes: 2 additions & 2 deletions app/src/components/settings/workspace/AppearanceSettings.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import { Text, Switch, Group, Box } from '@mantine/core';
import { useWorkspace } from '../../../contexts/WorkspaceContext';
import { useTheme } from '../../../contexts/ThemeContext';
import { Theme } from '@/types/models';

interface AppearanceSettingsProps {
Expand All @@ -10,7 +10,7 @@ interface AppearanceSettingsProps {
const AppearanceSettings: React.FC<AppearanceSettingsProps> = ({
onThemeChange,
}) => {
const { colorScheme, updateColorScheme } = useWorkspace();
const { colorScheme, updateColorScheme } = useTheme();

const handleThemeChange = (): void => {
const newTheme = colorScheme === 'dark' ? Theme.Light : Theme.Dark;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useState } from 'react';
import { Box, Button } from '@mantine/core';
import DeleteWorkspaceModal from '../../modals/workspace/DeleteWorkspaceModal';
import { useWorkspace } from '../../../contexts/WorkspaceContext';
import { useWorkspace } from '../../../hooks/useWorkspace';
import { useModalContext } from '../../../contexts/ModalContext';

const DangerZoneSettings: React.FC = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
Accordion,
} from '@mantine/core';
import { notifications } from '@mantine/notifications';
import { useWorkspace } from '../../../contexts/WorkspaceContext';
import { useWorkspace } from '../../../hooks/useWorkspace';
import AppearanceSettings from './AppearanceSettings';
import EditorSettings from './EditorSettings';
import GitSettings from './GitSettings';
Expand Down
46 changes: 46 additions & 0 deletions app/src/contexts/ThemeContext.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import React, {
createContext,
useContext,
useCallback,
type ReactNode,
} from 'react';
import { useMantineColorScheme, type MantineColorScheme } from '@mantine/core';

interface ThemeContextType {
colorScheme: MantineColorScheme;
updateColorScheme: (newTheme: MantineColorScheme) => void;
}

const ThemeContext = createContext<ThemeContextType | null>(null);

interface ThemeProviderProps {
children: ReactNode;
}

export const ThemeProvider: React.FC<ThemeProviderProps> = ({ children }) => {
const { colorScheme, setColorScheme } = useMantineColorScheme();

const updateColorScheme = useCallback(
(newTheme: MantineColorScheme): void => {
setColorScheme(newTheme);
},
[setColorScheme]
);

const value: ThemeContextType = {
colorScheme,
updateColorScheme,
};

return (
<ThemeContext.Provider value={value}>{children}</ThemeContext.Provider>
);
};

export const useTheme = (): ThemeContextType => {
const context = useContext(ThemeContext);
if (!context) {
throw new Error('useTheme must be used within a ThemeProvider');
}
return context;
};
Loading
Loading