Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
Signed-off-by: Cédric Boirard <cedric@framer.com>
  • Loading branch information
triozer committed Dec 31, 2024
1 parent 2e6a78f commit 9d893ad
Show file tree
Hide file tree
Showing 10 changed files with 365 additions and 326 deletions.
10 changes: 5 additions & 5 deletions examples/cms/datasources/articles.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,31 @@
"items": [
{
"Title": "Getting Started",
"Reading time": 5,
"Reading time": 3,
"Featured": true,
"Content": "<h2>Editing Content</h2><blockquote><p>You can choose to set up different types of input fields depending on your content...</p></blockquote>..."
},
{
"Title": "What's New",
"Reading time": 5,
"Reading time": 2,
"Featured": false,
"Content": "<h2>Reference Fields</h2>..."
},
{
"Title": "Styling Elements",
"Reading time": 5,
"Reading time": 4,
"Featured": false,
"Content": "<h2>Reference Fields</h2>..."
},
{
"Title": "Importing Content",
"Reading time": 5,
"Reading time": 6,
"Featured": false,
"Content": "<h2>Prepare your CSV file</h2><p>Make sure your file is exported as a \"CSV\" file...</p>"
},
{
"Title": "Best Practices",
"Reading time": 5,
"Reading time": 8,
"Featured": true,
"Content": "<h3>Choose Compelling Topics</h3><p>Use analytics tools to understand demographic data and user behavior...</p>"
}
Expand Down
7 changes: 7 additions & 0 deletions examples/cms/datasources/categories.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,32 @@
"Title": {
"type": "string"
},
"Description": {
"type": "string"
},
"Color": {
"type": "color"
}
},
"items": [
{
"Title": "CMS",
"Description": "Content Management System",
"Color": "orange"
},
{
"Title": "Basics",
"Description": "Basic content management",
"Color": "red"
},
{
"Title": "Updates",
"Description": "Updates to the CMS",
"Color": "blue"
},
{
"Title": "Pro Tips",
"Description": "Tips for using the CMS",
"Color": "green"
}
]
Expand Down
29 changes: 13 additions & 16 deletions examples/cms/src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ main {
padding: 0 15px 15px;
height: 100%;
gap: 15px;

user-select: none;
-webkit-user-select: none;
}

