Skip to content

Add nextjs-scheduler example and bump up examples to v0.4.7 #106

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

Merged
merged 7 commits into from
Oct 21, 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
2 changes: 2 additions & 0 deletions examples/nextjs-scheduler/fileInfo.ts

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion examples/profile-stack/fileInfo.ts

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion examples/react-tldraw/fileInfo.ts

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion examples/react-todomvc/fileInfo.ts

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions examples/simultaneous-cursors/fileInfo.ts

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion examples/vanilla-codemirror6/fileInfo.ts

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion examples/vanilla-quill/fileInfo.ts

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion examples/vuejs-kanban/fileInfo.ts

Large diffs are not rendered by default.

69 changes: 69 additions & 0 deletions pages/examples/calendar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { NextPage } from 'next';
import Head from 'next/head';
import { ExampleLayout } from '@/components';
import {
Sidebar,
BasicExampleView,
ProjectCodes,
COMMON_IGNORE_FILES,
EXAMPLE_CODE_URL,
EXAMPLE_PREVIEW_URL,
} from '@/components/exampleView';
import { FILE_INFO } from '@/examples/nextjs-scheduler/fileInfo';

const exampleKey = 'nextjs-scheduler';
const exampleTitle = 'Calendar';

const CalendarExampleView: NextPage = () => {
return (
<ExampleLayout breadcrumbTitle={exampleTitle}>
{() => (
<>
<Head>
<title>{`${exampleTitle} · Yorkie Examples`}</title>
</Head>
<Sidebar wide>
<Sidebar.Tabs defaultTab="code">
<Sidebar.Top>
<Sidebar.TabsList>
<Sidebar.TabsTab value="code">Code</Sidebar.TabsTab>
</Sidebar.TabsList>
</Sidebar.Top>
<Sidebar.TabsPanel value="code">
<Sidebar.GuideTitle>{exampleTitle}</Sidebar.GuideTitle>
<Sidebar.GuideDescription>
This demo shows the real-time collaborative version of the{' '}
<a href="https://quilljs.com/" className="link" target="_blank" rel="noreferrer">
Quill
</a>{' '}
editor with{' '}
<a href="https://yorkie.dev/" className="link" target="_blank" rel="noreferrer">
Yorkie
</a>{' '}
and{' '}
<a href="https://vitejs.dev/" className="link" target="_blank" rel="noreferrer">
Vite
</a>
.
</Sidebar.GuideDescription>
<ProjectCodes
files={FILE_INFO}
activeFile="/app/page.tsx"
ignoreFiles={[...COMMON_IGNORE_FILES, '.env', 'vite.config.js', '/src/vite-env.d.ts']}
/>
</Sidebar.TabsPanel>
<Sidebar.Bottom codeURL={EXAMPLE_CODE_URL + exampleKey} />
</Sidebar.Tabs>
</Sidebar>
<BasicExampleView
rpcAddr={process.env.NEXT_PUBLIC_API_ADDR || ''}
apiKey={process.env.NEXT_PUBLIC_EXAMPLES_API_KEY || ''}
documentKey={exampleKey}
iframeURL={EXAMPLE_PREVIEW_URL + exampleKey}
/>
</>
)}
</ExampleLayout>
);
};
export default CalendarExampleView;
13 changes: 13 additions & 0 deletions pages/examples/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,19 @@ const Examples: NextPage = () => {
</div>
</Link>
</li>
<li className="grid_item">
<Link href="/examples/calendar" className="grid_card">
<div className="grid_thumbnail">
<ExampleThumbnailImage fileName="nextjs-scheduler.jpg" alt="nextjs-scheudler" />
</div>
<div className="grid_card_info">
<strong className="title">Calendar</strong>
<p className="desc">
This demo shows the real-time collaborative version of the Calendar with Yorkie and Next.js.
</p>
</div>
</Link>
</li>
</ul>
</div>
</div>
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 21 additions & 12 deletions utils/exampleFileUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,18 +90,27 @@ export const setFirstFileOpen = (directoryInfo: DirectoryInfo): [DirectoryInfo,
return [directoryInfoResult, openedFileInfo];
};

export const setFileOpen = (directoryInfo: DirectoryInfo, targetFile: string): [DirectoryInfo, FileInfo | null] => {
const cloneDirectoryInfo = cloneDeep(directoryInfo);
let _openedFileInfo: FileInfo | null = null;
cloneDirectoryInfo.children.forEach((child, i) => {
export const setFileOpen = (directoryInfo: DirectoryInfo, targetFilePath: string): [DirectoryInfo, FileInfo | null] => {
const clonedDirectoryInfo = cloneDeep(directoryInfo);
const openedFileInfo = findOpenedFileInfo(clonedDirectoryInfo, targetFilePath);
return [clonedDirectoryInfo, openedFileInfo];
};

const findOpenedFileInfo = (directoryInfo: DirectoryInfo, targetFilePath: string): FileInfo | null => {
let opendFileInfo: FileInfo | null = null;
for (const child of directoryInfo.children) {
if (opendFileInfo != null) {
break;
}
if (child.isFile) {
child.isOpen = child.path === targetFile;
_openedFileInfo = child.path === targetFile ? child : _openedFileInfo;
child.isOpen = child.path === targetFilePath;
if (child.isOpen) {
opendFileInfo = child;
break;
}
} else {
const [childInfo, openedFileInfo] = setFileOpen(child, targetFile);
cloneDirectoryInfo.children[i] = childInfo;
_openedFileInfo = openedFileInfo;
opendFileInfo = opendFileInfo ?? findOpenedFileInfo(child, targetFilePath);
}
});
return [cloneDirectoryInfo, _openedFileInfo];
};
}
return opendFileInfo;
}