Skip to content

Commit 3581ee9

Browse files
committed
feat: add group and page "exists" field
1 parent 7850448 commit 3581ee9

File tree

17 files changed

+149
-63
lines changed

17 files changed

+149
-63
lines changed

apps/app-server/src/trpc/api/users/pages/get-current-path.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ export async function getCurrentPath({
2424
// Check if page exists
2525

2626
if (
27-
(await ctx.dataAbstraction.hget('page', input.initialPageId, 'group-id')) ==
28-
null
27+
!(await ctx.dataAbstraction.hget('page', input.initialPageId, 'exists'))
2928
) {
3029
throw new TRPCError({
3130
message: 'This page does not exist.',

apps/client/src/code/pages/page/page.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -359,9 +359,8 @@ export class Page implements IPageRegion {
359359
// Bump on recent pages
360360

361361
internals.pages.recentPageIdsKeepOverride = true;
362-
internals.pages.react.recentPageIdsOverride = [
363-
...internals.pages.react.recentPageIds,
364-
];
362+
internals.pages.react.recentPageIdsOverride =
363+
internals.pages.react.recentPageIds.slice();
365364
pull(this.app.react.recentPageIdsOverride!, this.id);
366365
this.app.react.recentPageIdsOverride!.unshift(this.id);
367366

apps/client/src/layouts/PagesLayout/LeftSidebar/RecentPages.vue

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
<q-item
5050
clickable
5151
@click="clearRecentPages"
52-
:disable="internals.pages.react.recentPageIds.length === 0"
52+
:disable="recentPageIds.length === 0"
5353
>
5454
<q-item-section avatar>
5555
<q-icon name="mdi-close" />
@@ -71,7 +71,7 @@
7171
flex: uiStore().recentPagesExpanded ? uiStore().recentPagesWeight : '0',
7272
}"
7373
>
74-
<q-item v-if="internals.pages.react.recentPageIds.length === 0">
74+
<q-item v-if="recentPageIds.length === 0">
7575
<q-item-section>
7676
<q-item-label
7777
style="color: rgba(255, 255, 255, 0.7); font-size: 13.5px"
@@ -82,7 +82,7 @@
8282
</q-item>
8383

8484
<div
85-
v-for="pageId in internals.pages.react.recentPageIds"
85+
v-for="pageId in recentPageIds"
8686
:key="pageId"
8787
class="recent-page"
8888
>
@@ -123,9 +123,18 @@
123123
<script setup lang="ts">
124124
import { listenPointerEvents, map, negateProp } from '@stdlib/misc';
125125
import { pull } from 'lodash';
126+
import { useRealtimeContext } from 'src/code/realtime/context';
126127
import { asyncDialog, handleError } from 'src/code/utils/misc';
127128
import type { ComponentPublicInstance } from 'vue';
128129
130+
const realtimeCtx = useRealtimeContext();
131+
132+
const recentPageIds = computed(() =>
133+
internals.pages.react.recentPageIds.filter((pageId) =>
134+
realtimeCtx.hget('page', pageId, 'exists'),
135+
),
136+
);
137+
129138
const listRef = ref<ComponentPublicInstance>();
130139
131140
function resizeHandlePointerDown(downEvent: PointerEvent) {
@@ -178,9 +187,7 @@ async function removeRecentPage(pageId: string) {
178187
await trpcClient.users.pages.removeRecentPage.mutate({ pageId });
179188
180189
internals.pages.recentPageIdsKeepOverride = true;
181-
internals.pages.react.recentPageIdsOverride = [
182-
...internals.pages.react.recentPageIds,
183-
];
190+
internals.pages.react.recentPageIdsOverride = recentPageIds.value.slice();
184191
pull(internals.pages.react.recentPageIdsOverride, pageId);
185192
} catch (error) {
186193
handleError(error);

apps/client/src/layouts/PagesLayout/LeftSidebar/SelectedPages.vue

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@
100100
: '0',
101101
}"
102102
>
103-
<q-item v-if="pageSelectionStore().selectedPages.size === 0">
103+
<q-item v-if="selectedPageIds.length === 0">
104104
<q-item-section>
105105
<q-item-label
106106
style="color: rgba(255, 255, 255, 0.7); font-size: 13.5px"
@@ -111,7 +111,7 @@
111111
</q-item>
112112

113113
<div
114-
v-for="pageId in pageSelectionStore().selectedPages"
114+
v-for="pageId in selectedPageIds"
115115
:key="pageId"
116116
class="selected-page"
117117
>
@@ -141,11 +141,20 @@ import { negateProp, pluralS } from '@stdlib/misc';
141141
import type { QNotifyUpdateOptions } from 'quasar';
142142
import { deletePage } from 'src/code/api-interface/pages/deletion/delete';
143143
import { movePage } from 'src/code/api-interface/pages/move';
144+
import { useRealtimeContext } from 'src/code/realtime/context';
144145
import { asyncDialog, handleError } from 'src/code/utils/misc';
145146
import { pageSelectionStore } from 'src/stores/page-selection';
146147
147148
import MovePageDialog from '../RightSidebar/PageProperties/MovePageDialog.vue';
148149
150+
const realtimeCtx = useRealtimeContext();
151+
152+
const selectedPageIds = computed(() =>
153+
Array.from(pageSelectionStore().selectedPages).filter((pageId) =>
154+
realtimeCtx.hget('page', pageId, 'exists'),
155+
),
156+
);
157+
149158
async function movePages() {
150159
try {
151160
const movePageParams: Parameters<typeof movePage>[0] = await asyncDialog({
@@ -162,17 +171,15 @@ async function movePages() {
162171
message: 'Moving pages...',
163172
});
164173
165-
const numTotal = pageSelectionStore().selectedPages.size;
174+
const _selectedPageIds = selectedPageIds.value.slice();
166175
167176
let numSuccess = 0;
168177
let numFailed = 0;
169178
170-
for (const [index, pageId] of Array.from(
171-
pageSelectionStore().selectedPages,
172-
).entries()) {
179+
for (const [index, pageId] of _selectedPageIds.entries()) {
173180
try {
174181
notif({
175-
caption: `${index} of ${numTotal}`,
182+
caption: `${index} of ${_selectedPageIds.length}`,
176183
});
177184
178185
await movePage({
@@ -234,17 +241,17 @@ async function deletePages() {
234241
message: 'Deleting pages...',
235242
});
236243
237-
const numTotal = pageSelectionStore().selectedPages.size;
244+
const selectedPageIds = Array.from(
245+
pageSelectionStore().selectedPages,
246+
).filter((pageId) => realtimeCtx.hget('page', pageId, 'exists'));
238247
239248
let numSuccess = 0;
240249
let numFailed = 0;
241250
242-
for (const [index, pageId] of Array.from(
243-
pageSelectionStore().selectedPages,
244-
).entries()) {
251+
for (const [index, pageId] of selectedPageIds.entries()) {
245252
try {
246253
notif({
247-
caption: `${index} of ${numTotal}`,
254+
caption: `${index} of ${selectedPageIds.length}`,
248255
});
249256
250257
await deletePage(pageId);

apps/client/src/layouts/PagesLayout/MainToolbar/PagesSettingsDialog/GroupsTab.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,15 +156,15 @@ async function leaveSelectedGroups() {
156156
message: 'Leaving groups...',
157157
});
158158
159-
const numTotal = finalSelectedGroupIds.value.length;
159+
const selectedGroupIds = finalSelectedGroupIds.value.slice();
160160
161161
let numSuccess = 0;
162162
let numFailed = 0;
163163
164-
for (const [index, groupId] of finalSelectedGroupIds.value.entries()) {
164+
for (const [index, groupId] of selectedGroupIds.entries()) {
165165
try {
166166
notif({
167-
caption: `${index} of ${numTotal}`,
167+
caption: `${index} of ${selectedGroupIds.length}`,
168168
});
169169
170170
await removeGroupUser({

apps/client/src/layouts/PagesLayout/MainToolbar/PagesSettingsDialog/InvitationsTab.vue

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ const realtimeCtx = inject<RealtimeContext>('realtimeCtx')!;
115115
const invitationGroupsIds = computed(() =>
116116
groupIds.value.filter(
117117
(groupId) =>
118+
realtimeCtx.hget('group', groupId, 'permanent-deletion-date') == null &&
118119
!!realtimeCtx.hget(
119120
'group-join-invitation',
120121
`${groupId}:${authStore().userId}`,
@@ -177,15 +178,15 @@ async function rejectSelectedInvitations() {
177178
message: 'Rejecting join invitations...',
178179
});
179180
180-
const numTotal = finalSelectedGroupIds.value.length;
181+
const selectedGroupIds = finalSelectedGroupIds.value.slice();
181182
182183
let numSuccess = 0;
183184
let numFailed = 0;
184185
185-
for (const [index, groupId] of finalSelectedGroupIds.value.entries()) {
186+
for (const [index, groupId] of selectedGroupIds.entries()) {
186187
try {
187188
notif({
188-
caption: `${index} of ${numTotal}`,
189+
caption: `${index} of ${selectedGroupIds.length}`,
189190
});
190191
191192
await rejectJoinInvitation({ groupId });

apps/client/src/layouts/PagesLayout/MainToolbar/PagesSettingsDialog/RequestsTab.vue

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ const realtimeCtx = inject<RealtimeContext>('realtimeCtx')!;
9090
const requestGroupsIds = computed(() =>
9191
groupIds.value.filter(
9292
(groupId) =>
93+
realtimeCtx.hget('group', groupId, 'permanent-deletion-date') == null &&
9394
realtimeCtx.hget(
9495
'group-join-request',
9596
`${groupId}:${authStore().userId}`,
@@ -143,15 +144,15 @@ async function cancelSelectedRequests() {
143144
message: 'Canceling join requests...',
144145
});
145146
146-
const numTotal = finalSelectedGroupIds.value.length;
147+
const selectedGroupIds = finalSelectedGroupIds.value.slice();
147148
148149
let numSuccess = 0;
149150
let numFailed = 0;
150151
151-
for (const [index, groupId] of finalSelectedGroupIds.value.entries()) {
152+
for (const [index, groupId] of selectedGroupIds.entries()) {
152153
try {
153154
notif({
154-
caption: `${index} of ${numTotal}`,
155+
caption: `${index} of ${selectedGroupIds.length}`,
155156
});
156157
157158
await cancelJoinRequest({

apps/client/src/layouts/PagesLayout/RightSidebar/PageProperties/GroupSettingsDialog/InvitationsTab/InvitationsTab.vue

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ const realtimeCtx = inject<RealtimeContext>('realtimeCtx')!;
139139
const invitationsUserIds = computed(() =>
140140
Array.from(pagesStore().groups[groupId]?.userIds ?? []).filter(
141141
(groupMemberId) =>
142+
realtimeCtx.hget('group', groupId, 'permanent-deletion-date') == null &&
142143
!!realtimeCtx.hget(
143144
'group-join-invitation',
144145
`${groupId}:${groupMemberId}`,
@@ -184,15 +185,15 @@ async function cancelSelectedInvitations() {
184185
message: 'Canceling join invitations...',
185186
});
186187
187-
const numTotal = finalSelectedUserIds.value.length;
188+
const selectedUserIds = finalSelectedUserIds.value.slice();
188189
189190
let numSuccess = 0;
190191
let numFailed = 0;
191192
192-
for (const [index, userId] of finalSelectedUserIds.value.entries()) {
193+
for (const [index, userId] of selectedUserIds.entries()) {
193194
try {
194195
notif({
195-
caption: `${index} of ${numTotal}`,
196+
caption: `${index} of ${selectedUserIds.length}`,
196197
});
197198
198199
await cancelJoinInvitation({

apps/client/src/layouts/PagesLayout/RightSidebar/PageProperties/GroupSettingsDialog/MembersTab/ChangeRoleDialog.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,15 +115,15 @@ async function changeRole() {
115115
message: 'Changing user roles...',
116116
});
117117
118-
const numTotal = props.userIds.length;
118+
const selectedUserIds = props.userIds.slice();
119119
120120
let numSuccess = 0;
121121
let numFailed = 0;
122122
123-
for (const [index, userId] of props.userIds.entries()) {
123+
for (const [index, userId] of selectedUserIds.entries()) {
124124
try {
125125
notif({
126-
caption: `${index} of ${numTotal}`,
126+
caption: `${index} of ${selectedUserIds.length}`,
127127
});
128128
129129
await changeUserRole({

apps/client/src/layouts/PagesLayout/RightSidebar/PageProperties/GroupSettingsDialog/MembersTab/MembersTab.vue

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -224,17 +224,17 @@ async function removeSelectedUsers() {
224224
message: 'Removing users...',
225225
});
226226
227-
const numTotal = finalSelectedUserIds.value.length;
227+
const selectedUserIds = finalSelectedUserIds.value.filter(
228+
(userId) => userId !== authStore().userId,
229+
);
228230
229231
let numSuccess = 0;
230232
let numFailed = 0;
231233
232-
for (const [index, userId] of finalSelectedUserIds.value
233-
.filter((userId) => userId !== authStore().userId)
234-
.entries()) {
234+
for (const [index, userId] of selectedUserIds.entries()) {
235235
try {
236236
notif({
237-
caption: `${index} of ${numTotal}`,
237+
caption: `${index} of ${selectedUserIds.length}`,
238238
});
239239
240240
await removeGroupUser({

0 commit comments

Comments
 (0)