Skip to content

Commit

Permalink
dynamic editor
Browse files Browse the repository at this point in the history
  • Loading branch information
inetol committed Aug 10, 2024
1 parent f65e3b6 commit 8009cfb
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/app/[documentName]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { EditorScreen } from '@/screen/EditorScreen';
import EditorScreen from '@/screen/EditorScreen';

type PageProps = {
params: {
Expand Down
2 changes: 1 addition & 1 deletion src/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { EditorScreen } from '@/screen/EditorScreen';
import EditorScreen from '@/screen/EditorScreen';

export default function () {
return <EditorScreen />;
Expand Down
4 changes: 2 additions & 2 deletions src/component/editor/EditorComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type EditorProps = {
enableEdit: boolean;
};

export const EditorComponent = (props: EditorProps) => {
export default function (props: EditorProps) {
const editorRef = useRef<ReactCodeMirrorRef>(null);

const updateCursorInformation = useCallback(() => {
Expand Down Expand Up @@ -55,4 +55,4 @@ export const EditorComponent = (props: EditorProps) => {
}}
/>
);
};
}
6 changes: 3 additions & 3 deletions src/component/editor/FooterButtonComponent.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import useThemeValues from '@/hook/useThemeValue';
import { useThemeValues } from '@/hook/useThemeValue';
import { ThemePalette } from '@/utils/themes';
import { IconButton, Tooltip } from '@chakra-ui/react';
import type { ReactElement } from 'react';
Expand All @@ -12,7 +12,7 @@ type ActionButtonProps = {
};

// TODO: Dirty port from stable
export const FooterButtonComponent = (props: ActionButtonProps) => {
export default function (props: ActionButtonProps) {
const { getThemeValue } = useThemeValues();

return (
Expand All @@ -35,4 +35,4 @@ export const FooterButtonComponent = (props: ActionButtonProps) => {
/>
</Tooltip>
);
};
}
8 changes: 4 additions & 4 deletions src/component/editor/FooterComponent.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FooterButtonComponent } from '@/component/editor/FooterButtonComponent';
import useThemeValues from '@/hook/useThemeValue';
import FooterButtonComponent from '@/component/editor/FooterButtonComponent';
import { useThemeValues } from '@/hook/useThemeValue';
import { ThemePalette } from '@/utils/themes';
import { Flex, useToast } from '@chakra-ui/react';
import { type Dispatch, type SetStateAction, useState } from 'react';
Expand All @@ -14,7 +14,7 @@ type ControlsProps = {
};

// TODO: Dirty port from stable
export const FooterComponent = (props: ControlsProps) => {
export default function (props: ControlsProps) {
const { getThemeValue } = useThemeValues();
const [isSaveLoading, setIsSaveLoading] = useState(false);
const toast = useToast();
Expand Down Expand Up @@ -68,4 +68,4 @@ export const FooterComponent = (props: ControlsProps) => {
/>
</Flex>
);
};
}
8 changes: 4 additions & 4 deletions src/component/editor/HeaderComponent.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { HeaderLabelComponent } from '@/component/editor/HeaderLabelComponent';
import useThemeValues from '@/hook/useThemeValue';
import HeaderLabelComponent from '@/component/editor/HeaderLabelComponent';
import { useThemeValues } from '@/hook/useThemeValue';
import { ThemePalette } from '@/utils/themes';
import { Flex, Show } from '@chakra-ui/react';
import { MdClass } from 'react-icons/md';
Expand All @@ -10,7 +10,7 @@ export type HeaderProps = {
columnNumber: number;
};

export const HeaderComponent = (props: HeaderProps) => {
export default function (props: HeaderProps) {
const { getThemeValue } = useThemeValues();

return (
Expand All @@ -36,4 +36,4 @@ export const HeaderComponent = (props: HeaderProps) => {
</Show>
</Flex>
);
};
}
6 changes: 3 additions & 3 deletions src/component/editor/HeaderLabelComponent.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import useThemeValues from '@/hook/useThemeValue';
import { useThemeValues } from '@/hook/useThemeValue';
import { ThemePalette } from '@/utils/themes';
import { Flex, Text } from '@chakra-ui/react';
import type { ReactElement } from 'react';
Expand All @@ -9,7 +9,7 @@ type HeaderLabelProps = {
onClick?: () => WindowProxy | null;
};

export const HeaderLabelComponent = (props: HeaderLabelProps) => {
export default function (props: HeaderLabelProps) {
const { getThemeValue } = useThemeValues();

return (
Expand All @@ -28,4 +28,4 @@ export const HeaderLabelComponent = (props: HeaderLabelProps) => {
<Text color={getThemeValue(ThemePalette.TextMuted)}>{props.label}</Text>
</Flex>
);
};
}
2 changes: 1 addition & 1 deletion src/hook/useTheme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { themeStore } from '@/utils/store';
import { themes } from '@/utils/themes';
import { useColorMode } from '@chakra-ui/react';

export default function useTheme() {
export function useTheme() {
const { themeId, setThemeId } = themeStore();
const { colorMode, toggleColorMode } = useColorMode();

Expand Down
2 changes: 1 addition & 1 deletion src/hook/useThemeValue.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { themeStore } from '@/utils/store';
import { type ThemePaletteKey, themes } from '@/utils/themes';

export default function useThemeValues() {
export function useThemeValues() {
const { themeId } = themeStore();

const theme = themes.find((theme) => theme.id === themeId) ?? themes[0];
Expand Down
12 changes: 7 additions & 5 deletions src/screen/EditorScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
'use client';

import { EditorComponent } from '@/component/editor/EditorComponent';
import { FooterComponent } from '@/component/editor/FooterComponent';
import { HeaderComponent, type HeaderProps } from '@/component/editor/HeaderComponent';
import FooterComponent from '@/component/editor/FooterComponent';
import HeaderComponent, { type HeaderProps } from '@/component/editor/HeaderComponent';
import dynamic from 'next/dynamic';
import { useState } from 'react';

const EditorComponent = dynamic(() => import('@/component/editor/EditorComponent'));

type EditorScreenProps = {
documentName?: string;
enableEdit?: boolean;
};

export const EditorScreen = ({ documentName, enableEdit = false }: EditorScreenProps) => {
export default function ({ documentName, enableEdit = false }: EditorScreenProps) {
const [position, setPosition] = useState<HeaderProps>({
lineNumber: 1,
columnNumber: 1
Expand Down Expand Up @@ -40,4 +42,4 @@ export const EditorScreen = ({ documentName, enableEdit = false }: EditorScreenP
/>
</div>
);
};
}

0 comments on commit 8009cfb

Please sign in to comment.