mirror of
https://github.com/lordmathis/lemma.git
synced 2025-11-05 15:44:21 +00:00
Fix type-check issues
This commit is contained in:
@@ -55,7 +55,9 @@ const MarkdownPreview: React.FC<MarkdownPreviewProps> = ({
|
||||
const [filePath] = decodeURIComponent(
|
||||
href.replace(`${baseUrl}/internal/`, '')
|
||||
).split('#');
|
||||
handleFileSelect(filePath);
|
||||
if (filePath) {
|
||||
handleFileSelect(filePath);
|
||||
}
|
||||
} else if (href.startsWith(`${baseUrl}/notfound/`)) {
|
||||
// For non-existent files, show a notification
|
||||
const fileName = decodeURIComponent(
|
||||
@@ -105,9 +107,6 @@ const MarkdownPreview: React.FC<MarkdownPreviewProps> = ({
|
||||
</a>
|
||||
),
|
||||
code: ({ children, className, ...props }: MarkdownCodeProps) => {
|
||||
const language = className
|
||||
? className.replace('language-', '')
|
||||
: null;
|
||||
return (
|
||||
<pre className={className}>
|
||||
<code {...props}>{children}</code>
|
||||
|
||||
@@ -30,7 +30,7 @@ const EditUserModal: React.FC<EditUserModalProps> = ({
|
||||
const [formData, setFormData] = useState<UpdateUserRequest>({
|
||||
email: '',
|
||||
displayName: '',
|
||||
role: undefined,
|
||||
role: UserRole.Editor,
|
||||
password: '',
|
||||
});
|
||||
|
||||
@@ -58,7 +58,7 @@ const EditUserModal: React.FC<EditUserModalProps> = ({
|
||||
setFormData({
|
||||
email: '',
|
||||
displayName: '',
|
||||
role: undefined,
|
||||
role: UserRole.Editor,
|
||||
password: '',
|
||||
});
|
||||
onClose();
|
||||
@@ -88,9 +88,9 @@ const EditUserModal: React.FC<EditUserModalProps> = ({
|
||||
<Select
|
||||
label="Role"
|
||||
required
|
||||
value={formData.role}
|
||||
value={formData.role ? formData.role.toString() : null}
|
||||
onChange={(value) =>
|
||||
setFormData({ ...formData, role: value as UserRole | undefined })
|
||||
setFormData({ ...formData, role: value as UserRole })
|
||||
}
|
||||
data={[
|
||||
{ value: UserRole.Admin, label: 'Admin' },
|
||||
|
||||
@@ -139,7 +139,7 @@ const WorkspaceSwitcher: React.FC = () => {
|
||||
truncate
|
||||
c={
|
||||
isSelected
|
||||
? theme.colors.blue[
|
||||
? (theme as any).colors.blue[
|
||||
(theme as any).colorScheme === 'dark'
|
||||
? 0
|
||||
: 9
|
||||
|
||||
@@ -83,7 +83,7 @@ const AccountSettings: React.FC<AccountSettingsProps> = ({
|
||||
if (isInitialMount.current && user) {
|
||||
isInitialMount.current = false;
|
||||
const settings: UserProfileSettings = {
|
||||
displayName: user.displayName,
|
||||
displayName: user.displayName || '',
|
||||
email: user.email,
|
||||
currentPassword: '',
|
||||
newPassword: '',
|
||||
@@ -112,7 +112,7 @@ const AccountSettings: React.FC<AccountSettingsProps> = ({
|
||||
|
||||
// Add display name if changed
|
||||
if (state.localSettings.displayName !== state.initialSettings.displayName) {
|
||||
updates.displayName = state.localSettings.displayName;
|
||||
updates.displayName = state.localSettings.displayName || '';
|
||||
}
|
||||
|
||||
// Handle password change
|
||||
@@ -132,10 +132,10 @@ const AccountSettings: React.FC<AccountSettingsProps> = ({
|
||||
// If we're only changing display name or have password already provided, proceed directly
|
||||
if (!needsPasswordConfirmation || state.localSettings.currentPassword) {
|
||||
if (needsPasswordConfirmation) {
|
||||
updates.email = state.localSettings.email;
|
||||
updates.email = state.localSettings.email || '';
|
||||
// If we don't have a password change, we still need to include the current password for email change
|
||||
if (!updates.currentPassword) {
|
||||
updates.currentPassword = state.localSettings.currentPassword;
|
||||
updates.currentPassword = state.localSettings.currentPassword || '';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,12 +4,10 @@ import { useWorkspace } from '../../../contexts/WorkspaceContext';
|
||||
import { Theme } from '@/types/theme';
|
||||
|
||||
interface AppearanceSettingsProps {
|
||||
themeSettings?: Theme;
|
||||
onThemeChange: (newTheme: Theme) => void;
|
||||
}
|
||||
|
||||
const AppearanceSettings: React.FC<AppearanceSettingsProps> = ({
|
||||
themeSettings,
|
||||
onThemeChange,
|
||||
}) => {
|
||||
const { colorScheme, updateColorScheme } = useWorkspace();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import React, { useState } from 'react';
|
||||
import { Box, Button, Title } from '@mantine/core';
|
||||
import { Box, Button } from '@mantine/core';
|
||||
import DeleteWorkspaceModal from '../../modals/workspace/DeleteWorkspaceModal';
|
||||
import { useWorkspace } from '../../../contexts/WorkspaceContext';
|
||||
import { useModalContext } from '../../../contexts/ModalContext';
|
||||
|
||||
@@ -192,7 +192,6 @@ const WorkspaceSettings: React.FC = () => {
|
||||
<AccordionControl>Appearance</AccordionControl>
|
||||
<Accordion.Panel>
|
||||
<AppearanceSettings
|
||||
themeSettings={state.localSettings.theme}
|
||||
onThemeChange={(newTheme: string) =>
|
||||
handleInputChange('theme', newTheme)
|
||||
}
|
||||
|
||||
@@ -16,11 +16,7 @@ import {
|
||||
deleteWorkspace,
|
||||
listWorkspaces,
|
||||
} from '@/api/workspace';
|
||||
import {
|
||||
Workspace,
|
||||
DEFAULT_WORKSPACE_SETTINGS,
|
||||
WorkspaceSettings,
|
||||
} from '@/types/workspace';
|
||||
import { Workspace, DEFAULT_WORKSPACE_SETTINGS } from '@/types/workspace';
|
||||
|
||||
interface WorkspaceContextType {
|
||||
currentWorkspace: Workspace | null;
|
||||
@@ -89,6 +85,7 @@ export const WorkspaceProvider: React.FC<WorkspaceProviderProps> = ({
|
||||
const allWorkspaces = await listWorkspaces();
|
||||
if (allWorkspaces.length > 0) {
|
||||
const firstWorkspace = allWorkspaces[0];
|
||||
if (!firstWorkspace) throw new Error('No workspaces available');
|
||||
await updateLastWorkspaceName(firstWorkspace.name);
|
||||
await loadWorkspaceData(firstWorkspace.name);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
import { notifications } from '@mantine/notifications';
|
||||
import { getUsers, getWorkspaces, getSystemStats } from '@/api/admin';
|
||||
import { SystemStats, UserStats, WorkspaceStats } from '@/types/adminApi';
|
||||
import { SystemStats, WorkspaceStats } from '@/types/adminApi';
|
||||
import { User } from '@/types/authApi';
|
||||
|
||||
// Possible types of admin data
|
||||
type AdminDataType = 'stats' | 'workspaces' | 'users';
|
||||
@@ -12,7 +13,7 @@ type AdminData<T extends AdminDataType> = T extends 'stats'
|
||||
: T extends 'workspaces'
|
||||
? WorkspaceStats[]
|
||||
: T extends 'users'
|
||||
? UserStats[]
|
||||
? User[]
|
||||
: never;
|
||||
|
||||
// Define the return type of the hook
|
||||
@@ -34,10 +35,8 @@ export const useAdminData = <T extends AdminDataType>(
|
||||
} else if (type === 'workspaces') {
|
||||
return [] as WorkspaceStats[] as AdminData<T>;
|
||||
} else if (type === 'users') {
|
||||
return [] as UserStats[] as AdminData<T>;
|
||||
return [] as User[] as AdminData<T>;
|
||||
} else {
|
||||
// This case should never happen due to type constraints,
|
||||
// but TypeScript requires us to handle it
|
||||
return [] as unknown as AdminData<T>;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -37,15 +37,14 @@ export const useGitOperations = (): UseGitOperationsResult => {
|
||||
const handleCommitAndPush = useCallback(
|
||||
async (message: string): Promise<void> => {
|
||||
if (!currentWorkspace || !settings.gitEnabled) return;
|
||||
|
||||
const commitHash: CommitHash = await commitAndPush(
|
||||
currentWorkspace.name,
|
||||
message
|
||||
);
|
||||
try {
|
||||
const commitHash: CommitHash = await commitAndPush(
|
||||
currentWorkspace.name,
|
||||
message
|
||||
);
|
||||
notifications.show({
|
||||
title: 'Success',
|
||||
message: 'Successfully committed and pushed changes',
|
||||
message: 'Successfully committed and pushed changes ' + commitHash,
|
||||
color: 'green',
|
||||
});
|
||||
return;
|
||||
|
||||
@@ -1,19 +1,20 @@
|
||||
import { visit } from 'unist-util-visit';
|
||||
import { lookupFileByName, getFileUrl } from '../api/git';
|
||||
import { InlineContainerType, MARKDOWN_REGEX } from '../types/markdown';
|
||||
import { Node } from 'unist';
|
||||
import { Parent } from 'unist';
|
||||
import { Text } from 'mdast';
|
||||
import { lookupFileByName } from '@/api/file';
|
||||
import { getFileUrl } from './fileHelpers';
|
||||
|
||||
/**
|
||||
* Represents a wiki link match from the regex
|
||||
*/
|
||||
interface WikiLinkMatch {
|
||||
fullMatch: string;
|
||||
isImage: string;
|
||||
isImage: boolean; // Changed from string to boolean
|
||||
fileName: string;
|
||||
displayText: string;
|
||||
heading?: string;
|
||||
heading?: string | undefined;
|
||||
index: number;
|
||||
}
|
||||
|
||||
@@ -171,11 +172,22 @@ export function remarkWikiLinks(workspaceName: string) {
|
||||
const matches: WikiLinkMatch[] = [];
|
||||
|
||||
while ((match = regex.exec(node.value)) !== null) {
|
||||
const [fullMatch, isImage, innerContent] = match;
|
||||
// Provide default values during destructuring to handle potential undefined values
|
||||
const [fullMatch = '', isImageMark = '', innerContent = ''] = match;
|
||||
|
||||
// Skip if we somehow got a match without the expected content
|
||||
if (!innerContent) {
|
||||
console.warn('Matched wiki link without inner content:', fullMatch);
|
||||
continue;
|
||||
}
|
||||
|
||||
let fileName: string;
|
||||
let displayText: string;
|
||||
let heading: string | undefined;
|
||||
|
||||
// Convert isImageMark string to boolean
|
||||
const isImage: boolean = isImageMark === '!';
|
||||
|
||||
const pipeIndex: number = innerContent.indexOf('|');
|
||||
const hashIndex: number = innerContent.indexOf('#');
|
||||
|
||||
@@ -231,7 +243,7 @@ export function remarkWikiLinks(workspaceName: string) {
|
||||
lookupFileName
|
||||
);
|
||||
|
||||
if (paths && paths.length > 0) {
|
||||
if (paths && paths.length > 0 && paths[0]) {
|
||||
const filePath: string = paths[0];
|
||||
if (match.isImage) {
|
||||
newNodes.push(
|
||||
|
||||
Reference in New Issue
Block a user