Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(contented-preview): remove uncessary files #581

Merged
merged 3 commits into from
Aug 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
Binary file not shown.
Binary file not shown.

This file was deleted.

4 changes: 3 additions & 1 deletion packages/contented-preview/src/pages/_app.page.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ export default function App({ Component, pageProps }) {
<ThemeProvider>
<MenuProvider>
<Header />
<Component {...pageProps} />
<main className="bg-white text-gray-900 dark:bg-slate-900 dark:text-slate-300">
<Component {...pageProps} />
</main>
</MenuProvider>
</ThemeProvider>
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ export default function ContentNavigation({ sections, className }) {
<div className="mt-1 flex gap-4">
{pipelines.map(([type, pipeline]) => {
if (pipeline.collection[0] === undefined || pipeline.collection[0] === null) {
throw new PipelineCollectionNotFoundException(type);
throw new Error(
`Pipeline type '${type}' cannot resolve its collection. Please check if contented.config.mjs is properly configured.`,
);
}
return (
<Link href={`/${type.toLowerCase()}${pipeline.collection[0].path}`} key={type}>
Expand Down
26 changes: 21 additions & 5 deletions packages/contented-preview/src/pages/_components/Header.jsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { Bars3Icon, DocumentTextIcon, XMarkIcon } from '@heroicons/react/24/outline';
import { Bars3Icon, DocumentTextIcon, MoonIcon, SunIcon, XMarkIcon } from '@heroicons/react/24/outline';
import clsx from 'clsx';
import Link from 'next/link';

import { Pipelines } from '../../../../index.js';
import { PipelineCollectionNotFoundException } from '../../errors/PipelineCollectionNotFoundException.js';
import { useMenu } from './MenuContext';
import ThemeButton from './ThemeButton';
import { useTheme } from './ThemeContext';

export default function Header() {
const { isOpen, setIsOpen } = useMenu();
Expand Down Expand Up @@ -37,7 +36,9 @@ export default function Header() {
<div className="ml-6 hidden border-l border-slate-300/60 pl-4 dark:border-slate-300/10 md:flex">
{pipelines.map(([type, pipeline]) => {
if (pipeline.collection[0] === undefined || pipeline.collection[0] === null) {
throw new PipelineCollectionNotFoundException(type);
throw new Error(
`Pipeline type '${type}' cannot resolve its collection. Please check if contented.config.mjs is properly configured.`,
);
}
return (
<Link href={`/${type.toLowerCase()}${pipeline.collection[0].path}`} key={type}>
Expand Down Expand Up @@ -71,7 +72,7 @@ export default function Header() {
);
}

export function GitHubButton(props) {
function GitHubButton(props) {
return (
<div {...props}>
<a className="flex items-center" href={process.env.CONTENTED_PREVIEW_GITHUB_URL} target="_blank">
Expand All @@ -82,3 +83,18 @@ export function GitHubButton(props) {
</div>
);
}

function ThemeButton(props) {
const { setTheme } = useTheme();

return (
<div {...props}>
<button className="flex items-center">
<SunIcon className="hidden h-4 w-4 [[data-theme=light]_&]:block" onClick={() => setTheme('dark')} />
<MoonIcon className="hidden h-4 w-4 [[data-theme=dark]_&]:block" onClick={() => setTheme('light')} />
<SunIcon className="hidden h-4 w-4 [:not(.dark)[data-theme=system]_&]:block" onClick={() => setTheme('dark')} />
<MoonIcon className="hidden h-4 w-4 [.dark[data-theme=system]_&]:block" onClick={() => setTheme('light')} />
</button>
</div>
);
}
17 changes: 0 additions & 17 deletions packages/contented-preview/src/pages/_components/ThemeButton.jsx

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,59 @@
import { createContext, useState, useEffect, useContext } from 'react';
import Script from 'next/script';

/*
let mQ = window.matchMedia('(prefers-color-scheme: dark)');
let dE = document.documentElement;
let dEC = dE.classList;
function update(savedTheme) {
let theme = 'system'
try {
if (!savedTheme) {
savedTheme = window.localStorage.theme
}
if (savedTheme === 'dark') {
theme = 'dark'
dEC.add('dark')
} else if (savedTheme === 'light') {
theme = 'light'
dEC.remove('dark')
} else if (mQ.matches) {
dEC.add('dark')
} else {
dEC.remove('dark')
}
} catch {
theme = 'light'
dEC.remove('dark')
}
return theme
}
function updateWT(savedTheme) {
update(savedTheme)
dEC.add('[&_*]:!transition-none')
window.setTimeout(() => {
dEC.remove('[&_*]:!transition-none')
}, 0)
}
dE.setAttribute('data-theme', update())
new MutationObserver(([{ oldValue }]) => {
let newValue = dE.getAttribute('data-theme')
if (newValue !== oldValue) {
try {
window.localStorage.setItem('theme', newValue)
} catch {}
updateWT(newValue)
}
}).observe(dE, { attributeFilter: ['data-theme'], attributeOldValue: true })
mQ.addEventListener('change', updateWT)
window.addEventListener('storage', updateWT)
*/
const colorSchemeScript = `let mQ=window.matchMedia("(prefers-color-scheme: dark)"),dE=document.documentElement,dEC=dE.classList;function update(e){let t="system";try{e||(e=window.localStorage.theme),"dark"===e?(t="dark",dEC.add("dark")):"light"===e?(t="light",dEC.remove("dark")):mQ.matches?dEC.add("dark"):dEC.remove("dark")}catch{t="light",dEC.remove("dark")}return t}function updateWT(e){update(e),dEC.add("[&_*]:!transition-none"),window.setTimeout((()=>{dEC.remove("[&_*]:!transition-none")}),0)}dE.setAttribute("data-theme",update()),new MutationObserver((([{oldValue:e}])=>{let t=dE.getAttribute("data-theme");if(t!==e){try{window.localStorage.setItem("theme",t)}catch{}updateWT(t)}})).observe(dE,{attributeFilter:["data-theme"],attributeOldValue:!0}),mQ.addEventListener("change",updateWT),window.addEventListener("storage",updateWT);`;

const ThemeContext = createContext(undefined);

Expand All @@ -13,7 +68,12 @@ export function ThemeProvider(props) {
}
}, [theme]);

return <ThemeContext.Provider value={{ theme, setTheme }}>{props.children}</ThemeContext.Provider>;
return (
<>
<ThemeContext.Provider value={{ theme, setTheme }}>{props.children}</ThemeContext.Provider>
<Script id="theme-script" strategy="beforeInteractive" dangerouslySetInnerHTML={{ __html: colorSchemeScript }} />
</>
);
}

export function useTheme() {
Expand Down
78 changes: 0 additions & 78 deletions packages/contented-preview/src/pages/_document.page.jsx

This file was deleted.

Loading