Skip to content

Open-source and local-first Slack and Notion alternative that puts you in control of your data

Implement channel and page create from space sidebar node

Hakan Shehud133ebb66924
diff --git a/desktop/src/components/channels/channel-create-dialog.tsx b/desktop/src/components/channels/channel-create-dialog.tsx
new file mode 100644
index 00000000..e7e59c98
--- /dev/null
+++ b/desktop/src/components/channels/channel-create-dialog.tsx
@@ -0,0 +1,150 @@
+import React from 'react';
+import { useWorkspace } from '@/contexts/workspace';
+import {
+ Dialog,
+ DialogContent,
+ DialogDescription,
+ DialogFooter,
+ DialogHeader,
+ DialogTitle,
+} from '@/components/ui/dialog';
+import { z } from 'zod';
+import {
+ Form,
+ FormControl,
+ FormField,
+ FormItem,
+ FormLabel,
+ FormMessage,
+} from '@/components/ui/form';
+import { Input } from '@/components/ui/input';
+import { Button } from '@/components/ui/button';
+import { Spinner } from '@/components/ui/spinner';
+import { useForm } from 'react-hook-form';
+import { zodResolver } from '@hookform/resolvers/zod';
+import { NeuronId } from '@/lib/id';
+import { NodeTypes } from '@/lib/constants';
+import { generateNodeIndex } from '@/lib/nodes';
+import { useMutation } from '@tanstack/react-query';
+import { compareString } from '@/lib/utils';
+
+const formSchema = z.object({
+ name: z.string().min(3, 'Name must be at least 3 characters long.'),
+});
+
+interface ChannelCreateDialogProps {
+ spaceId: string;
+ open: boolean;
+ onOpenChange: (open: boolean) => void;
+}
+
+export const ChannelCreateDialog = ({
+ spaceId,
+ open,
+ onOpenChange,
+}: ChannelCreateDialogProps) => {
+ const workspace = useWorkspace();
+ const form = useForm<z.infer<typeof formSchema>>({
+ resolver: zodResolver(formSchema),
+ defaultValues: {
+ name: '',
+ },
+ });
+
+ const { mutate, isPending } = useMutation({
+ mutationFn: async (values: z.infer<typeof formSchema>) => {
+ const siblingsQuery = workspace.schema
+ .selectFrom('nodes')
+ .where('parent_id', '=', spaceId)
+ .selectAll()
+ .compile();
+
+ const result = await workspace.query(siblingsQuery);
+ const siblings = result.rows;
+ const maxIndex =
+ siblings.length > 0
+ ? siblings.sort((a, b) => compareString(a.index, b.index))[
+ siblings.length - 1
+ ].index
+ : null;
+
+ const index = generateNodeIndex(maxIndex, null);
+ const query = workspace.schema
+ .insertInto('nodes')
+ .values({
+ id: NeuronId.generate(NeuronId.Type.Channel),
+ type: NodeTypes.Channel,
+ parent_id: spaceId,
+ index,
+ attrs: JSON.stringify({
+ name: values.name,
+ }),
+ content: null,
+ created_at: new Date().toISOString(),
+ created_by: workspace.userId,
+ version_id: NeuronId.generate(NeuronId.Type.Version),
+ })
+ .compile();
+
+ await workspace.mutate(query);
+ },
+ });
+
+ const handleCancel = () => {
+ form.reset();
+ onOpenChange(false);
+ };
+
+ const handleSubmit = async (values: z.infer<typeof formSchema>) => {
+ mutate(values, {
+ onSuccess: () => {
+ onOpenChange(false);
+ form.reset();
+ },
+ });
+ };
+
+ return (
+ <Dialog open={open} onOpenChange={onOpenChange}>
+ <DialogContent>
+ <DialogHeader>
+ <DialogTitle>Create channel</DialogTitle>
+ <DialogDescription>
+ Create a new channel to collaborate with your peers
+ </DialogDescription>
+ </DialogHeader>
+ <Form {...form}>
+ <form
+ className="flex flex-col"
+ onSubmit={form.handleSubmit(handleSubmit)}
+ >
+ <div className="flex-grow space-y-4 py-2 pb-4">
+ <FormField
+ control={form.control}
+ name="name"
+ render={({ field }) => (
+ <FormItem className="flex-1">
+ <FormLabel>Name *</FormLabel>
+ <FormControl>
+ <Input placeholder="Name" {...field} />
+ </FormControl>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+ </div>
+ <DialogFooter>
+ <Button variant="outline" onClick={handleCancel}>
+ Cancel
+ </Button>
+ <Button type="submit" disabled={isPending}>
+ {isPending && <Spinner className="mr-1" />}
+ Create
+ </Button>
+ </DialogFooter>
+ </form>
+ </Form>
+ </DialogContent>
+ </Dialog>
+ );
+};
diff --git a/desktop/src/components/messages/message-list.tsx b/desktop/src/components/messages/message-list.tsx
index 3f603b1c..abc394ab 100644
--- a/desktop/src/components/messages/message-list.tsx
+++ b/desktop/src/components/messages/message-list.tsx
@@ -44,34 +44,33 @@ export const MessageList = ({
queryFn: async ({ queryKey, pageParam }) => {
const offset = pageParam * MESSAGES_PER_PAGE;
const query = sql<SelectNode>`
- WITH message_nodes AS (
- SELECT *
- FROM nodes
- WHERE parent_id = ${conversationId} AND type = ${NodeTypes.Message}
- ORDER BY id DESC
- LIMIT ${sql.lit(MESSAGES_PER_PAGE)}
- OFFSET ${sql.lit(offset)}
- ),
- descendant_nodes AS (
- SELECT *
- FROM nodes
- WHERE parent_id IN (SELECT id FROM message_nodes)
+ WITH message_nodes AS (
+ SELECT *
+ FROM nodes
+ WHERE parent_id = ${conversationId} AND type = ${NodeTypes.Message}
+ ORDER BY id DESC
+ LIMIT ${sql.lit(MESSAGES_PER_PAGE)}
+ OFFSET ${sql.lit(offset)}
+ ),
+ descendant_nodes AS (
+ SELECT *
+ FROM nodes
+ WHERE parent_id IN (SELECT id FROM message_nodes)
+ UNION ALL
+ SELECT child.*
+ FROM nodes child
+ INNER JOIN descendant_nodes parent ON child.parent_id = parent.id
+ ),
+ authors AS (
+ SELECT *
+ FROM nodes
+ WHERE id IN (SELECT DISTINCT created_by FROM message_nodes)
+ )
+ SELECT * FROM message_nodes
UNION ALL
- SELECT child.*
- FROM nodes child
- INNER JOIN descendant_nodes parent ON child.parent_id = parent.id
- ),
- authors AS (
- SELECT *
- FROM nodes
- WHERE id IN (SELECT DISTINCT created_by FROM message_nodes)
- )
- SELECT * FROM message_nodes
- UNION ALL
- SELECT * FROM descendant_nodes
- UNION ALL
- SELECT * FROM authors;
-
+ SELECT * FROM descendant_nodes
+ UNION ALL
+ SELECT * FROM authors;
`.compile(workspace.schema);
return await workspace.queryAndSubscribe({
diff --git a/desktop/src/components/pages/page-create-dialog.tsx b/desktop/src/components/pages/page-create-dialog.tsx
new file mode 100644
index 00000000..47449326
--- /dev/null
+++ b/desktop/src/components/pages/page-create-dialog.tsx
@@ -0,0 +1,150 @@
+import React from 'react';
+import { useWorkspace } from '@/contexts/workspace';
+import {
+ Dialog,
+ DialogContent,
+ DialogDescription,
+ DialogFooter,
+ DialogHeader,
+ DialogTitle,
+} from '@/components/ui/dialog';
+import { z } from 'zod';
+import {
+ Form,
+ FormControl,
+ FormField,
+ FormItem,
+ FormLabel,
+ FormMessage,
+} from '@/components/ui/form';
+import { Input } from '@/components/ui/input';
+import { Button } from '@/components/ui/button';
+import { Spinner } from '@/components/ui/spinner';
+import { useForm } from 'react-hook-form';
+import { zodResolver } from '@hookform/resolvers/zod';
+import { NeuronId } from '@/lib/id';
+import { NodeTypes } from '@/lib/constants';
+import { generateNodeIndex } from '@/lib/nodes';
+import { useMutation } from '@tanstack/react-query';
+import { compareString } from '@/lib/utils';
+
+const formSchema = z.object({
+ name: z.string().min(3, 'Name must be at least 3 characters long.'),
+});
+
+interface PageCreateDialogProps {
+ spaceId: string;
+ open: boolean;
+ onOpenChange: (open: boolean) => void;
+}
+
+export const PageCreateDialog = ({
+ spaceId,
+ open,
+ onOpenChange,
+}: PageCreateDialogProps) => {
+ const workspace = useWorkspace();
+ const form = useForm<z.infer<typeof formSchema>>({
+ resolver: zodResolver(formSchema),
+ defaultValues: {
+ name: '',
+ },
+ });
+
+ const { mutate, isPending } = useMutation({
+ mutationFn: async (values: z.infer<typeof formSchema>) => {
+ const siblingsQuery = workspace.schema
+ .selectFrom('nodes')
+ .where('parent_id', '=', spaceId)
+ .selectAll()
+ .compile();
+
+ const result = await workspace.query(siblingsQuery);
+ const siblings = result.rows;
+ const maxIndex =
+ siblings.length > 0
+ ? siblings.sort((a, b) => compareString(a.index, b.index))[
+ siblings.length - 1
+ ].index
+ : null;
+
+ const index = generateNodeIndex(maxIndex, null);
+ const query = workspace.schema
+ .insertInto('nodes')
+ .values({
+ id: NeuronId.generate(NeuronId.Type.Page),
+ type: NodeTypes.Page,
+ parent_id: spaceId,
+ index,
+ attrs: JSON.stringify({
+ name: values.name,
+ }),
+ content: null,
+ created_at: new Date().toISOString(),
+ created_by: workspace.userId,
+ version_id: NeuronId.generate(NeuronId.Type.Version),
+ })
+ .compile();
+
+ await workspace.mutate(query);
+ },
+ });
+
+ const handleCancel = () => {
+ form.reset();
+ onOpenChange(false);
+ };
+
+ const handleSubmit = async (values: z.infer<typeof formSchema>) => {
+ mutate(values, {
+ onSuccess: () => {
+ onOpenChange(false);
+ form.reset();
+ },
+ });
+ };
+
+ return (
+ <Dialog open={open} onOpenChange={onOpenChange}>
+ <DialogContent>
+ <DialogHeader>
+ <DialogTitle>Create page</DialogTitle>
+ <DialogDescription>
+ Create a new page to collaborate with your peers
+ </DialogDescription>
+ </DialogHeader>
+ <Form {...form}>
+ <form
+ className="flex flex-col"
+ onSubmit={form.handleSubmit(handleSubmit)}
+ >
+ <div className="flex-grow space-y-4 py-2 pb-4">
+ <FormField
+ control={form.control}
+ name="name"
+ render={({ field }) => (
+ <FormItem className="flex-1">
+ <FormLabel>Name *</FormLabel>
+ <FormControl>
+ <Input placeholder="Name" {...field} />
+ </FormControl>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+ </div>
+ <DialogFooter>
+ <Button variant="outline" onClick={handleCancel}>
+ Cancel
+ </Button>
+ <Button type="submit" disabled={isPending}>
+ {isPending && <Spinner className="mr-1" />}
+ Create
+ </Button>
+ </DialogFooter>
+ </form>
+ </Form>
+ </DialogContent>
+ </Dialog>
+ );
+};
diff --git a/desktop/src/components/spaces/space-sidebar-node.tsx b/desktop/src/components/spaces/space-sidebar-node.tsx
index 29e6dc21..5bdaf025 100644
--- a/desktop/src/components/spaces/space-sidebar-node.tsx
+++ b/desktop/src/components/spaces/space-sidebar-node.tsx
@@ -4,6 +4,23 @@ import { cn } from '@/lib/utils';
import { Avatar } from '@/components/ui/avatar';
import { Icon } from '@/components/ui/icon';
import { SidebarNodeChildren } from '@/components/workspaces/sidebar-node-children';
+import {
+ DropdownMenu,
+ DropdownMenuContent,
+ DropdownMenuItem,
+ DropdownMenuLabel,
+ DropdownMenuSeparator,
+ DropdownMenuTrigger,
+} from '@/components/ui/dropdown-menu';
+import { getDefaultNodeIcon } from '@/lib/nodes';
+import { NodeTypes } from '@/lib/constants';
+import { ChannelCreateDialog } from '@/components/channels/channel-create-dialog';
+import { PageCreateDialog } from '@/components/pages/page-create-dialog';
+
+interface SettingsState {
+ open: boolean;
+ tab?: string;
+}
interface SpaceSidebarNodeProps {
node: LocalNode;
@@ -11,11 +28,15 @@ interface SpaceSidebarNodeProps {
export const SpaceSidebarNode = ({ node }: SpaceSidebarNodeProps) => {
const [isOpen, setIsOpen] = React.useState(true);
+ const [openCreatePage, setOpenCreatePage] = React.useState(false);
+ const [openCreateChannel, setOpenCreateChannel] = React.useState(false);
+ const [openCreateDatabase, setOpenCreateDatabase] = React.useState(false);
+ const [openCreateFolder, setOpenCreateFolder] = React.useState(false);
+ const [settingsState, setSettingsState] = React.useState<SettingsState>({
+ open: false,
+ });
const isActive = false;
- const isUnread = false;
- const directCount = 0;
-
const avatar = node.attrs.avatar;
const name = node.attrs.name ?? 'Unnamed';
return (
@@ -23,36 +44,92 @@ export const SpaceSidebarNode = ({ node }: SpaceSidebarNodeProps) => {
<div
key={node.id}
className={cn(
- 'flex cursor-pointer items-center rounded-md p-1 text-sm text-foreground/80 hover:bg-gray-100',
+ 'group/sidebar-node flex cursor-pointer items-center rounded-md p-1 text-sm text-foreground/80 hover:bg-gray-100',
isActive && 'bg-gray-100',
)}
>
<Avatar id={node.id} avatar={avatar} name={name} size="small" />
<span
- className={cn(
- 'line-clamp-1 w-full flex-grow pl-2 text-left',
- isUnread && 'font-bold',
- )}
+ className="line-clamp-1 w-full flex-grow pl-2 text-left"
+ onClick={() => setIsOpen(!isOpen)}
>
{name}
</span>
- {directCount > 0 && (
- <span className="mr-1 rounded-md bg-red-500 px-1 py-0.5 text-xs text-white">
- {directCount}
- </span>
- )}
- {directCount == 0 && isUnread && (
- <Icon
- name="checkbox-blank-circle-fill"
- className="mr-2 h-3 w-3 p-0.5 text-red-500"
- />
- )}
+ <DropdownMenu>
+ <DropdownMenuTrigger asChild>
+ <span className="flex h-5 w-5 cursor-pointer items-center justify-center rounded-md p-1 opacity-0 hover:bg-gray-200 hover:text-primary group-hover/sidebar-node:opacity-100">
+ <Icon name="more-line" />
+ </span>
+ </DropdownMenuTrigger>
+ <DropdownMenuContent className="ml-1 w-72">
+ <DropdownMenuLabel>{name}</DropdownMenuLabel>
+ <DropdownMenuSeparator />
+ <DropdownMenuItem onSelect={() => setOpenCreatePage(true)}>
+ <div className="flex flex-row items-center gap-2">
+ <Icon name={getDefaultNodeIcon(NodeTypes.Page)} />
+ <span>Add page</span>
+ </div>
+ </DropdownMenuItem>
+ <DropdownMenuItem onSelect={() => setOpenCreateChannel(true)}>
+ <div className="flex flex-row items-center gap-2">
+ <Icon name={getDefaultNodeIcon(NodeTypes.Channel)} />
+ <span>Add channel</span>
+ </div>
+ </DropdownMenuItem>
+ <DropdownMenuItem onSelect={() => setOpenCreateDatabase(true)}>
+ <div className="flex flex-row items-center gap-2">
+ <Icon name={getDefaultNodeIcon(NodeTypes.Database)} />
+ <span>Add database</span>
+ </div>
+ </DropdownMenuItem>
+ <DropdownMenuItem onSelect={() => setOpenCreateFolder(true)}>
+ <div className="flex flex-row items-center gap-2">
+ <Icon name={getDefaultNodeIcon(NodeTypes.Folder)} />
+ <span>Add folder</span>
+ </div>
+ </DropdownMenuItem>
+ <DropdownMenuSeparator />
+ <DropdownMenuItem onClick={() => setSettingsState({ open: true })}>
+ <div className="flex flex-row items-center gap-2">
+ <Icon name="settings-3-line" />
+ <span>Settings</span>
+ </div>
+ </DropdownMenuItem>
+ <DropdownMenuItem
+ onClick={() =>
+ setSettingsState({
+ open: true,
+ tab: 'collaborators',
+ })
+ }
+ >
+ <div className="flex flex-row items-center gap-2">
+ <Icon name="user-add-line" />
+ <span>Add collaborators</span>
+ </div>
+ </DropdownMenuItem>
+ </DropdownMenuContent>
+ </DropdownMenu>
</div>
{isOpen && (
<div className="pl-4">
<SidebarNodeChildren node={node} />
</div>
)}
+ {openCreateChannel && (
+ <ChannelCreateDialog
+ spaceId={node.id}
+ open={openCreateChannel}
+ onOpenChange={setOpenCreateChannel}
+ />
+ )}
+ {openCreatePage && (
+ <PageCreateDialog
+ spaceId={node.id}
+ open={openCreatePage}
+ onOpenChange={setOpenCreatePage}
+ />
+ )}
</React.Fragment>
);
};
diff --git a/desktop/src/components/workspaces/sidebar-node-children.tsx b/desktop/src/components/workspaces/sidebar-node-children.tsx
index 9cc1f1af..847ff284 100644
--- a/desktop/src/components/workspaces/sidebar-node-children.tsx
+++ b/desktop/src/components/workspaces/sidebar-node-children.tsx
@@ -2,7 +2,7 @@ import React from 'react';
import { LocalNode } from '@/types/nodes';
import { SidebarNode } from '@/components/workspaces/sidebar-node';
import { useSidebar } from '@/contexts/sidebar';
-import { compareNodeIndex } from '@/lib/nodes';
+import { compareString } from '@/lib/utils';
interface SidebarNodeChildrenProps {
node: LocalNode;
@@ -12,7 +12,7 @@ export const SidebarNodeChildren = ({ node }: SidebarNodeChildrenProps) => {
const sidebar = useSidebar();
const children: LocalNode[] = sidebar.nodes
.filter((n) => n.parentId === node.id)
- .sort((a, b) => compareNodeIndex(a, b));
+ .sort((a, b) => compareString(a.index, b.index));
return (
<React.Fragment>
diff --git a/desktop/src/editor/observer.ts b/desktop/src/editor/observer.ts
index 65833fae..66b6723e 100644
--- a/desktop/src/editor/observer.ts
+++ b/desktop/src/editor/observer.ts
@@ -1,7 +1,8 @@
import { WorkspaceDatabaseSchema } from '@/data/schemas/workspace';
import { LeafNodeTypes } from '@/lib/constants';
import { NeuronId } from '@/lib/id';
-import { compareNodeIndex, generateNodeIndex } from '@/lib/nodes';
+import { generateNodeIndex } from '@/lib/nodes';
+import { compareString } from '@/lib/utils';
import { LocalNode, NodeBlock } from '@/types/nodes';
import { Workspace } from '@/types/workspaces';
import { Editor, JSONContent } from '@tiptap/core';
@@ -57,7 +58,7 @@ export class EditorObserver {
const contents: JSONContent[] = [];
const childrenNodes = nodesArray
.filter((node) => node.parentId === this.rootNode.id)
- .sort((a, b) => compareNodeIndex(a, b));
+ .sort((a, b) => compareString(a.index, b.index));
for (const child of childrenNodes) {
const content = this.buildEditorContentFromNode(child, nodesArray);
@@ -90,7 +91,7 @@ export class EditorObserver {
const childrenNodes = nodesArray
.filter((n) => n.parentId === node.id)
- .sort((a, b) => compareNodeIndex(a, b));
+ .sort((a, b) => compareString(a.index, b.index));
if (childrenNodes.length > 0) {
editorContent.content = editorContent.content || [];
diff --git a/desktop/src/lib/constants.ts b/desktop/src/lib/constants.ts
index 4e37e649..5f24a363 100644
--- a/desktop/src/lib/constants.ts
+++ b/desktop/src/lib/constants.ts
@@ -14,6 +14,9 @@ export const NodeTypes = {
TaskList: 'taskList',
TaskItem: 'taskItem',
HorizontalRule: 'horizontalRule',
+ Database: 'database',
+ Record: 'record',
+ Folder: 'folder',
};
export const LeafNodeTypes: string[] = [
diff --git a/desktop/src/lib/messages.ts b/desktop/src/lib/messages.ts
index a6d29e58..36a40577 100644
--- a/desktop/src/lib/messages.ts
+++ b/desktop/src/lib/messages.ts
@@ -3,12 +3,9 @@ import { JSONContent } from '@tiptap/core';
import { NeuronId } from '@/lib/id';
import { LocalNode, NodeBlock } from '@/types/nodes';
import { LeafNodeTypes, NodeTypes } from '@/lib/constants';
-import {
- buildNodeWithChildren,
- compareNodeId,
- generateNodeIndex,
-} from '@/lib/nodes';
+import { buildNodeWithChildren, generateNodeIndex } from '@/lib/nodes';
import { MessageNode } from '@/types/messages';
+import { compareString } from './utils';
export const buildMessageCreateNodes = (
nodes: CreateNode[],
@@ -74,9 +71,9 @@ export const buildMessageCreateNodes = (
};
export const buildMessages = (allNodes: LocalNode[]): MessageNode[] => {
- const messageNodes = allNodes
- .filter((node) => node.type === NodeTypes.Message)
- .sort((a, b) => compareNodeId(a, b));
+ const messageNodes = allNodes.filter(
+ (node) => node.type === NodeTypes.Message,
+ );
const authorNodes = allNodes.filter((node) => node.type === NodeTypes.User);
const messages: MessageNode[] = [];
@@ -97,5 +94,5 @@ export const buildMessages = (allNodes: LocalNode[]): MessageNode[] => {
messages.push(message);
}
- return messages.sort((a, b) => compareNodeId(a, b));
+ return messages.sort((a, b) => compareString(a.id, b.id));
};
diff --git a/desktop/src/lib/nodes.ts b/desktop/src/lib/nodes.ts
index 91608f9e..e854d6f5 100644
--- a/desktop/src/lib/nodes.ts
+++ b/desktop/src/lib/nodes.ts
@@ -1,6 +1,7 @@
import { SelectNode } from '@/data/schemas/workspace';
import { LocalNode, LocalNodeWithChildren } from '@/types/nodes';
import { generateKeyBetween } from 'fractional-indexing-jittered';
+import { NodeTypes } from '@/lib/constants';
export const buildNodeWithChildren = (
node: LocalNode,
@@ -45,22 +46,21 @@ export const mapNode = (row: SelectNode): LocalNode => {
};
};
-export const compareNodeIndex = (a: LocalNode, b: LocalNode): number => {
- if (a.index < b.index) {
- return -1;
- } else if (a.index > b.index) {
- return 1;
+export const getDefaultNodeIcon = (type: string) => {
+ switch (type) {
+ case NodeTypes.Channel:
+ return 'discuss-line';
+ case NodeTypes.Page:
+ return 'book-line';
+ case NodeTypes.Database:
+ return 'database-2-line';
+ case NodeTypes.Record:
+ return 'article-line';
+ case NodeTypes.Folder:
+ return 'folder-open-line';
+ case NodeTypes.Space:
+ return 'team-line';
+ default:
+ return 'file-unknown-line';
}
-
- return 0;
-};
-
-export const compareNodeId = (a: LocalNode, b: LocalNode): number => {
- if (a.id < b.id) {
- return -1;
- } else if (a.id > b.id) {
- return 1;
- }
-
- return 0;
};
diff --git a/desktop/src/lib/utils.ts b/desktop/src/lib/utils.ts
index 32b1b90e..bedc7bef 100644
--- a/desktop/src/lib/utils.ts
+++ b/desktop/src/lib/utils.ts
@@ -105,3 +105,19 @@ export const formatDate = (dateParam: Date | string | undefined): string => {
return `${monthNames[monthIndex]} ${day}, ${year} at ${hour}:${minute}`;
};
+
+export const compareString = (a?: string | null, b?: string | null): number => {
+ if (a === b) {
+ return 0;
+ }
+
+ if (a === undefined || a === null) {
+ return -1;
+ }
+
+ if (b === undefined || b === null) {
+ return 1;
+ }
+
+ return a.localeCompare(b);
+};