Skip to content

Commit

Permalink
Merge pull request #12 from thomasKn/thomas/fv-222-section-setting-sh…
Browse files Browse the repository at this point in the history
…owhide

Add hide section setting
  • Loading branch information
thomasKn authored Jan 30, 2024
2 parents f37d5b4 + 3fff73f commit 18565d9
Show file tree
Hide file tree
Showing 17 changed files with 64 additions and 60 deletions.
6 changes: 4 additions & 2 deletions app/components/CmsSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ export function CmsSection(props: {
const type = data._type;
const Section = useMemo(() => sections[type], [type]);

if (data.settings.hide) return null;

return Section ? (
<SectionWrapper data={data} type={props.type}>
<Suspense
Expand Down Expand Up @@ -71,7 +73,7 @@ function SectionWrapper(props: {

return props.type === 'footer' ? (
<footer
className="bg-background text-foreground section-padding relative"
className="section-padding relative bg-background text-foreground"
data-footer-type={isDev ? sectionType : null}
>
<style dangerouslySetInnerHTML={{__html: cssVars}} />
Expand All @@ -82,7 +84,7 @@ function SectionWrapper(props: {
</footer>
) : (
<section
className="bg-background text-foreground section-padding relative"
className="section-padding relative bg-background text-foreground"
data-section-type={isDev ? sectionType : null}
id={`section-${data._key}`}
>
Expand Down
1 change: 1 addition & 0 deletions app/qroq/footers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const FOOTER_SETTINGS_FRAGMENT = q('settings').grab({
code: q.string().optional(),
})
.nullable(),
hide: q.boolean().nullable(),
padding: q
.object({
bottom: q.number().nullable(),
Expand Down
1 change: 1 addition & 0 deletions app/qroq/sections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export const SECTION_SETTINGS_FRAGMENT = q('settings').grab({
code: q.string().optional(),
})
.nullable(),
hide: q.boolean().nullable(),
padding: q
.object({
bottom: q.number().nullable(),
Expand Down
2 changes: 0 additions & 2 deletions studio/schemas/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import header from './singletons/header';
import page from './documents/page';
import settings from './singletons/settings';
import themeContent from './singletons/themeContent';
import ctaSection from './objects/sections/ctaSection';
import imageBannerSection from './objects/sections/imageBannerSection';
import home from './singletons/home';
import collection from './documents/collection';
Expand Down Expand Up @@ -63,7 +62,6 @@ const sections = [
featuredProductSection,
collectionListSection,
productInformationSection,
ctaSection,
relatedProductsSection,
carouselSection,
richtextSection,
Expand Down
6 changes: 6 additions & 0 deletions studio/schemas/objects/global/sectionSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ export default defineField({
type: 'object',
name: 'sectionSettings',
fields: [
defineField({
name: 'hide',
title: 'Hide section',
type: 'boolean',
initialValue: false,
}),
defineField({
name: 'colorScheme',
title: 'Color scheme',
Expand Down
3 changes: 0 additions & 3 deletions studio/schemas/objects/global/sectionsList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ const globalSections = [
{
type: 'collectionListSection',
},
{
type: 'ctaSection',
},
{
type: 'carouselSection',
},
Expand Down
7 changes: 4 additions & 3 deletions studio/schemas/objects/sections/carouselSection.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {GalleryHorizontal} from 'lucide-react';
import {EyeOff, GalleryHorizontal} from 'lucide-react';
import {defineField} from 'sanity';

export default defineField({
Expand All @@ -8,11 +8,12 @@ export default defineField({
preview: {
select: {
title: 'title',
settings: 'settings',
},
prepare({title}: any) {
prepare({title, settings}: any) {
return {
title: title?.[0]?.value || 'Missing title',
media: GalleryHorizontal,
media: settings.hide ? EyeOff : GalleryHorizontal,
};
},
},
Expand Down
9 changes: 6 additions & 3 deletions studio/schemas/objects/sections/collectionBanner.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {defineField} from 'sanity';
import {Image} from 'lucide-react';
import {EyeOff, Image} from 'lucide-react';

export default defineField({
name: 'collectionBannerSection',
Expand All @@ -23,10 +23,13 @@ export default defineField({
}),
],
preview: {
prepare() {
select: {
settings: 'settings',
},
prepare({settings}:any) {
return {
title: 'Collection Banner',
media: () => <Image />,
media: () => settings.hide ? <EyeOff/> : <Image />,
};
},
},
Expand Down
9 changes: 6 additions & 3 deletions studio/schemas/objects/sections/collectionListSection.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {LayoutGrid} from 'lucide-react';
import {EyeOff, LayoutGrid} from 'lucide-react';
import {defineField} from 'sanity';

export default defineField({
Expand Down Expand Up @@ -40,10 +40,13 @@ export default defineField({
}),
],
preview: {
prepare() {
select: {
settings: 'settings',
},
prepare({settings}: any) {
return {
title: 'Collection List',
media: () => <LayoutGrid />,
media: () => settings.hide ? <EyeOff/> : <LayoutGrid />,
};
},
},
Expand Down
9 changes: 6 additions & 3 deletions studio/schemas/objects/sections/collectionProductGrid.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {defineField} from 'sanity';
import {LayoutGrid} from 'lucide-react';
import {EyeOff, LayoutGrid} from 'lucide-react';

export default defineField({
name: 'collectionProductGridSection',
Expand Down Expand Up @@ -57,10 +57,13 @@ export default defineField({
enableSorting: true,
},
preview: {
prepare() {
select: {
settings: 'settings',
},
prepare({settings}: any) {
return {
title: 'Collection Product Grid',
media: () => <LayoutGrid />,
media: () => settings.hide ? <EyeOff/> : <LayoutGrid />,
};
},
},
Expand Down
28 changes: 0 additions & 28 deletions studio/schemas/objects/sections/ctaSection.ts

This file was deleted.

6 changes: 4 additions & 2 deletions studio/schemas/objects/sections/featuredCollectionSection.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { EyeOff } from 'lucide-react';
import {defineField} from 'sanity';

export default defineField({
Expand Down Expand Up @@ -41,12 +42,13 @@ export default defineField({
preview: {
select: {
collection: 'collection.store',
settings: 'settings',
},
prepare({collection}: any) {
prepare({collection, settings}: any) {
return {
title: collection.title,
subtitle: 'Featured Collection',
media: () => <img src={collection.imageUrl} alt={collection.title} />,
media: () => settings.hide ? <EyeOff/> : <img src={collection.imageUrl} alt={collection.title} />,
};
},
},
Expand Down
6 changes: 4 additions & 2 deletions studio/schemas/objects/sections/featuredProductSection.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { EyeOff } from 'lucide-react';
import {defineField} from 'sanity';

export default defineField({
Expand All @@ -19,12 +20,13 @@ export default defineField({
preview: {
select: {
product: 'product.store',
settings: 'settings',
},
prepare({product}: any) {
prepare({product, settings}: any) {
return {
title: product.title,
subtitle: 'Featured Product',
media: () => <img src={product.previewImageUrl} alt={product.title} />,
media: () => settings.hide ? <EyeOff/> : <img src={product.previewImageUrl} alt={product.title} />,
};
},
},
Expand Down
6 changes: 4 additions & 2 deletions studio/schemas/objects/sections/imageBannerSection.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { EyeOff } from 'lucide-react';
import {defineField} from 'sanity';

export default defineField({
Expand Down Expand Up @@ -54,12 +55,13 @@ export default defineField({
select: {
title: 'title',
media: 'backgroundImage',
settings: 'settings',
},
prepare({title, media}: any) {
prepare({title, media, settings}: any) {
return {
title: title?.[0]?.value || 'Missing title',
subtitle: 'Image Banner',
media: media,
media: settings.hide ? EyeOff : media,
};
},
},
Expand Down
8 changes: 6 additions & 2 deletions studio/schemas/objects/sections/productInformationSection.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {defineField} from 'sanity';
import {IconTag} from '../../../components/icons/Tag';
import { EyeOff } from 'lucide-react';

export default defineField({
name: 'productInformationSection',
Expand All @@ -16,10 +17,13 @@ export default defineField({
}),
],
preview: {
prepare() {
select: {
settings: 'settings',
},
prepare({ settings }: any) {
return {
title: 'Product Information',
media: () => <IconTag />,
media: () => settings.hide ? <EyeOff/> : <IconTag />,
};
},
},
Expand Down
8 changes: 6 additions & 2 deletions studio/schemas/objects/sections/relatedProductsSection.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {defineField} from 'sanity';
import {IconCollectionTag} from '../../../components/icons/CollectionTag';
import { EyeOff } from 'lucide-react';

export default defineField({
name: 'relatedProductsSection',
Expand Down Expand Up @@ -40,10 +41,13 @@ export default defineField({
desktopColumns: 3,
},
preview: {
prepare() {
select: {
settings: 'settings',
},
prepare({ settings }: any) {
return {
title: 'Related Products',
media: () => <IconCollectionTag />,
media: () => settings.hide ? <EyeOff/> : <IconCollectionTag />,
};
},
},
Expand Down
9 changes: 6 additions & 3 deletions studio/schemas/objects/sections/richtextSection.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {TextSelect} from 'lucide-react';
import {EyeOff, TextSelect} from 'lucide-react';
import {defineField} from 'sanity';

export default defineField({
Expand Down Expand Up @@ -73,10 +73,13 @@ export default defineField({
maxWidth: 900,
},
preview: {
prepare() {
select: {
settings: 'settings',
},
prepare({ settings }: any) {
return {
title: 'Richtext',
media: () => <TextSelect />,
media: () => settings.hide ? <EyeOff/> : <TextSelect />,
};
},
},
Expand Down

0 comments on commit 18565d9

Please sign in to comment.