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

bookmarks: setup user_query support #7995

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from
27 changes: 26 additions & 1 deletion src/packages/frontend/project/page/flyouts/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import { merge, sortBy, throttle, uniq, xor } from "lodash";
import { useState } from "react";
import useAsyncEffect from "use-async-effect";

import { useTypedRedux } from "@cocalc/frontend/app-framework";
import api from "@cocalc/frontend/client/api";
import { webapp_client } from "@cocalc/frontend/webapp-client";
import { STARRED_FILES } from "@cocalc/util/consts/bookmarks";
import {
GetStarredBookmarks,
Expand All @@ -25,6 +27,8 @@ import {
// The only really important situation to think of are when there is nothing in local storage but in the database,
// or when there is
export function useStarredFilesManager(project_id: string) {
const account_id = useTypedRedux("account", "account_id");

const [starred, setStarred] = useState<FlyoutActiveStarred>(
getFlyoutActiveStarred(project_id),
);
Expand Down Expand Up @@ -55,7 +59,17 @@ export function useStarredFilesManager(project_id: string) {
project_id,
stars,
};
await api("bookmarks/set", payload);
//await api("bookmarks/set", payload);

const data = await webapp_client.async_query({
query: {
bookmarks: {
...payload,
account_id,
},
},
});
console.log("save starred files", data);
} catch (err) {
console.error("api error", err);
}
Expand All @@ -72,6 +86,17 @@ export function useStarredFilesManager(project_id: string) {
};
const data: GetStarredBookmarks = await api("bookmarks/get", payload);

const data2 = await webapp_client.async_query({
query: {
bookmarks: {
...payload,
type: STARRED_FILES,
stars: null,
},
},
});
console.log({ data, data2 });

const { type, status } = data;

if (type !== STARRED_FILES) {
Expand Down
2 changes: 2 additions & 0 deletions src/packages/util/consts/bookmarks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ export const MAX_STARS = 256;
export const MAX_LENGTH_STAR = 2048;
// the type of bookmark for starring files
export const STARRED_FILES = "starred-files";
// all allowed types (right now just one)
export const BOOKMARK_TYPES = [STARRED_FILES] as const;
42 changes: 40 additions & 2 deletions src/packages/util/db-schema/bookmarks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
* License: MS-RSL – see LICENSE.md for details
*/

import { Table } from "./types";
import { BOOKMARK_TYPES } from "@cocalc/util/consts/bookmarks";

import { ID } from "./crm";
import { Table } from "./types";

// This table stores various types of bookmarks. This started with backing up starred tabs for a user in a project.
Table({
Expand Down Expand Up @@ -41,6 +43,42 @@ Table({
desc: "Table for various types of bookmarks.",
primary_key: "id",
pg_indexes: ["type", "project_id", "account_id"],
user_query: {},
user_query: {
get: {
pg_where: [
{
"project_id = $::UUID": "project_id",
"account_id = $::UUID": "account_id",
"type = $::TEXT": "type",
},
],
fields: {
id: null,
type: null,
project_id: null,
account_id: null,
path: null,
stars: null,
last_edited: null,
},
},
set: {
fields: {
type: true,
project_id: "project_write",
account_id: "account_id",
path: true,
stars: true,
},
async check_hook(_db, obj, _account_id, _project_id, cb) {
const type = obj.type;
if (!BOOKMARK_TYPES.includes(type)) {
cb("type '${type} is invalid");
return;
}
cb();
},
},
},
},
});
Loading