Add favorites and recently visited pages
Pages can be starred from their header; favorites show in the sidebar above the spaces, and Home lists the pages visited last. Both are per user and per workspace, and are filtered by the caller's current rights, so pages that moved out of reach or into the trash drop out. Visits are trimmed to the newest 50 per workspace. The icon set gains the glyphs the rest of Phase 1 needs, and DwIcon can draw a filled variant for on/off states. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
34660c6b46
commit
b0e36fcfaf
19 files changed
+804
-13
No files matched your search
@@ -0,0 +1,59 @@
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
/// <reference path="../pb_data/types.d.ts" />
|
||||
|
||||
// Per-user favorites and recently visited pages. workspace is copied from the
|
||||
// page so the sidebar can list one workspace's entries without a join.
|
||||
|
||||
migrate(
|
||||
(app) => {
|
||||
const users = app.findCollectionByNameOrId("users");
|
||||
const pages = app.findCollectionByNameOrId("pages");
|
||||
const workspaces = app.findCollectionByNameOrId("workspaces");
|
||||
const refs = () => [
|
||||
{ name: "user", type: "relation", collectionId: users.id, maxSelect: 1, required: true, cascadeDelete: true },
|
||||
{ name: "page", type: "relation", collectionId: pages.id, maxSelect: 1, required: true, cascadeDelete: true },
|
||||
{ name: "workspace", type: "relation", collectionId: workspaces.id, maxSelect: 1, required: true, cascadeDelete: true },
|
||||
];
|
||||
|
||||
app.save(
|
||||
new Collection({
|
||||
type: "base",
|
||||
name: "favorites",
|
||||
fields: [
|
||||
...refs(),
|
||||
{ name: "created", type: "autodate", onCreate: true, onUpdate: false },
|
||||
{ name: "updated", type: "autodate", onCreate: true, onUpdate: true },
|
||||
],
|
||||
indexes: [
|
||||
"CREATE UNIQUE INDEX idx_favorites_unique ON favorites (user, page)",
|
||||
"CREATE INDEX idx_favorites_list ON favorites (user, workspace)",
|
||||
],
|
||||
}),
|
||||
);
|
||||
|
||||
app.save(
|
||||
new Collection({
|
||||
type: "base",
|
||||
name: "page_visits",
|
||||
fields: [
|
||||
...refs(),
|
||||
{ name: "visited", type: "date", required: true },
|
||||
{ name: "created", type: "autodate", onCreate: true, onUpdate: false },
|
||||
{ name: "updated", type: "autodate", onCreate: true, onUpdate: true },
|
||||
],
|
||||
indexes: [
|
||||
"CREATE UNIQUE INDEX idx_page_visits_unique ON page_visits (user, page)",
|
||||
"CREATE INDEX idx_page_visits_list ON page_visits (user, workspace, visited)",
|
||||
],
|
||||
}),
|
||||
);
|
||||
},
|
||||
(app) => {
|
||||
for (const name of ["page_visits", "favorites"]) {
|
||||
try {
|
||||
app.delete(app.findCollectionByNameOrId(name));
|
||||
} catch (_) {}
|
||||
}
|
||||
},
|
||||
);
|
||||
@@ -34,6 +34,7 @@ export type InstanceSettings = Schemas["InstanceSettings"];
|
||||
export type InstanceSettingsUpdate = Schemas["InstanceSettingsUpdate"];
|
||||
export type Invite = Schemas["Invite"];
|
||||
export type Group = Schemas["Group"];
|
||||
export type PageItem = Schemas["PageItem"];
|
||||
export type GroupRequest = Schemas["GroupRequest"];
|
||||
export type SpaceGroup = Schemas["SpaceGroup"];
|
||||
export type MemberUser = Schemas["MemberUser"];
|
||||
@@ -180,6 +181,9 @@ export function createClient(opts: ClientOptions) {
|
||||
createSpace: (id: string, input: CreateSpaceRequest) =>
|
||||
post<Space>(`/api/v1/workspaces/${encodeURIComponent(id)}/spaces`, input),
|
||||
groups: (id: string) => request<Group[]>("GET", `/api/v1/workspaces/${encodeURIComponent(id)}/groups`),
|
||||
favorites: (id: string) => request<PageItem[]>("GET", `/api/v1/workspaces/${encodeURIComponent(id)}/favorites`),
|
||||
recent: (id: string, limit?: number) =>
|
||||
request<PageItem[]>("GET", `/api/v1/workspaces/${encodeURIComponent(id)}/recent${query({ limit })}`),
|
||||
createGroup: (id: string, input: GroupRequest) =>
|
||||
post<Group>(`/api/v1/workspaces/${encodeURIComponent(id)}/groups`, input),
|
||||
},
|
||||
@@ -237,6 +241,10 @@ export function createClient(opts: ClientOptions) {
|
||||
post<Page>(`/api/v1/pages/${encodeURIComponent(id)}/move`, { parent, index }),
|
||||
trash: (id: string) => request<void>("DELETE", `/api/v1/pages/${encodeURIComponent(id)}`),
|
||||
restore: (id: string) => post<Page>(`/api/v1/pages/${encodeURIComponent(id)}/restore`),
|
||||
setFavorite: (id: string, on: boolean) =>
|
||||
request<void>(on ? "PUT" : "DELETE", `/api/v1/pages/${encodeURIComponent(id)}/favorite`),
|
||||
/** Records that the user opened the page, for their recent list. */
|
||||
visit: (id: string) => post(`/api/v1/pages/${encodeURIComponent(id)}/visit`),
|
||||
purge: (id: string) => request<void>("DELETE", `/api/v1/pages/${encodeURIComponent(id)}?permanent=true`),
|
||||
},
|
||||
};
|
||||
|
||||
Vendored
+199
@@ -966,6 +966,83 @@ export interface paths {
|
||||
patch?: never;
|
||||
trace?: never;
|
||||
};
|
||||
"/api/v1/workspaces/{id}/favorites": {
|
||||
parameters: {
|
||||
query?: never;
|
||||
header?: never;
|
||||
path: {
|
||||
id: string;
|
||||
};
|
||||
cookie?: never;
|
||||
};
|
||||
/** The caller's favorite pages in the workspace, newest first */
|
||||
get: operations["listFavorites"];
|
||||
put?: never;
|
||||
post?: never;
|
||||
delete?: never;
|
||||
options?: never;
|
||||
head?: never;
|
||||
patch?: never;
|
||||
trace?: never;
|
||||
};
|
||||
"/api/v1/workspaces/{id}/recent": {
|
||||
parameters: {
|
||||
query?: never;
|
||||
header?: never;
|
||||
path: {
|
||||
id: string;
|
||||
};
|
||||
cookie?: never;
|
||||
};
|
||||
/** Pages the caller visited last in the workspace */
|
||||
get: operations["listRecentPages"];
|
||||
put?: never;
|
||||
post?: never;
|
||||
delete?: never;
|
||||
options?: never;
|
||||
head?: never;
|
||||
patch?: never;
|
||||
trace?: never;
|
||||
};
|
||||
"/api/v1/pages/{id}/favorite": {
|
||||
parameters: {
|
||||
query?: never;
|
||||
header?: never;
|
||||
path: {
|
||||
id: string;
|
||||
};
|
||||
cookie?: never;
|
||||
};
|
||||
get?: never;
|
||||
/** Add the page to the caller's favorites */
|
||||
put: operations["addFavorite"];
|
||||
post?: never;
|
||||
/** Remove the page from the caller's favorites */
|
||||
delete: operations["removeFavorite"];
|
||||
options?: never;
|
||||
head?: never;
|
||||
patch?: never;
|
||||
trace?: never;
|
||||
};
|
||||
"/api/v1/pages/{id}/visit": {
|
||||
parameters: {
|
||||
query?: never;
|
||||
header?: never;
|
||||
path: {
|
||||
id: string;
|
||||
};
|
||||
cookie?: never;
|
||||
};
|
||||
get?: never;
|
||||
put?: never;
|
||||
/** Note that the caller opened the page (for the recent list) */
|
||||
post: operations["recordPageVisit"];
|
||||
delete?: never;
|
||||
options?: never;
|
||||
head?: never;
|
||||
patch?: never;
|
||||
trace?: never;
|
||||
};
|
||||
}
|
||||
export type webhooks = Record<string, never>;
|
||||
export interface components {
|
||||
@@ -1115,6 +1192,8 @@ export interface components {
|
||||
/** @description Root first */
|
||||
ancestors: components["schemas"]["PageRef"][];
|
||||
role: components["schemas"]["SpaceRole"];
|
||||
/** @description In the caller's favorites */
|
||||
favorite: boolean;
|
||||
};
|
||||
PageContent: {
|
||||
/** @description Tiptap JSON with type "doc"; null for a page that was never edited */
|
||||
@@ -1307,6 +1386,15 @@ export interface components {
|
||||
};
|
||||
role: components["schemas"]["SpaceRole"];
|
||||
};
|
||||
PageItem: {
|
||||
id: string;
|
||||
title: string;
|
||||
icon: string;
|
||||
space: string;
|
||||
spaceName: string;
|
||||
/** @description When it was favorited */
|
||||
at: string;
|
||||
};
|
||||
};
|
||||
responses: {
|
||||
/** @description Signed in */
|
||||
@@ -3118,4 +3206,115 @@ export interface operations {
|
||||
404: components["responses"]["Error"];
|
||||
};
|
||||
};
|
||||
listFavorites: {
|
||||
parameters: {
|
||||
query?: never;
|
||||
header?: never;
|
||||
path: {
|
||||
id: string;
|
||||
};
|
||||
cookie?: never;
|
||||
};
|
||||
requestBody?: never;
|
||||
responses: {
|
||||
/** @description OK */
|
||||
200: {
|
||||
headers: {
|
||||
[name: string]: unknown;
|
||||
};
|
||||
content: {
|
||||
"application/json": components["schemas"]["PageItem"][];
|
||||
};
|
||||
};
|
||||
404: components["responses"]["Error"];
|
||||
};
|
||||
};
|
||||
listRecentPages: {
|
||||
parameters: {
|
||||
query?: {
|
||||
limit?: number;
|
||||
};
|
||||
header?: never;
|
||||
path: {
|
||||
id: string;
|
||||
};
|
||||
cookie?: never;
|
||||
};
|
||||
requestBody?: never;
|
||||
responses: {
|
||||
/** @description OK */
|
||||
200: {
|
||||
headers: {
|
||||
[name: string]: unknown;
|
||||
};
|
||||
content: {
|
||||
"application/json": components["schemas"]["PageItem"][];
|
||||
};
|
||||
};
|
||||
404: components["responses"]["Error"];
|
||||
};
|
||||
};
|
||||
addFavorite: {
|
||||
parameters: {
|
||||
query?: never;
|
||||
header?: never;
|
||||
path: {
|
||||
id: string;
|
||||
};
|
||||
cookie?: never;
|
||||
};
|
||||
requestBody?: never;
|
||||
responses: {
|
||||
/** @description Added */
|
||||
204: {
|
||||
headers: {
|
||||
[name: string]: unknown;
|
||||
};
|
||||
content?: never;
|
||||
};
|
||||
404: components["responses"]["Error"];
|
||||
};
|
||||
};
|
||||
removeFavorite: {
|
||||
parameters: {
|
||||
query?: never;
|
||||
header?: never;
|
||||
path: {
|
||||
id: string;
|
||||
};
|
||||
cookie?: never;
|
||||
};
|
||||
requestBody?: never;
|
||||
responses: {
|
||||
/** @description Removed */
|
||||
204: {
|
||||
headers: {
|
||||
[name: string]: unknown;
|
||||
};
|
||||
content?: never;
|
||||
};
|
||||
404: components["responses"]["Error"];
|
||||
};
|
||||
};
|
||||
recordPageVisit: {
|
||||
parameters: {
|
||||
query?: never;
|
||||
header?: never;
|
||||
path: {
|
||||
id: string;
|
||||
};
|
||||
cookie?: never;
|
||||
};
|
||||
requestBody?: never;
|
||||
responses: {
|
||||
/** @description Recorded */
|
||||
204: {
|
||||
headers: {
|
||||
[name: string]: unknown;
|
||||
};
|
||||
content?: never;
|
||||
};
|
||||
404: components["responses"]["Error"];
|
||||
};
|
||||
};
|
||||
}
|
||||
@@ -4,7 +4,10 @@ import { computed } from "vue";
|
||||
import { iconPaths, type IconName } from "./icons";
|
||||
|
||||
// 16 in tree rows and small buttons, 18 in buttons, 20 in callouts and menus.
|
||||
const props = withDefaults(defineProps<{ name: IconName; size?: number; label?: string }>(), { size: 18 });
|
||||
// filled paints the shape too, for on/off states such as a favorite star.
|
||||
const props = withDefaults(defineProps<{ name: IconName; size?: number; label?: string; filled?: boolean }>(), {
|
||||
size: 18,
|
||||
});
|
||||
const paths = computed(() => iconPaths[props.name] ?? iconPaths.page);
|
||||
</script>
|
||||
|
||||
@@ -14,7 +17,7 @@ const paths = computed(() => iconPaths[props.name] ?? iconPaths.page);
|
||||
:width="size"
|
||||
:height="size"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
:fill="filled ? 'currentColor' : 'none'"
|
||||
stroke="currentColor"
|
||||
stroke-width="1.75"
|
||||
stroke-linecap="round"
|
||||
|
||||
@@ -50,6 +50,38 @@ export const iconPaths = {
|
||||
moon: ["M19.5 14.5A8 8 0 0 1 9.5 4.5a8 8 0 1 0 10 10z"],
|
||||
monitor: ["M4 5h16v11H4z", "M9 20h6", "M12 16v4"],
|
||||
selector: ["M8 9l4-4 4 4", "M8 15l4 4 4-4"],
|
||||
// Phase 1: favorites, sharing, files, comments and editor formatting.
|
||||
star: ["M12 4l2.5 5.2 5.5.8-4 3.9.9 5.6L12 16.9l-4.9 2.6.9-5.6-4-3.9 5.5-.8z"],
|
||||
clock: ["M12 3a9 9 0 1 0 0 18a9 9 0 1 0 0-18z", "M12 7v5l3 2"],
|
||||
share: ["M12 4v11", "M8 8l4-4 4 4", "M6 13v7h12v-7"],
|
||||
link: ["M10 14a4 4 0 0 0 5.7 0l3-3a4 4 0 0 0-5.7-5.7l-1 1", "M14 10a4 4 0 0 0-5.7 0l-3 3a4 4 0 0 0 5.7 5.7l1-1"],
|
||||
upload: ["M12 16V4", "M7 9l5-5 5 5", "M4 20h16"],
|
||||
download: ["M12 4v12", "M7 11l5 5 5-5", "M4 20h16"],
|
||||
file: ["M6 3h8l4 4v14H6z", "M14 3v4h4"],
|
||||
paperclip: ["M18 11.5l-6.4 6.4a4.2 4.2 0 0 1-6-6l7-7a2.8 2.8 0 0 1 4 4l-7 7a1.4 1.4 0 0 1-2-2l6.4-6.4"],
|
||||
comment: ["M5 5h14v10H9l-4 4z"],
|
||||
at: ["M12 8a4 4 0 1 0 0 8a4 4 0 1 0 0-8z", "M16 12v1.5a2.5 2.5 0 0 0 5 0V12a9 9 0 1 0-3.5 7.1"],
|
||||
bold: ["M7 5h6a3.5 3.5 0 0 1 0 7H7z", "M7 12h7a3.5 3.5 0 0 1 0 7H7z"],
|
||||
italic: ["M10 5h8", "M6 19h8", "M14 5l-4 14"],
|
||||
strike: [
|
||||
"M5 12h14",
|
||||
"M16 7.5A3.5 3 0 0 0 12.5 5h-1A3.5 3 0 0 0 8 8c0 4 8 3 8 7.5a3.5 3.5 0 0 1-3.5 3.5h-1A3.5 3 0 0 1 8 16.5",
|
||||
],
|
||||
underline: ["M7 4v7a5 5 0 0 0 10 0V4", "M5 20h14"],
|
||||
"list-ordered": ["M10 6h10", "M10 12h10", "M10 18h10", "M4 5l1.5-1v5", "M4 15.5a1.5 1.5 0 0 1 3 .5L4 19h3"],
|
||||
divider: ["M4 12h16"],
|
||||
globe: [
|
||||
"M12 3a9 9 0 1 0 0 18a9 9 0 1 0 0-18z",
|
||||
"M3 12h18",
|
||||
"M12 3c2.5 2.5 3.5 5.5 3.5 9s-1 6.5-3.5 9",
|
||||
"M12 3C9.5 5.5 8.5 8.5 8.5 12s1 6.5 3.5 9",
|
||||
],
|
||||
users: [
|
||||
"M9 11a3.5 3.5 0 1 0 0-7a3.5 3.5 0 1 0 0 7z",
|
||||
"M3 20a6 6 0 0 1 12 0",
|
||||
"M16 4.5a3.5 3.5 0 0 1 0 6.5",
|
||||
"M18 14a6 6 0 0 1 3 6",
|
||||
],
|
||||
} as const;
|
||||
|
||||
export type IconName = keyof typeof iconPaths;
|
||||
@@ -635,6 +635,7 @@ class Page {
|
||||
required this.inTrash,
|
||||
required this.ancestors,
|
||||
required this.role,
|
||||
required this.favorite,
|
||||
});
|
||||
|
||||
factory Page.fromJson(Map<String, dynamic> json) => Page(
|
||||
@@ -652,6 +653,7 @@ class Page {
|
||||
.map((e) => PageRef.fromJson(e as Map<String, dynamic>))
|
||||
.toList(),
|
||||
role: SpaceRole.fromJson(json['role'] as String),
|
||||
favorite: json['favorite'] as bool,
|
||||
);
|
||||
|
||||
final String id;
|
||||
@@ -681,6 +683,9 @@ class Page {
|
||||
|
||||
final SpaceRole role;
|
||||
|
||||
/// In the caller's favorites
|
||||
final bool favorite;
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
'id': id,
|
||||
'workspace': workspace,
|
||||
@@ -694,6 +699,7 @@ class Page {
|
||||
'inTrash': inTrash,
|
||||
'ancestors': ancestors.map((e) => e.toJson()).toList(),
|
||||
'role': role.toJson(),
|
||||
'favorite': favorite,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1558,3 +1564,45 @@ class SpaceGroup {
|
||||
'role': role.toJson(),
|
||||
};
|
||||
}
|
||||
|
||||
class PageItem {
|
||||
const PageItem({
|
||||
required this.id,
|
||||
required this.title,
|
||||
required this.icon,
|
||||
required this.space,
|
||||
required this.spaceName,
|
||||
required this.at,
|
||||
});
|
||||
|
||||
factory PageItem.fromJson(Map<String, dynamic> json) => PageItem(
|
||||
id: json['id'] as String,
|
||||
title: json['title'] as String,
|
||||
icon: json['icon'] as String,
|
||||
space: json['space'] as String,
|
||||
spaceName: json['spaceName'] as String,
|
||||
at: json['at'] as String,
|
||||
);
|
||||
|
||||
final String id;
|
||||
|
||||
final String title;
|
||||
|
||||
final String icon;
|
||||
|
||||
final String space;
|
||||
|
||||
final String spaceName;
|
||||
|
||||
/// When it was favorited
|
||||
final String at;
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
'id': id,
|
||||
'title': title,
|
||||
'icon': icon,
|
||||
'space': space,
|
||||
'spaceName': spaceName,
|
||||
'at': at,
|
||||
};
|
||||
}
|
||||
@@ -379,8 +379,11 @@ type Page struct {
|
||||
|
||||
// DeletedAt When the page itself was trashed; empty otherwise
|
||||
DeletedAt string `json:"deletedAt"`
|
||||
Icon string `json:"icon"`
|
||||
Id string `json:"id"`
|
||||
|
||||
// Favorite In the caller's favorites
|
||||
Favorite bool `json:"favorite"`
|
||||
Icon string `json:"icon"`
|
||||
Id string `json:"id"`
|
||||
|
||||
// InTrash The page or one of its ancestors is in the trash
|
||||
InTrash bool `json:"inTrash"`
|
||||
@@ -399,6 +402,17 @@ type PageContent struct {
|
||||
Updated string `json:"updated"`
|
||||
}
|
||||
|
||||
// PageItem defines model for PageItem.
|
||||
type PageItem struct {
|
||||
// At When it was favorited
|
||||
At string `json:"at"`
|
||||
Icon string `json:"icon"`
|
||||
Id string `json:"id"`
|
||||
Space string `json:"space"`
|
||||
SpaceName string `json:"spaceName"`
|
||||
Title string `json:"title"`
|
||||
}
|
||||
|
||||
// PageNode defines model for PageNode.
|
||||
type PageNode struct {
|
||||
Icon string `json:"icon"`
|
||||
@@ -763,6 +777,11 @@ type SetWorkspaceMemberJSONBody struct {
|
||||
Role WorkspaceRole `json:"role"`
|
||||
}
|
||||
|
||||
// ListRecentPagesParams defines parameters for ListRecentPages.
|
||||
type ListRecentPagesParams struct {
|
||||
Limit *int `form:"limit,omitempty" json:"limit,omitempty"`
|
||||
}
|
||||
|
||||
// CreateSpaceJSONBody defines parameters for CreateSpace.
|
||||
type CreateSpaceJSONBody struct {
|
||||
Description *string `json:"description,omitempty"`
|
||||
|
||||
@@ -0,0 +1,183 @@
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
package directory
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"docwell/server/internal/access"
|
||||
"docwell/server/internal/store/pocketbase"
|
||||
)
|
||||
|
||||
// ---- Favorites and recent pages --------------------------------------------
|
||||
//
|
||||
// Both are per user. Lists are filtered by the caller's current rights, so a
|
||||
// page that was moved out of reach, or trashed, quietly drops out.
|
||||
|
||||
// maxRecent is how many recently visited pages a workspace keeps per user.
|
||||
const maxRecent = 50
|
||||
|
||||
// PageItem is a page in a favorites or recent list.
|
||||
type PageItem struct {
|
||||
ID string `json:"id"`
|
||||
Title string `json:"title"`
|
||||
Icon string `json:"icon"`
|
||||
Space string `json:"space"`
|
||||
SpaceName string `json:"spaceName"`
|
||||
// At is when it was added to favorites, or last visited.
|
||||
At string `json:"at"`
|
||||
}
|
||||
|
||||
// userPageRecord is a favorites or page_visits row with its page inlined
|
||||
// (without the page's large content fields).
|
||||
type userPageRecord struct {
|
||||
ID string `json:"id"`
|
||||
Page string `json:"page"`
|
||||
Created string `json:"created"`
|
||||
Visited string `json:"visited"`
|
||||
Expand struct {
|
||||
Page *pageRecord `json:"page"`
|
||||
} `json:"expand"`
|
||||
}
|
||||
|
||||
const userPageFields = "id,page,created,visited," +
|
||||
"expand.page.id,expand.page.space,expand.page.title,expand.page.icon,expand.page.deleted_at"
|
||||
|
||||
// visibleItems keeps the rows whose page c can still open, with space names.
|
||||
func (s *Service) visibleItems(ctx context.Context, c access.Caller, rows []userPageRecord, at func(userPageRecord) string) []PageItem {
|
||||
spaceNames := map[string]string{} // space id → name, "" = no access
|
||||
out := []PageItem{}
|
||||
for _, r := range rows {
|
||||
p := r.Expand.Page
|
||||
if p == nil || p.DeletedAt != "" {
|
||||
continue
|
||||
}
|
||||
name, seen := spaceNames[p.Space]
|
||||
if !seen {
|
||||
if a, err := s.spaceFor(ctx, c, p.Space); err == nil {
|
||||
name = a.space.Name
|
||||
}
|
||||
spaceNames[p.Space] = name
|
||||
}
|
||||
if name == "" {
|
||||
continue
|
||||
}
|
||||
out = append(out, PageItem{ID: p.ID, Title: p.Title, Icon: p.Icon, Space: p.Space, SpaceName: name, At: at(r)})
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// ListFavorites lists the caller's favorite pages in a workspace, newest first.
|
||||
func (s *Service) ListFavorites(ctx context.Context, c access.Caller, wsID string) ([]PageItem, error) {
|
||||
ws, _, err := s.workspaceFor(ctx, c, wsID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
rows, err := listAll[userPageRecord](ctx, s, "favorites", pocketbase.ListOptions{
|
||||
Filter: fmt.Sprintf("user = '%s' && workspace = '%s'", c.ID, ws.ID), Sort: "-created",
|
||||
Expand: "page", Fields: userPageFields,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return s.visibleItems(ctx, c, rows, func(r userPageRecord) string { return r.Created }), nil
|
||||
}
|
||||
|
||||
func (s *Service) favoriteRow(ctx context.Context, userID, pageID string) (string, error) {
|
||||
res, err := pocketbase.List[userPageRecord](ctx, s.pb, "favorites", pocketbase.ListOptions{
|
||||
PerPage: 1, Filter: fmt.Sprintf("user = '%s' && page = '%s'", userID, pageID), Fields: "id",
|
||||
})
|
||||
if err != nil || len(res.Items) == 0 {
|
||||
return "", err
|
||||
}
|
||||
return res.Items[0].ID, nil
|
||||
}
|
||||
|
||||
// SetFavorite adds a page the caller can open to their favorites, or removes it.
|
||||
func (s *Service) SetFavorite(ctx context.Context, c access.Caller, pageID string, on bool) error {
|
||||
p, _, err := s.pageFor(ctx, c, pageID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
id, err := s.favoriteRow(ctx, c.ID, p.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
switch {
|
||||
case on && id == "":
|
||||
_, err = pocketbase.Create[userPageRecord](ctx, s.pb, "favorites", map[string]any{
|
||||
"user": c.ID, "page": p.ID, "workspace": p.Workspace,
|
||||
})
|
||||
case !on && id != "":
|
||||
err = s.pb.Delete(ctx, "favorites", id)
|
||||
}
|
||||
return mapPB(err, "page not found")
|
||||
}
|
||||
|
||||
// RecordVisit notes that the caller opened a page, for their recent list.
|
||||
func (s *Service) RecordVisit(ctx context.Context, c access.Caller, pageID string) error {
|
||||
p, _, err := s.pageFor(ctx, c, pageID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
res, err := pocketbase.List[userPageRecord](ctx, s.pb, "page_visits", pocketbase.ListOptions{
|
||||
PerPage: 1, Filter: fmt.Sprintf("user = '%s' && page = '%s'", c.ID, p.ID), Fields: "id",
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
now := pbTime(time.Now())
|
||||
if len(res.Items) > 0 {
|
||||
_, err = pocketbase.Update[userPageRecord](ctx, s.pb, "page_visits", res.Items[0].ID, map[string]any{"visited": now})
|
||||
return mapPB(err, "page not found")
|
||||
}
|
||||
if _, err := pocketbase.Create[userPageRecord](ctx, s.pb, "page_visits", map[string]any{
|
||||
"user": c.ID, "page": p.ID, "workspace": p.Workspace, "visited": now,
|
||||
}); err != nil {
|
||||
return mapPB(err, "page not found")
|
||||
}
|
||||
s.trimVisits(ctx, c.ID, p.Workspace)
|
||||
return nil
|
||||
}
|
||||
|
||||
// trimVisits keeps the newest maxRecent visits per user and workspace (best effort).
|
||||
func (s *Service) trimVisits(ctx context.Context, userID, wsID string) {
|
||||
res, err := pocketbase.List[userPageRecord](ctx, s.pb, "page_visits", pocketbase.ListOptions{
|
||||
Page: 2, PerPage: maxRecent, Filter: fmt.Sprintf("user = '%s' && workspace = '%s'", userID, wsID),
|
||||
Sort: "-visited", Fields: "id",
|
||||
})
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
for _, r := range res.Items {
|
||||
_ = s.pb.Delete(ctx, "page_visits", r.ID)
|
||||
}
|
||||
}
|
||||
|
||||
// ListRecent lists the pages the caller visited last in a workspace.
|
||||
func (s *Service) ListRecent(ctx context.Context, c access.Caller, wsID string, limit int) ([]PageItem, error) {
|
||||
ws, _, err := s.workspaceFor(ctx, c, wsID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if limit <= 0 || limit > maxRecent {
|
||||
limit = 20
|
||||
}
|
||||
res, err := pocketbase.List[userPageRecord](ctx, s.pb, "page_visits", pocketbase.ListOptions{
|
||||
PerPage: maxRecent, Filter: fmt.Sprintf("user = '%s' && workspace = '%s'", c.ID, ws.ID), Sort: "-visited",
|
||||
Expand: "page", Fields: userPageFields,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
out := s.visibleItems(ctx, c, res.Items, func(r userPageRecord) string { return r.Visited })
|
||||
return out[:min(limit, len(out))], nil
|
||||
}
|
||||
|
||||
// isFavorite reports whether the caller has the page in their favorites.
|
||||
func (s *Service) isFavorite(ctx context.Context, userID, pageID string) bool {
|
||||
id, err := s.favoriteRow(ctx, userID, pageID)
|
||||
return err == nil && id != ""
|
||||
}
|
||||
@@ -74,6 +74,8 @@ type Page struct {
|
||||
InTrash bool `json:"inTrash"`
|
||||
Ancestors []PageRef `json:"ancestors"`
|
||||
Role string `json:"role"`
|
||||
// Favorite is whether the caller has the page in their favorites.
|
||||
Favorite bool `json:"favorite"`
|
||||
}
|
||||
|
||||
type TrashedPage struct {
|
||||
@@ -199,7 +201,7 @@ func (s *Service) GetPage(ctx context.Context, c access.Caller, id string) (Page
|
||||
page := Page{
|
||||
ID: p.ID, Workspace: p.Workspace, Space: p.Space, Parent: p.Parent, Title: p.Title, Icon: p.Icon,
|
||||
Created: p.Created, Updated: p.Updated, DeletedAt: p.DeletedAt, InTrash: p.DeletedAt != "",
|
||||
Ancestors: []PageRef{}, Role: a.role,
|
||||
Ancestors: []PageRef{}, Role: a.role, Favorite: s.isFavorite(ctx, c.ID, p.ID),
|
||||
}
|
||||
parent := p.Parent
|
||||
for depth := 0; parent != "" && depth < 100; depth++ {
|
||||
|
||||
@@ -144,6 +144,7 @@ func (a *api) routes(mux *routeMux) {
|
||||
a.settingsRoutes(mux)
|
||||
a.inviteRoutes(mux)
|
||||
a.groupRoutes(mux)
|
||||
a.favoriteRoutes(mux)
|
||||
}
|
||||
|
||||
func (a *api) decode(w http.ResponseWriter, r *http.Request, v any) bool {
|
||||
|
||||
@@ -35,6 +35,7 @@ type DirectoryService interface {
|
||||
SpaceService
|
||||
InviteService
|
||||
GroupService
|
||||
FavoriteService
|
||||
}
|
||||
|
||||
func caller(r *http.Request) access.Caller {
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
package httpapi
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"docwell/server/internal/access"
|
||||
"docwell/server/internal/directory"
|
||||
)
|
||||
|
||||
// FavoriteService is the part of directory.Service for favorites and recent pages.
|
||||
type FavoriteService interface {
|
||||
ListFavorites(ctx context.Context, c access.Caller, wsID string) ([]directory.PageItem, error)
|
||||
SetFavorite(ctx context.Context, c access.Caller, pageID string, on bool) error
|
||||
RecordVisit(ctx context.Context, c access.Caller, pageID string) error
|
||||
ListRecent(ctx context.Context, c access.Caller, wsID string, limit int) ([]directory.PageItem, error)
|
||||
}
|
||||
|
||||
func (a *api) favoriteRoutes(mux *routeMux) {
|
||||
mux.HandleFunc("GET /api/v1/workspaces/{id}/favorites", a.requireUser(func(w http.ResponseWriter, r *http.Request) {
|
||||
list, err := a.dir.ListFavorites(r.Context(), caller(r), r.PathValue("id"))
|
||||
a.respond(w, list, err)
|
||||
}))
|
||||
mux.HandleFunc("GET /api/v1/workspaces/{id}/recent", a.requireUser(func(w http.ResponseWriter, r *http.Request) {
|
||||
limit, _ := strconv.Atoi(r.URL.Query().Get("limit"))
|
||||
list, err := a.dir.ListRecent(r.Context(), caller(r), r.PathValue("id"), limit)
|
||||
a.respond(w, list, err)
|
||||
}))
|
||||
mux.HandleFunc("PUT /api/v1/pages/{id}/favorite", a.requireUser(func(w http.ResponseWriter, r *http.Request) {
|
||||
a.respondNoContent(w, a.dir.SetFavorite(r.Context(), caller(r), r.PathValue("id"), true))
|
||||
}))
|
||||
mux.HandleFunc("DELETE /api/v1/pages/{id}/favorite", a.requireUser(func(w http.ResponseWriter, r *http.Request) {
|
||||
a.respondNoContent(w, a.dir.SetFavorite(r.Context(), caller(r), r.PathValue("id"), false))
|
||||
}))
|
||||
mux.HandleFunc("POST /api/v1/pages/{id}/visit", a.requireUser(func(w http.ResponseWriter, r *http.Request) {
|
||||
a.respondNoContent(w, a.dir.RecordVisit(r.Context(), caller(r), r.PathValue("id")))
|
||||
}))
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import { useRoute, useRouter } from "vue-router";
|
||||
import { useFormErrors } from "../composables/useFormErrors";
|
||||
import { SIDEBAR_DEFAULT, clampWidth, useSidebar } from "../composables/useSidebar";
|
||||
import { useAuthStore } from "../stores/auth";
|
||||
import { useFavoritesStore } from "../stores/favorites";
|
||||
import { useSpacesStore } from "../stores/spaces";
|
||||
import { atLeast, useWorkspacesStore } from "../stores/workspaces";
|
||||
import PageTreeNode from "./PageTreeNode.vue";
|
||||
@@ -18,6 +19,7 @@ import WorkspaceSwitcher from "./WorkspaceSwitcher.vue";
|
||||
const auth = useAuthStore();
|
||||
const workspaces = useWorkspacesStore();
|
||||
const spaces = useSpacesStore();
|
||||
const favorites = useFavoritesStore();
|
||||
const router = useRouter();
|
||||
const route = useRoute();
|
||||
const { mode } = useTheme();
|
||||
@@ -34,7 +36,11 @@ function showError(e: unknown) {
|
||||
onMounted(() => workspaces.load().catch(showError));
|
||||
watch(
|
||||
() => workspaces.current?.id,
|
||||
(id) => id && spaces.load(id).catch(showError),
|
||||
(id) => {
|
||||
if (!id) return;
|
||||
spaces.load(id).catch(showError);
|
||||
favorites.load(id).catch(showError);
|
||||
},
|
||||
{ immediate: true },
|
||||
);
|
||||
watch(
|
||||
@@ -190,6 +196,24 @@ function signOut() {
|
||||
<DwCallout v-if="error" tone="danger" size="ui">{{ error }}</DwCallout>
|
||||
|
||||
<template v-if="ws">
|
||||
<section v-if="favorites.items.length" data-testid="favorites">
|
||||
<h2 class="flex h-7 items-center px-2 text-ui-xs font-medium text-ink-muted">
|
||||
{{ $t("sidebar.favorites") }}
|
||||
</h2>
|
||||
<ul class="mt-0.5 flex flex-col gap-px">
|
||||
<li v-for="f in favorites.items" :key="f.id">
|
||||
<RouterLink
|
||||
:to="{ name: 'page', params: { id: f.id } }"
|
||||
:class="[navRow, spaces.active.page === f.id ? navActive : '']"
|
||||
:title="f.spaceName"
|
||||
>
|
||||
<span v-if="f.icon" class="w-4 shrink-0 text-center">{{ f.icon }}</span>
|
||||
<DwIcon v-else name="page" :size="16" />
|
||||
<span class="truncate">{{ f.title || $t("home.untitled") }}</span>
|
||||
</RouterLink>
|
||||
</li>
|
||||
</ul>
|
||||
</section>
|
||||
<section v-for="s in spaces.items" :key="s.id">
|
||||
<div
|
||||
class="group flex h-7 items-center gap-1 rounded-sm pr-1 pl-2 hover:bg-surface-hover"
|
||||
|
||||
@@ -30,7 +30,8 @@
|
||||
"untitled": "Untitled",
|
||||
"server": "Server",
|
||||
"serverOnline": "Connected · v{version}",
|
||||
"serverOffline": "Server unreachable"
|
||||
"serverOffline": "Server unreachable",
|
||||
"recent": "Recently visited"
|
||||
},
|
||||
"theme": {
|
||||
"system": "System",
|
||||
@@ -237,7 +238,9 @@
|
||||
"before-replace": "Before a replace"
|
||||
}
|
||||
},
|
||||
"notFound": "This page does not exist or you don't have access to it."
|
||||
"notFound": "This page does not exist or you don't have access to it.",
|
||||
"favorite": "Add to favorites",
|
||||
"unfavorite": "Remove from favorites"
|
||||
},
|
||||
"trash": {
|
||||
"hint": "Pages inside a trashed page come back when you restore it.",
|
||||
|
||||
@@ -30,7 +30,8 @@
|
||||
"untitled": "Bez tytułu",
|
||||
"server": "Serwer",
|
||||
"serverOnline": "Połączono · v{version}",
|
||||
"serverOffline": "Serwer niedostępny"
|
||||
"serverOffline": "Serwer niedostępny",
|
||||
"recent": "Ostatnio odwiedzone"
|
||||
},
|
||||
"theme": {
|
||||
"system": "Systemowy",
|
||||
@@ -237,7 +238,9 @@
|
||||
"before-replace": "Przed zastąpieniem"
|
||||
}
|
||||
},
|
||||
"notFound": "Ta strona nie istnieje lub nie masz do niej dostępu."
|
||||
"notFound": "Ta strona nie istnieje lub nie masz do niej dostępu.",
|
||||
"favorite": "Dodaj do ulubionych",
|
||||
"unfavorite": "Usuń z ulubionych"
|
||||
},
|
||||
"trash": {
|
||||
"hint": "Strony wewnątrz przywróconej strony wracają razem z nią.",
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
import type { PageItem } from "@docwell/api-client";
|
||||
import { defineStore } from "pinia";
|
||||
import { ref } from "vue";
|
||||
import { useApi } from "../api";
|
||||
|
||||
/** The signed-in user's favorite pages in the current workspace, for the sidebar. */
|
||||
export const useFavoritesStore = defineStore("favorites", () => {
|
||||
const api = useApi();
|
||||
const items = ref<PageItem[]>([]);
|
||||
const workspace = ref("");
|
||||
|
||||
async function load(wsId: string) {
|
||||
workspace.value = wsId;
|
||||
const list = await api.workspaces.favorites(wsId);
|
||||
if (workspace.value === wsId) items.value = list;
|
||||
}
|
||||
|
||||
function has(pageId: string) {
|
||||
return items.value.some((p) => p.id === pageId);
|
||||
}
|
||||
|
||||
async function set(pageId: string, on: boolean) {
|
||||
await api.pages.setFavorite(pageId, on);
|
||||
if (workspace.value) await load(workspace.value);
|
||||
}
|
||||
|
||||
/** Keeps a renamed favorite's title in step with the page tree. */
|
||||
function setTitle(pageId: string, title: string) {
|
||||
const item = items.value.find((p) => p.id === pageId);
|
||||
if (item) item.title = title;
|
||||
}
|
||||
|
||||
return { items, load, has, set, setTitle };
|
||||
});
|
||||
@@ -1,7 +1,9 @@
|
||||
<!-- SPDX-License-Identifier: AGPL-3.0-or-later -->
|
||||
<script setup lang="ts">
|
||||
import type { PageItem } from "@docwell/api-client";
|
||||
import { DwBadge, DwCallout, DwIcon } from "@docwell/ui";
|
||||
import { computed, onMounted } from "vue";
|
||||
import { computed, onMounted, ref, watch } from "vue";
|
||||
import { useApi } from "../api";
|
||||
import { useAuthStore } from "../stores/auth";
|
||||
import { useSpacesStore } from "../stores/spaces";
|
||||
import { atLeast, useWorkspacesStore } from "../stores/workspaces";
|
||||
@@ -9,8 +11,19 @@ import { atLeast, useWorkspacesStore } from "../stores/workspaces";
|
||||
const auth = useAuthStore();
|
||||
const workspaces = useWorkspacesStore();
|
||||
const spaces = useSpacesStore();
|
||||
const api = useApi();
|
||||
const ws = computed(() => workspaces.current);
|
||||
onMounted(() => (spaces.active = { space: "", page: "" }));
|
||||
|
||||
const recent = ref<PageItem[]>([]);
|
||||
watch(
|
||||
() => ws.value?.id,
|
||||
async (id) => {
|
||||
recent.value = [];
|
||||
if (id) recent.value = await api.workspaces.recent(id, 8).catch(() => []);
|
||||
},
|
||||
{ immediate: true },
|
||||
);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -27,6 +40,25 @@ onMounted(() => (spaces.active = { space: "", page: "" }));
|
||||
</DwCallout>
|
||||
|
||||
<template v-if="ws">
|
||||
<section v-if="recent.length" class="mt-10" data-testid="recent">
|
||||
<h2 class="dw-label">{{ $t("home.recent") }}</h2>
|
||||
<ul class="mt-3 grid gap-2 sm:grid-cols-2">
|
||||
<li v-for="p in recent" :key="p.id">
|
||||
<RouterLink
|
||||
:to="{ name: 'page', params: { id: p.id } }"
|
||||
class="flex items-center gap-3 rounded-sm border border-line bg-surface-raised px-3 py-2 hover:border-line-strong"
|
||||
>
|
||||
<span v-if="p.icon" class="w-5 shrink-0 text-center">{{ p.icon }}</span>
|
||||
<DwIcon v-else name="page" :size="18" class="text-ink-muted" />
|
||||
<span class="min-w-0 flex-1">
|
||||
<span class="block truncate text-ui-md font-medium text-ink">{{ p.title || $t("home.untitled") }}</span>
|
||||
<span class="block truncate text-ui-sm text-ink-muted">{{ p.spaceName }}</span>
|
||||
</span>
|
||||
</RouterLink>
|
||||
</li>
|
||||
</ul>
|
||||
</section>
|
||||
|
||||
<div class="mt-10 flex items-center justify-between gap-2">
|
||||
<h2 class="dw-label">{{ $t("sidebar.spaces") }}</h2>
|
||||
<RouterLink
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<script setup lang="ts">
|
||||
import type { Page } from "@docwell/api-client";
|
||||
import { CollabProvider, DocwellEditor, userColor } from "@docwell/editor";
|
||||
import { DwBreadcrumbs, DwButton, DwCallout } from "@docwell/ui";
|
||||
import { DwBreadcrumbs, DwButton, DwCallout, DwIcon } from "@docwell/ui";
|
||||
import { computed, onBeforeUnmount, ref, shallowRef, watch } from "vue";
|
||||
import { useI18n } from "vue-i18n";
|
||||
import { useRouter } from "vue-router";
|
||||
@@ -11,6 +11,7 @@ import PageHistory from "../../components/PageHistory.vue";
|
||||
import PageList from "../../components/PageList.vue";
|
||||
import { useRuntimeConfig } from "../../platform";
|
||||
import { useAuthStore } from "../../stores/auth";
|
||||
import { useFavoritesStore } from "../../stores/favorites";
|
||||
import { spaceAtLeast, useSpacesStore } from "../../stores/spaces";
|
||||
import { useWorkspacesStore } from "../../stores/workspaces";
|
||||
|
||||
@@ -18,6 +19,7 @@ const props = defineProps<{ id: string }>();
|
||||
const emit = defineEmits<{ error: [err: unknown] }>();
|
||||
const api = useApi();
|
||||
const spaces = useSpacesStore();
|
||||
const favorites = useFavoritesStore();
|
||||
const workspaces = useWorkspacesStore();
|
||||
const router = useRouter();
|
||||
const { t } = useI18n();
|
||||
@@ -102,6 +104,8 @@ async function load(id: string) {
|
||||
// A link from another workspace switches the sidebar to it.
|
||||
if (workspaces.current && p.workspace !== workspaces.current.id) workspaces.select(p.workspace);
|
||||
spaces.reveal(p.space, p.id);
|
||||
// Best effort: the recent list is a convenience.
|
||||
api.pages.visit(p.id).catch(() => {});
|
||||
} catch {
|
||||
page.value = null;
|
||||
notFound.value = true;
|
||||
@@ -119,6 +123,7 @@ async function saveTitle() {
|
||||
const saved = await api.pages.update(p.id, { title: title.value });
|
||||
if (page.value?.id === saved.id) page.value = { ...page.value, title: saved.title, updated: saved.updated };
|
||||
spaces.setTitle(saved.space, saved.id, saved.title);
|
||||
favorites.setTitle(saved.id, saved.title);
|
||||
} catch (e) {
|
||||
emit("error", e);
|
||||
}
|
||||
@@ -157,6 +162,13 @@ async function run(action: () => Promise<unknown>) {
|
||||
}
|
||||
}
|
||||
|
||||
const toggleFavorite = () =>
|
||||
run(async () => {
|
||||
const p = page.value!;
|
||||
await favorites.set(p.id, !p.favorite);
|
||||
if (page.value?.id === p.id) page.value = { ...page.value, favorite: !p.favorite };
|
||||
});
|
||||
|
||||
const addChild = () =>
|
||||
run(async () => {
|
||||
const child = await spaces.createPage(page.value!.space, page.value!.id);
|
||||
@@ -204,6 +216,18 @@ const purge = () =>
|
||||
}}</span>
|
||||
</template>
|
||||
</p>
|
||||
<button
|
||||
class="grid size-control-sm shrink-0 cursor-pointer place-items-center rounded-sm hover:bg-surface-hover"
|
||||
:class="page.favorite ? 'text-warning' : 'text-ink-muted hover:text-ink'"
|
||||
:aria-pressed="page.favorite"
|
||||
:aria-label="$t(page.favorite ? 'page.unfavorite' : 'page.favorite')"
|
||||
:title="$t(page.favorite ? 'page.unfavorite' : 'page.favorite')"
|
||||
:disabled="busy"
|
||||
data-testid="favorite-toggle"
|
||||
@click="toggleFavorite"
|
||||
>
|
||||
<DwIcon name="star" :size="16" :filled="page.favorite" />
|
||||
</button>
|
||||
<DwButton
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
|
||||
+74
-1
@@ -1209,6 +1209,68 @@ paths:
|
||||
"204": { description: Removed }
|
||||
"403": { $ref: "#/components/responses/Error" }
|
||||
"404": { $ref: "#/components/responses/Error" }
|
||||
/api/v1/workspaces/{id}/favorites:
|
||||
parameters:
|
||||
- { name: id, in: path, required: true, schema: { type: string } }
|
||||
get:
|
||||
operationId: listFavorites
|
||||
tags: [pages]
|
||||
summary: The caller's favorite pages in the workspace, newest first
|
||||
security: [{ bearer: [] }]
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
content:
|
||||
application/json:
|
||||
schema: { type: array, items: { $ref: "#/components/schemas/PageItem" } }
|
||||
"404": { $ref: "#/components/responses/Error" }
|
||||
/api/v1/workspaces/{id}/recent:
|
||||
parameters:
|
||||
- { name: id, in: path, required: true, schema: { type: string } }
|
||||
get:
|
||||
operationId: listRecentPages
|
||||
tags: [pages]
|
||||
summary: Pages the caller visited last in the workspace
|
||||
security: [{ bearer: [] }]
|
||||
parameters:
|
||||
- { name: limit, in: query, schema: { type: integer, minimum: 1, maximum: 50 } }
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
content:
|
||||
application/json:
|
||||
schema: { type: array, items: { $ref: "#/components/schemas/PageItem" } }
|
||||
"404": { $ref: "#/components/responses/Error" }
|
||||
/api/v1/pages/{id}/favorite:
|
||||
parameters:
|
||||
- { name: id, in: path, required: true, schema: { type: string } }
|
||||
put:
|
||||
operationId: addFavorite
|
||||
tags: [pages]
|
||||
summary: Add the page to the caller's favorites
|
||||
security: [{ bearer: [] }]
|
||||
responses:
|
||||
"204": { description: Added }
|
||||
"404": { $ref: "#/components/responses/Error" }
|
||||
delete:
|
||||
operationId: removeFavorite
|
||||
tags: [pages]
|
||||
summary: Remove the page from the caller's favorites
|
||||
security: [{ bearer: [] }]
|
||||
responses:
|
||||
"204": { description: Removed }
|
||||
"404": { $ref: "#/components/responses/Error" }
|
||||
/api/v1/pages/{id}/visit:
|
||||
parameters:
|
||||
- { name: id, in: path, required: true, schema: { type: string } }
|
||||
post:
|
||||
operationId: recordPageVisit
|
||||
tags: [pages]
|
||||
summary: Note that the caller opened the page (for the recent list)
|
||||
security: [{ bearer: [] }]
|
||||
responses:
|
||||
"204": { description: Recorded }
|
||||
"404": { $ref: "#/components/responses/Error" }
|
||||
components:
|
||||
securitySchemes:
|
||||
bearer:
|
||||
@@ -1377,7 +1439,7 @@ components:
|
||||
icon: { type: string }
|
||||
Page:
|
||||
type: object
|
||||
required: [id, workspace, space, parent, title, icon, created, updated, deletedAt, inTrash, ancestors, role]
|
||||
required: [id, workspace, space, parent, title, icon, created, updated, deletedAt, inTrash, ancestors, role, favorite]
|
||||
properties:
|
||||
id: { type: string }
|
||||
workspace: { type: string }
|
||||
@@ -1391,6 +1453,7 @@ components:
|
||||
inTrash: { type: boolean, description: The page or one of its ancestors is in the trash }
|
||||
ancestors: { type: array, items: { $ref: "#/components/schemas/PageRef" }, description: Root first }
|
||||
role: { $ref: "#/components/schemas/SpaceRole" }
|
||||
favorite: { type: boolean, description: In the caller's favorites }
|
||||
PageContent:
|
||||
type: object
|
||||
required: [content, updated]
|
||||
@@ -1608,3 +1671,13 @@ components:
|
||||
id: { type: string }
|
||||
name: { type: string }
|
||||
role: { $ref: "#/components/schemas/SpaceRole" }
|
||||
PageItem:
|
||||
type: object
|
||||
required: [id, title, icon, space, spaceName, at]
|
||||
properties:
|
||||
id: { type: string }
|
||||
title: { type: string }
|
||||
icon: { type: string }
|
||||
space: { type: string }
|
||||
spaceName: { type: string }
|
||||
at: { type: string, description: When it was favorited, or last visited }
|
||||
Reference in new issue
Block a user