Skip to content

Instantly share code, notes, and snippets.

@moxdev
Created October 15, 2020 17:54
Show Gist options
  • Save moxdev/cf6a6327b756eab43127baa19d8de300 to your computer and use it in GitHub Desktop.
Save moxdev/cf6a6327b756eab43127baa19d8de300 to your computer and use it in GitHub Desktop.
Idea: You can create Categories (e.g. Programming Basics). Inside these you can create individual lessons (e.g. What are variables?, what are recursions?).
import S from "@sanity/desk-tool/structure-builder"
import { FaFileText, FaEdit, FaComment, FaPlayCircle, FaQuestionCircle, FaCheckCircle } from 'react-icons/lib/fa'
export default () =>
S.list()
.title("App")
.items([
S.listItem()
.title("Content")
.icon(FaFileText)
.child(
S.documentList()
.id('categories')
.title('Categories')
.schemaType('category')
.filter('_type == "category" && !(_id in path("drafts.**"))')
.defaultOrdering([{field: 'position', direction: 'asc'}])
.menuItems([
S.orderingMenuItem({title: 'Position ascending', by: [{ field: "position", direction: "asc" }]}),
S.orderingMenuItem({title: 'Position descending', by: [{ field: "position", direction: "desc" }]})
])
.child(categoryId =>
S.documentList()
.id('lessons')
.title('Lessons of Category')
.schemaType('lesson')
.filter('_type == "lesson" && category._ref == $categoryId && !(_id in path("drafts.**"))')
.params({types: ['lesson-for-category'], categoryId})
//not this works:
.initialValueTemplates([
S.initialValueTemplateItem('lesson-for-category', {categoryId: categoryId})
])
.defaultOrdering([{field: 'position', direction: 'asc'}])
.menuItems([
//nor this:
S.menuItemsFromInitialValueTemplateItems([
S.initialValueTemplateItem('lesson-for-category', {categoryId: categoryId}),
]),
S.menuItem()
.title('edit category')
.icon(FaEdit)
.intent({
type: "edit",
params: {
type: "category",
id: categoryId
}
}),
S.orderingMenuItem({title: 'Position ascending', by: [{ field: "position", direction: "asc" }]}),
S.orderingMenuItem({title: 'Position descending', by: [{ field: "position", direction: "desc" }]})
])
import T from '@sanity/base/initial-value-template-builder'
export default [
...T.defaults(),
T.template({
id: 'lesson-for-category',
title: 'Lesson for Category',
description: 'Creates a lesson for selected category',
schemaType: 'lesson',
parameters: [
{
name: 'categoryId',
type: 'string'
}
],
value: parameters => ({
category: {_type: 'reference', _ref: parameters.categoryId}
})
})
]
{
//...
"parts": [
{
"name": "part:@sanity/base/schema",
"path": "./schemas/schema.js"
},
{
"name": "part:@sanity/desk-tool/structure",
"path": "./deskStructure.js"
},
{
"name": "part:@sanity/base/initial-value-templates",
"path": "./initialValueTemplates.js"
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment