Skip to content

Commit

Permalink
Add nextjs-scheduler example and bump up examples to v0.4.7 (#106)
Browse files Browse the repository at this point in the history
* Bump up examples to v0.4.7

* Add nextjs-scheduler example

* Prevent fileinfo being overwritten with null when selecting a file

---------

Co-authored-by: blurfx <[email protected]>
  • Loading branch information
hackerwins and blurfx authored Oct 21, 2023
1 parent eab9f38 commit a3110a2
Show file tree
Hide file tree
Showing 12 changed files with 113 additions and 18 deletions.
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;
}

0 comments on commit a3110a2

Please sign in to comment.