improve: change db schema for settings
This commit is contained in:
@@ -67,9 +67,9 @@ export const useSaveMarkdown = () => {
|
||||
body: JSON.stringify(data),
|
||||
})
|
||||
},{
|
||||
onSuccess: (res, variables) => {
|
||||
queryClient.invalidateQueries(["markdownsByPath", variables.data.path_id]);
|
||||
queryClient.invalidateQueries(["markdown", variables.data.id]);
|
||||
onSuccess: (res) => {
|
||||
queryClient.invalidateQueries(["markdownsByPath", res.path_id]);
|
||||
queryClient.invalidateQueries(["markdown", res.id]);
|
||||
},
|
||||
});
|
||||
};
|
||||
@@ -93,7 +93,6 @@ export const useMoveMarkdown = () => {
|
||||
};
|
||||
|
||||
export const useSearchMarkdown = (keyword) => {
|
||||
const queryClient = useQueryClient();
|
||||
const config = useConfig();
|
||||
return useQuery(["markdownsByKeyword", keyword],
|
||||
() => fetch_(
|
||||
|
||||
@@ -45,8 +45,8 @@ export const useCreatePath = () => {
|
||||
body: JSON.stringify(data),
|
||||
}),
|
||||
{
|
||||
onSuccess: (res, variables) => {
|
||||
queryClient.invalidateQueries(["paths", variables.parent_id]);
|
||||
onSuccess: (res) => {
|
||||
queryClient.invalidateQueries(["paths", res.parent_id]);
|
||||
queryClient.invalidateQueries("tree");
|
||||
},
|
||||
}
|
||||
@@ -63,9 +63,9 @@ export const useUpdatePath = () => {
|
||||
body: JSON.stringify(data),
|
||||
}),
|
||||
{
|
||||
onSuccess: (res, variables) => {
|
||||
onSuccess: (res) => {
|
||||
queryClient.invalidateQueries(["paths", res.parent_id]);
|
||||
queryClient.invalidateQueries(["path", variables.data.id]);
|
||||
queryClient.invalidateQueries(["path", res.id]);
|
||||
queryClient.invalidateQueries("tree");
|
||||
},
|
||||
}
|
||||
|
||||
151
src/utils/setting-queries.js
Normal file
151
src/utils/setting-queries.js
Normal file
@@ -0,0 +1,151 @@
|
||||
import {fetch_} from "./request-utils";
|
||||
import {useConfig} from "../ConfigProvider";
|
||||
import {useMutation, useQuery, useQueryClient} from "react-query";
|
||||
|
||||
export const usePathSettings = () => {
|
||||
const config = useConfig();
|
||||
const queryClient = useQueryClient();
|
||||
return useQuery(
|
||||
"path_settings",
|
||||
() => fetch_(`${config.BACKEND_HOST}/api/setting/path/`),
|
||||
{
|
||||
onSuccess: (data) => {
|
||||
if(data){
|
||||
for(const setting of data)
|
||||
queryClient.setQueryData(["path_setting", setting.id], setting);
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
export const usePathSetting = (setting_id) => {
|
||||
const config = useConfig();
|
||||
return useQuery(
|
||||
["path_setting", setting_id],
|
||||
() => fetch_(`${config.BACKEND_HOST}/api/setting/path/${setting_id}`),
|
||||
{
|
||||
enabled: !!setting_id,
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
export const useCreatePathSetting = () => {
|
||||
const config = useConfig();
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation(
|
||||
(data) => fetch_(`${config.BACKEND_HOST}/api/setting/path/`, {
|
||||
method: "POST",
|
||||
body: JSON.stringify(data)
|
||||
}), {
|
||||
onSuccess: (data) => {
|
||||
queryClient.invalidateQueries(["path_setting", data.id]);
|
||||
queryClient.invalidateQueries("path_setting");
|
||||
}
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
export const useUpdatePathSetting = () => {
|
||||
const config = useConfig();
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation(
|
||||
({id, data}) => fetch_(`${config.BACKEND_HOST}/api/setting/path/${id}`, {
|
||||
method: "PATCH",
|
||||
body: JSON.stringify(data)
|
||||
}), {
|
||||
onSuccess: (data, variables) => {
|
||||
queryClient.invalidateQueries(["path_setting", variables.id]);
|
||||
queryClient.invalidateQueries("path_setting");
|
||||
}
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
export const useDeletePathSetting = () => {
|
||||
const config = useConfig();
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation(
|
||||
(id) => fetch_(`${config.BACKEND_HOST}/api/setting/path/${id}`, {
|
||||
method: "DELETE",
|
||||
}),{
|
||||
onSuccess: (data, variables) => {
|
||||
queryClient.invalidateQueries(["path_setting", variables.id]);
|
||||
queryClient.invalidateQueries("path_setting");
|
||||
}
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
export const useMarkdownSettings = () => {
|
||||
const config = useConfig();
|
||||
const queryClient = useQueryClient();
|
||||
return useQuery(
|
||||
"markdown_setting",
|
||||
() => fetch_(`${config.BACKEND_HOST}/api/setting/markdown/`),
|
||||
{
|
||||
onSuccess: (data) => {
|
||||
if(data){
|
||||
for(const setting of data)
|
||||
queryClient.invalidateQueries(["markdown_setting", setting.id]);
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
export const useMarkdownSetting = (setting_id) => {
|
||||
const config = useConfig();
|
||||
return useQuery(
|
||||
["markdown_setting", setting_id],
|
||||
() => fetch_(`${config.BACKEND_HOST}/api/setting/markdown/`), {
|
||||
enabled: !!setting_id,
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
export const useCreateMarkdownSetting = () => {
|
||||
const config = useConfig();
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation(
|
||||
(data) => fetch_(`${config.BACKEND_HOST}/api/setting/markdown/`, {
|
||||
method: "POST",
|
||||
body: JSON.stringify(data)
|
||||
}), {
|
||||
onSuccess: (data) => {
|
||||
queryClient.invalidateQueries(["path_setting", data.id]);
|
||||
}
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
export const useUpdateMarkdownSetting = () => {
|
||||
const config = useConfig();
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation(
|
||||
({id, data}) => fetch_(`${config.BACKEND_HOST}/api/setting/markdown/${id}`, {
|
||||
method: "PATCH",
|
||||
body: JSON.stringify(data)
|
||||
}),{
|
||||
onSuccess: (data) => {
|
||||
queryClient.invalidateQueries(["path_setting", data.id]);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
export const useDeleteMarkdownSetting = () => {
|
||||
const config = useConfig();
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation(
|
||||
(id) => fetch_(`${config.BACKEND_HOST}/api/setting/markdown/${id}`, {
|
||||
method: "DELETE",
|
||||
}),{
|
||||
onSuccess: (data) => {
|
||||
queryClient.invalidateQueries(["path_setting", data.id]);
|
||||
}
|
||||
}
|
||||
);
|
||||
};
|
||||
@@ -17,7 +17,7 @@ export const useWebhooks = () =>{
|
||||
);
|
||||
};
|
||||
|
||||
export const useCreateWebhook = () =>{
|
||||
export const useCreateWebhook = () => {
|
||||
const config = useConfig();
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
@@ -78,7 +78,6 @@ export const useWebhookSettings = () => {
|
||||
if(data){
|
||||
for(const setting of data){
|
||||
queryClient.setQueryData(["webhook_setting", setting.id], setting);
|
||||
queryClient.setQueryData(["webhook_setting_path_id", setting.path_id], setting);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -88,33 +87,14 @@ export const useWebhookSettings = () => {
|
||||
|
||||
export const useWebhookSetting = (setting_id) => {
|
||||
const config = useConfig();
|
||||
const queryClient = useQueryClient();
|
||||
return useQuery(
|
||||
["webhook_setting", setting_id],
|
||||
() => fetch_(`${config.BACKEND_HOST}/api/webhook/setting/${setting_id}`),
|
||||
{
|
||||
enabled: !!setting_id,
|
||||
onSuccess: (res) => {
|
||||
if(res)
|
||||
queryClient.setQueryData(["webhook_setting_path_id", res.path_id], res);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
export const useWebhookSettingByPathId = (pathId) => {
|
||||
const config = useConfig();
|
||||
const queryClient = useQueryClient();
|
||||
return useQuery(
|
||||
["webhook_setting_path_id", pathId],
|
||||
() => fetch_(`${config.BACKEND_HOST}/api/webhook/setting/path/${pathId}`),
|
||||
{
|
||||
enabled: !!pathId,
|
||||
onSuccess: (res) => {
|
||||
if(res)
|
||||
queryClient.setQueryData(["webhook_setting", res.id], res);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
export const useCreateWebhookSetting = () => {
|
||||
const config = useConfig();
|
||||
@@ -126,7 +106,6 @@ export const useCreateWebhookSetting = () => {
|
||||
}),{
|
||||
onSuccess: (res) => {
|
||||
queryClient.invalidateQueries(["webhook_setting", res.id]);
|
||||
queryClient.invalidateQueries(["webhook_setting_path_id", res.path_id]);
|
||||
queryClient.invalidateQueries("webhook_setting");
|
||||
}
|
||||
}
|
||||
@@ -143,7 +122,6 @@ export const useUpdateWebhookSetting = () => {
|
||||
}),{
|
||||
onSuccess: (res, variables) => {
|
||||
queryClient.invalidateQueries(["webhook_setting", variables.id]);
|
||||
queryClient.invalidateQueries(["webhook_setting_path_id", variables.path_id]);
|
||||
queryClient.invalidateQueries("webhook_setting");
|
||||
}
|
||||
}
|
||||
@@ -161,7 +139,6 @@ export const useDeleteWebhookSetting = () => {
|
||||
{
|
||||
onSuccess: (res, variables) => {
|
||||
queryClient.invalidateQueries(["webhook_setting", variables.id]);
|
||||
queryClient.invalidateQueries(["webhook_setting_path_id", variables.path_id]);
|
||||
queryClient.invalidateQueries("webhook_setting");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user