form {
Expand Down Expand Up @@ -35,10 +38,6 @@ form {
background: linear-gradient(180deg, rgba(18, 18, 18, 0) 0%, rgb(17, 17, 17) 97.8%);
}

[data-framer-theme="dark"] input[type="checkbox"]:checked {
background-image: url("data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxMiIgaGVpZ2h0PSIxMiI+PHBhdGggZD0iTSAzIDYgTCA1IDggTCA5IDQiIGZpbGw9InRyYW5zcGFyZW50IiBzdHJva2Utd2lkdGg9IjEuNSIgc3Ryb2tlPSIjMmIyYjJiIiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiIHN0cm9rZS1kYXNoYXJyYXk9IiI+PC9wYXRoPjwvc3ZnPg==");
}

.sticky-top {
position: sticky;
top: 0;
Expand All @@ -53,11 +52,6 @@ form {
grid-column: span 2 / span 2;
}

.setup,
.mapping {
composes: no-scrollbar;
}

.setup .logo {
display: flex;
flex-direction: column;
Expand Down Expand Up @@ -113,25 +107,28 @@ form {
flex-direction: row;
align-items: center;
white-space: nowrap;
height: 30px;
padding: 0px 8px;
font-size: 12px;
color: var(--framer-color-text);
font-weight: 500;
background-color: var(--framer-color-bg-tertiary);
border-radius: 8px;
cursor: pointer;
gap: 8px;
user-select: none;
}

.mapping .source-field[aria-disabled="true"] {
opacity: 0.5;
}

.mapping .source-field:focus-visible {
outline: none;
box-shadow: inset 0 0 0 1px var(--framer-color-tint);
}

.mapping .source-field input[type="checkbox"] {
cursor: pointer;
}

.mapping .source-field input[type="checkbox"]:focus {
box-shadow: none;
}

.mapping footer {
position: sticky;
bottom: 0;
Expand Down
95 changes: 55 additions & 40 deletions examples/cms/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,64 +1,79 @@
import "./App.css"

import { framer, ManagedCollection, ManagedCollectionField } from "framer-plugin"
import type { ManagedCollection } from "framer-plugin"

import { framer } from "framer-plugin"
import { useEffect, useLayoutEffect, useState } from "react"
import { DataSource, getDataSource, getDataSourcesIds, syncCollection } from "./data"
import { DataSource, getDataSource } from "./data"
import { FieldMapping } from "./FieldMapping"
import { SelectDataSource } from "./SelectDataSource"
import { UI_DEFAULTS } from "./constants"
import { Spinner } from "./components/Spinner"

interface AppProps {
collection: ManagedCollection
dataSourceId: string | null
slugFieldId: string | null
previousDataSourceId: string | null
previousSlugFieldId: string | null
}

export function App({ collection, dataSourceId, slugFieldId }: AppProps) {
export function App({ collection, previousDataSourceId, previousSlugFieldId }: AppProps) {
const [dataSource, setDataSource] = useState<DataSource | null>(null)
const [existingFields, setExistingFields] = useState<ManagedCollectionField[]>([])

useLayoutEffect(() => {
if (!dataSource) {
framer.showUI({
width: UI_DEFAULTS.SETUP_WIDTH,
height: UI_DEFAULTS.SETUP_HEIGHT,
resizable: false,
})
return
}
const [isLoadingDataSource, setIsLoadingDataSource] = useState(Boolean(previousDataSourceId))
const hasDataSourceSelected = Boolean(isLoadingDataSource || dataSource)

useLayoutEffect(() => {
framer.showUI({
width: UI_DEFAULTS.MAPPING_WIDTH,
height: UI_DEFAULTS.MAPPING_HEIGHT,
minWidth: UI_DEFAULTS.MAPPING_WIDTH,
minHeight: UI_DEFAULTS.MAPPING_HEIGHT,
resizable: true,
width: hasDataSourceSelected ? 360 : 320,
height: hasDataSourceSelected ? 425 : 305,
minWidth: hasDataSourceSelected ? 360 : undefined,
minHeight: hasDataSourceSelected ? 425 : undefined,
resizable: dataSource !== null,
})
}, [dataSource])

useEffect(() => {
collection.getFields().then(setExistingFields)
}, [collection])
}, [hasDataSourceSelected, dataSource])

useEffect(() => {
if (!dataSourceId) {
if (!previousDataSourceId) {
return
}

getDataSource(dataSourceId).then(setDataSource)
}, [dataSourceId])
const abortController = new AbortController()

setIsLoadingDataSource(true)
getDataSource(previousDataSourceId, abortController.signal)
.then(setDataSource)
.catch(error => {
if (abortController.signal.aborted) {
return
}

console.error(error)
framer.notify(
`Error loading previously configured data source "${previousDataSourceId}". Check the logs for more details.`,
{
variant: "error",
}
)
})
.finally(() => {
if (abortController.signal.aborted) {
return
}

setIsLoadingDataSource(false)
})

return () => {
abortController.abort()
}
}, [previousDataSourceId])

if (isLoadingDataSource) {
return <Spinner />
}

if (!dataSource) {
return <SelectDataSource dataSources={getDataSourcesIds()} onSelectDataSource={setDataSource} />
} else {
return (
<FieldMapping
collection={collection}
dataSource={dataSource}
existingFields={existingFields}
slugFieldId={slugFieldId}
onImport={syncCollection}
/>
)
return <SelectDataSource onSelectDataSource={setDataSource} />
}

return <FieldMapping collection={collection} dataSource={dataSource} initialSlugFieldId={previousSlugFieldId} />
}
Loading

0 comments on commit 9d893ad

Please sign in to comment.