-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
244 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { Panel, Placeholder } from 'rsuite'; | ||
|
||
import { WebrepubPreset } from '@/desginer/typings/webrepub'; | ||
|
||
interface PresetCardProps extends Pick<WebrepubPreset, 'name'> { | ||
onClick: () => void; | ||
} | ||
|
||
export function PresetCard({ name, onClick }: PresetCardProps) { | ||
return ( | ||
<Panel bordered header={name} onClick={onClick} className='pointer-cursor'> | ||
<Placeholder.Paragraph /> | ||
</Panel> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { useRouter } from 'next/router'; | ||
import { useCallback } from 'react'; | ||
import { Col, Grid, Row } from 'rsuite'; | ||
|
||
import { PresetCard } from '@/desginer/Components/PresetCard'; | ||
import { useWebrepub } from '@/desginer/Providers/webrepub'; | ||
|
||
export function PresetList() { | ||
const { | ||
presets: { collection }, | ||
setCurrentPreset, | ||
} = useWebrepub(); | ||
const router = useRouter(); | ||
|
||
const handlePresetClick = useCallback( | ||
(presetName: string) => { | ||
setCurrentPreset(presetName); | ||
router.push('/editor'); | ||
}, | ||
[router, setCurrentPreset] | ||
); | ||
|
||
return ( | ||
<Grid fluid> | ||
<Row gutter={16}> | ||
{collection.map(({ name }) => ( | ||
<Col lg={8} md={8} sm={24} xs={24} key={name} className='mb-20'> | ||
<PresetCard name={name} onClick={() => handlePresetClick(name)} /> | ||
</Col> | ||
))} | ||
</Row> | ||
</Grid> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 0 additions & 50 deletions
50
src/desginer/Providers/GlobalSettings/globalSettingsContext.tsx
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './webrepubContext'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import { createContext, PropsWithChildren, useContext, useState } from 'react'; | ||
|
||
import { WebrepubPreset } from '@/desginer/typings/webrepub'; | ||
import { ensure } from '@/utils'; | ||
|
||
interface WebrepubConfigurations { | ||
settings: { | ||
isInDesignMode: boolean; | ||
}; | ||
presets: { | ||
collection: WebrepubPreset[]; | ||
currentPreset?: WebrepubPreset; | ||
}; | ||
} | ||
|
||
const noop = () => { | ||
/* do nothing */ | ||
}; | ||
|
||
const defaultWebrepubConfigurations: WebrepubConfigurations = { | ||
settings: { | ||
isInDesignMode: true, | ||
}, | ||
presets: { | ||
collection: [], | ||
}, | ||
}; | ||
|
||
interface WebrepubConfigurationsContextProps { | ||
settings: WebrepubConfigurations['settings']; | ||
presets: WebrepubConfigurations['presets']; | ||
setSettings: (settings: Partial<WebrepubConfigurations['settings']>) => void; | ||
setCurrentPreset: (presetName: string) => void; | ||
} | ||
|
||
const WebrepubContext = createContext<WebrepubConfigurationsContextProps>({ | ||
...defaultWebrepubConfigurations, | ||
setSettings: noop, | ||
setCurrentPreset: noop, | ||
}); | ||
|
||
interface GlobalSettingsProviderProps extends PropsWithChildren { | ||
settings: WebrepubConfigurations['settings']; | ||
presets: WebrepubConfigurations['presets']; | ||
} | ||
|
||
export function WebrepubProvider({ | ||
children, | ||
settings, | ||
presets, | ||
}: GlobalSettingsProviderProps) { | ||
const [globalSettings, setGlobalSettings] = useState(settings); | ||
const [presetsValue, setPresetsValue] = useState(presets); | ||
|
||
const value: WebrepubConfigurationsContextProps = { | ||
settings: globalSettings, | ||
setSettings: (settings) => { | ||
setGlobalSettings({ | ||
...globalSettings, | ||
...settings, | ||
}); | ||
}, | ||
presets: { | ||
collection: presetsValue.collection, | ||
currentPreset: presetsValue.currentPreset, | ||
}, | ||
setCurrentPreset: (presetName: string) => { | ||
setPresetsValue({ | ||
...presetsValue, | ||
currentPreset: ensure( | ||
presetsValue.collection.find((p) => p.name === presetName) | ||
), | ||
}); | ||
}, | ||
}; | ||
|
||
return ( | ||
<WebrepubContext.Provider value={value}> | ||
{children} | ||
</WebrepubContext.Provider> | ||
); | ||
} | ||
|
||
export function useWebrepub() { | ||
return useContext(WebrepubContext); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,11 @@ | ||
import { UserComponent } from '@craftjs/core'; | ||
import { ReactNode } from 'react'; | ||
|
||
export type WebrepubComponent<T = unknown> = UserComponent<T> & { | ||
export type WebrepubComponent<T> = UserComponent<T> & { | ||
icon?: ReactNode; | ||
}; | ||
|
||
export type WebrepubPreset = { | ||
name: string; | ||
components: WebrepubComponent[]; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { useEffect, useState } from 'react'; | ||
|
||
import { WebRepubApp } from '@/desginer'; | ||
import { isMobileDevice, isSmallScreen } from '@/desginer/utils/screen'; | ||
import { LoadingView, SmallScreenView } from '@/desginer/Views'; | ||
|
||
export default function EditorPage() { | ||
const [loading, setLoading] = useState(true); | ||
const [isDesktop, setIsDesktop] = useState(false); | ||
|
||
useEffect(() => { | ||
setLoading(false); | ||
|
||
const checkIsDesktop = () => | ||
setIsDesktop(!isMobileDevice() && !isSmallScreen()); | ||
|
||
checkIsDesktop(); | ||
window.addEventListener('resize', checkIsDesktop); | ||
|
||
return () => { | ||
window.removeEventListener('resize', checkIsDesktop); | ||
}; | ||
}, []); | ||
|
||
if (loading) { | ||
return <LoadingView></LoadingView>; | ||
} | ||
|
||
if (isDesktop) { | ||
return <WebRepubApp />; | ||
} | ||
|
||
return <SmallScreenView />; | ||
} |
Oops, something went wrong.