refactor all widgets
This commit is contained in:
@@ -5,17 +5,15 @@ import { useStorage } from '@libs/storage/provider';
|
||||
import { ArrowRightCircleIcon, CheckCircleIcon } from '@shared/icons';
|
||||
import { User } from '@shared/user';
|
||||
|
||||
import { WidgetKinds, useWidgets } from '@stores/widgets';
|
||||
import { WidgetKinds } from '@stores/constants';
|
||||
|
||||
import { useWidget } from '@utils/hooks/useWidget';
|
||||
import { Widget } from '@utils/types';
|
||||
|
||||
export function XfeedsWidget({ params }: { params: Widget }) {
|
||||
const { db } = useStorage();
|
||||
const { addWidget, removeWidget } = useWidget();
|
||||
|
||||
const [setWidget, removeWidget] = useWidgets((state) => [
|
||||
state.setWidget,
|
||||
state.removeWidget,
|
||||
]);
|
||||
const [title, setTitle] = useState<string>('');
|
||||
const [groups, setGroups] = useState<Array<string>>([]);
|
||||
|
||||
@@ -28,17 +26,17 @@ export function XfeedsWidget({ params }: { params: Widget }) {
|
||||
};
|
||||
|
||||
const cancel = () => {
|
||||
removeWidget(db, params.id);
|
||||
removeWidget.mutate(params.id);
|
||||
};
|
||||
|
||||
const submit = async () => {
|
||||
setWidget(db, {
|
||||
addWidget.mutate({
|
||||
kind: WidgetKinds.local.feeds,
|
||||
title: title || 'Group',
|
||||
content: JSON.stringify(groups),
|
||||
});
|
||||
// remove temp widget
|
||||
removeWidget(db, params.id);
|
||||
removeWidget.mutate(params.id);
|
||||
};
|
||||
|
||||
return (
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
import { Resolver, useForm } from 'react-hook-form';
|
||||
|
||||
import { useStorage } from '@libs/storage/provider';
|
||||
|
||||
import { ArrowRightCircleIcon } from '@shared/icons';
|
||||
|
||||
import { WidgetKinds, useWidgets } from '@stores/widgets';
|
||||
import { WidgetKinds } from '@stores/constants';
|
||||
|
||||
import { useWidget } from '@utils/hooks/useWidget';
|
||||
import { Widget } from '@utils/types';
|
||||
|
||||
type FormValues = {
|
||||
@@ -27,12 +26,7 @@ const resolver: Resolver<FormValues> = async (values) => {
|
||||
};
|
||||
|
||||
export function XhashtagWidget({ params }: { params: Widget }) {
|
||||
const [setWidget, removeWidget] = useWidgets((state) => [
|
||||
state.setWidget,
|
||||
state.removeWidget,
|
||||
]);
|
||||
|
||||
const { db } = useStorage();
|
||||
const { addWidget, removeWidget } = useWidget();
|
||||
const {
|
||||
register,
|
||||
setError,
|
||||
@@ -41,18 +35,18 @@ export function XhashtagWidget({ params }: { params: Widget }) {
|
||||
} = useForm<FormValues>({ resolver });
|
||||
|
||||
const cancel = () => {
|
||||
removeWidget(db, params.id);
|
||||
removeWidget.mutate(params.id);
|
||||
};
|
||||
|
||||
const onSubmit = async (data: FormValues) => {
|
||||
try {
|
||||
setWidget(db, {
|
||||
addWidget.mutate({
|
||||
kind: WidgetKinds.global.hashtag,
|
||||
title: data.hashtag,
|
||||
content: data.hashtag.replace('#', ''),
|
||||
});
|
||||
// remove temp widget
|
||||
removeWidget(db, params.id);
|
||||
removeWidget.mutate(params.id);
|
||||
} catch (e) {
|
||||
setError('hashtag', {
|
||||
type: 'custom',
|
||||
|
||||
Reference in New Issue
Block a user