21
resources/client/channels/channel-header/use-channel-layouts.ts
Executable file
21
resources/client/channels/channel-header/use-channel-layouts.ts
Executable file
@@ -0,0 +1,21 @@
|
||||
import {Channel} from '@common/channels/channel';
|
||||
import {channelContentConfig} from '@app/admin/channels/channel-content-config';
|
||||
import {useCookie} from '@common/utils/hooks/use-cookie';
|
||||
|
||||
export function useChannelLayouts(channel: Channel) {
|
||||
const config = channelContentConfig.models[channel.config.contentModel];
|
||||
const availableLayouts = config?.layoutMethods
|
||||
.filter(m => channelContentConfig.userSelectableLayouts.includes(m))
|
||||
.map(method => ({
|
||||
key: method,
|
||||
label: channelContentConfig.layoutMethods[method].label,
|
||||
icon: channelContentConfig.layoutMethods[method].icon,
|
||||
}));
|
||||
|
||||
const [selectedLayout, setSelectedLayout] = useCookie(
|
||||
`channel-layout-${channel.config.contentModel}`,
|
||||
channel.config.selectedLayout || channel.config.layout
|
||||
);
|
||||
|
||||
return {selectedLayout, setSelectedLayout, availableLayouts};
|
||||
}
|
||||
Reference in New Issue
Block a user