mirror of
https://github.com/outline/outline.git
synced 2026-12-04 18:34:54 +03:00
refactor to use latest impl
This commit is contained in:
1 parent
89f2348888
commit
14bd41034f
7 files changed
+34
-28
No files matched your search
@@ -261,7 +261,7 @@ export const unsubscribeCollection = createAction({
|
||||
|
||||
const collection = stores.collections.get(activeCollectionId);
|
||||
|
||||
await collection?.unsubscribe(currentUserId);
|
||||
await collection?.unsubscribe();
|
||||
|
||||
toast.success(t("Unsubscribed from collection notifications"));
|
||||
},
|
||||
|
||||
@@ -74,7 +74,7 @@ function CollectionMenu({
|
||||
const file = React.useRef<HTMLInputElement>(null);
|
||||
|
||||
const { data, loading, error, request } = useRequest(() =>
|
||||
subscriptions.fetchPage({
|
||||
subscriptions.fetchOne({
|
||||
collectionId: collection.id,
|
||||
event: SubscriptionEventType.Collection,
|
||||
})
|
||||
|
||||
+11
-11
@@ -1,6 +1,7 @@
|
||||
import capitalize from "lodash/capitalize";
|
||||
import isEmpty from "lodash/isEmpty";
|
||||
import isUndefined from "lodash/isUndefined";
|
||||
import noop from "lodash/noop";
|
||||
import { observer } from "mobx-react";
|
||||
import { EditIcon, InputIcon, RestoreIcon, SearchIcon } from "outline-icons";
|
||||
import * as React from "react";
|
||||
@@ -101,10 +102,12 @@ const MenuTrigger: React.FC<MenuTriggerProps> = ({ label, onTrigger }) => {
|
||||
documentId: document.id,
|
||||
event: SubscriptionEventType.Document,
|
||||
}),
|
||||
subscriptions.fetchOne({
|
||||
collectionId: document.collectionId,
|
||||
event: SubscriptionEventType.Collection,
|
||||
}),
|
||||
document.collectionId
|
||||
? subscriptions.fetchOne({
|
||||
collectionId: document.collectionId,
|
||||
event: SubscriptionEventType.Collection,
|
||||
})
|
||||
: noop,
|
||||
])
|
||||
);
|
||||
|
||||
@@ -193,7 +196,7 @@ const MenuContent: React.FC<MenuContentProps> = observer(function MenuContent_({
|
||||
if (can.createDocument) {
|
||||
filtered.push({
|
||||
type: "button",
|
||||
onClick: ev =>
|
||||
onClick: (ev) =>
|
||||
handleRestore(ev, {
|
||||
collectionId: collection.id,
|
||||
}),
|
||||
@@ -224,7 +227,7 @@ const MenuContent: React.FC<MenuContentProps> = observer(function MenuContent_({
|
||||
visible:
|
||||
!!(document.isWorkspaceTemplate || collection?.isActive) &&
|
||||
!!(can.restore || can.unarchive),
|
||||
onClick: ev => handleRestore(ev),
|
||||
onClick: (ev) => handleRestore(ev),
|
||||
icon: <RestoreIcon />,
|
||||
},
|
||||
{
|
||||
@@ -336,7 +339,7 @@ const MenuContent: React.FC<MenuContentProps> = observer(function MenuContent_({
|
||||
label={t("Full width")}
|
||||
labelPosition="left"
|
||||
checked={document.fullWidth}
|
||||
onChange={ev => {
|
||||
onChange={(ev) => {
|
||||
const fullWidth = ev.currentTarget.checked;
|
||||
user.setPreference(
|
||||
UserPreference.FullWidthDocuments,
|
||||
@@ -438,10 +441,7 @@ function DocumentMenu({
|
||||
</label>
|
||||
</VisuallyHidden>
|
||||
<MenuContext.Provider value={{ model: document, menuState }}>
|
||||
<MenuTrigger
|
||||
label={label}
|
||||
onTrigger={showMenu}
|
||||
/>
|
||||
<MenuTrigger label={label} onTrigger={showMenu} />
|
||||
{isMenuVisible ? (
|
||||
<MenuContent
|
||||
onOpen={onOpen}
|
||||
|
||||
@@ -136,9 +136,7 @@ export default class Collection extends ParanoidModel {
|
||||
*/
|
||||
@computed
|
||||
get isSubscribed(): boolean {
|
||||
return !!this.store.rootStore.subscriptions.orderedData.find(
|
||||
(subscription) => subscription.collectionId === this.id
|
||||
);
|
||||
return !!this.store.rootStore.subscriptions.getByCollectionId(this.id);
|
||||
}
|
||||
|
||||
@computed
|
||||
@@ -402,7 +400,7 @@ export default class Collection extends ParanoidModel {
|
||||
* @returns A promise that resolves when the subscription is destroyed.
|
||||
*/
|
||||
@action
|
||||
unsubscribe = (userId: string) => this.store.unsubscribe(userId, this);
|
||||
unsubscribe = () => this.store.unsubscribe(this);
|
||||
|
||||
archive = () => this.store.archive(this);
|
||||
|
||||
|
||||
@@ -220,9 +220,9 @@ export default class CollectionsStore extends Store<Collection> {
|
||||
event: SubscriptionEventType.Collection,
|
||||
});
|
||||
|
||||
unsubscribe = (userId: string, collection: Collection) => {
|
||||
const subscription = this.rootStore.subscriptions.orderedData.find(
|
||||
(s) => s.collectionId === collection.id && s.userId === userId
|
||||
unsubscribe = (collection: Collection) => {
|
||||
const subscription = this.rootStore.subscriptions.getByCollectionId(
|
||||
collection.id
|
||||
);
|
||||
|
||||
return subscription?.delete();
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import invariant from "invariant";
|
||||
import { action } from "mobx";
|
||||
import { SubscriptionEventType } from "@shared/types";
|
||||
import Subscription from "~/models/Subscription";
|
||||
import { client } from "~/utils/ApiClient";
|
||||
import { AuthorizationError, NotFoundError } from "~/utils/errors";
|
||||
@@ -14,8 +15,15 @@ export default class SubscriptionsStore extends Store<Subscription> {
|
||||
}
|
||||
|
||||
@action
|
||||
async fetchOne({ documentId, event }: { documentId: string; event: string }) {
|
||||
const subscription = this.getByDocumentId(documentId);
|
||||
async fetchOne(
|
||||
options:
|
||||
| { documentId: string; event: SubscriptionEventType.Document }
|
||||
| { collectionId: string; event: SubscriptionEventType.Collection }
|
||||
) {
|
||||
const subscription =
|
||||
options.event === SubscriptionEventType.Collection
|
||||
? this.getByCollectionId(options.collectionId)
|
||||
: this.getByDocumentId(options.documentId);
|
||||
|
||||
if (subscription) {
|
||||
return subscription;
|
||||
@@ -24,10 +32,7 @@ export default class SubscriptionsStore extends Store<Subscription> {
|
||||
this.isFetching = true;
|
||||
|
||||
try {
|
||||
const res = await client.post(`/${this.apiEndpoint}.info`, {
|
||||
documentId,
|
||||
event,
|
||||
});
|
||||
const res = await client.post(`/${this.apiEndpoint}.info`, options);
|
||||
invariant(res?.data, "Data should be available");
|
||||
return this.add(res.data);
|
||||
} catch (err) {
|
||||
@@ -42,4 +47,7 @@ export default class SubscriptionsStore extends Store<Subscription> {
|
||||
|
||||
getByDocumentId = (documentId: string): Subscription | undefined =>
|
||||
this.find({ documentId });
|
||||
|
||||
getByCollectionId = (collectionId: string): Subscription | undefined =>
|
||||
this.find({ collectionId });
|
||||
}
|
||||
@@ -44,9 +44,9 @@ export default class DocumentSubscriptionProcessor extends BaseProcessor {
|
||||
},
|
||||
batchLimit: 10,
|
||||
},
|
||||
async groupUsers => {
|
||||
async (groupUsers) => {
|
||||
await Promise.all(
|
||||
groupUsers.map(groupUser =>
|
||||
groupUsers.map((groupUser) =>
|
||||
DocumentSubscriptionTask.schedule({
|
||||
...event,
|
||||
name: userEventName,
|
||||
|
||||
Reference in new issue
Block a user