Skip to content

Commit

Permalink
Disable populating private IDs
Browse files Browse the repository at this point in the history
We need to refine them before using them by default.
  • Loading branch information
dfahlander committed Dec 19, 2021
1 parent a765d3a commit e865e80
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 17 deletions.
32 changes: 17 additions & 15 deletions samples/dexie-cloud-todo-app/src/components/TodoItemView.tsx
Original file line number Diff line number Diff line change
@@ -1,36 +1,38 @@
import React, { useEffect, useState } from "react";
import { db } from "../db";
import { TodoItem } from "../db/TodoItem";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { faTrash } from "@fortawesome/free-solid-svg-icons";
import { usePermissions } from "dexie-react-hooks";
import React, { useEffect, useState } from 'react';
import { db } from '../db';
import { TodoItem } from '../db/TodoItem';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faTrash } from '@fortawesome/free-solid-svg-icons';
import { usePermissions } from 'dexie-react-hooks';

interface Props {
item: TodoItem;
}

export function TodoItemView({ item }: Props) {
const can = usePermissions(db, "todoItems", item);
console.log("TodoItem", item.title, item.owner, item.realmId);
const can = usePermissions(db, 'todoItems', item);
console.log('TodoItem', item.title, item.owner, item.realmId);
return (
<div className={"row " + (item.done ? "done" : "")}>
<div className={'row ' + (item.done ? 'done' : '')}>
<div className="narrow">
<input
type="checkbox"
disabled={!can.update("done")}
disabled={!can.update('done')}
checked={!!item.done}
onChange={ev =>
onChange={(ev) => {
db.todoItems.update(item.id, {
done: ev.target.checked
})
}
done: ev.target.checked,
});
}}
/>
</div>
<div className="todo-item-text">{item.title}</div>
<div className="todo-item-trash">
<button
disabled={!can.delete()}
onClick={() => db.todoItems.delete(item.id!)} title="Delete item">
onClick={() => db.todoItems.delete(item.id!)}
title="Delete item"
>
<FontAwesomeIcon icon={faTrash} />
</button>
</div>
Expand Down
8 changes: 6 additions & 2 deletions samples/dexie-cloud-todo-app/src/db/populate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ export function populate(db: TodoDB) {
// 3. Alice logs in --> items are synced to cloud and replaces existing ones for Alice
// but that does not matter as they have the same IDs. The items that
// Alice added on other device is now synced back.
const todoListId = `#tdl-defaultTodoList`;

// Private IDs are possible to test but does not behave optimally yet (as of 2021-12-19)
// Need to refine how they sync before using them by default.
// If you want to try, uncomment the code below:
/*const todoListId = `#tdl-defaultTodoList`;
return db.transaction('rw', db.todoLists, db.todoItems, () => {
db.todoLists.add({
id: todoListId,
Expand All @@ -49,5 +53,5 @@ export function populate(db: TodoDB) {
todoListId,
},
]);
});
});*/
}

0 comments on commit e865e80

Please sign in to comment.