This commit is contained in:
@@ -1,12 +1,41 @@
|
||||
import Server from './Server';
|
||||
|
||||
const SELECTED_CAMPAIGN_KEY = 'selectedCampaignId';
|
||||
|
||||
export const useCampaignService = () => {
|
||||
const Campaign = useState('campaign', () => null)
|
||||
|
||||
const SetCampaign = (data) => {
|
||||
Campaign.value = data;
|
||||
if (data?._id) {
|
||||
localStorage.setItem(SELECTED_CAMPAIGN_KEY, data._id);
|
||||
} else {
|
||||
localStorage.removeItem(SELECTED_CAMPAIGN_KEY);
|
||||
}
|
||||
}
|
||||
|
||||
const RestoreCampaign = async () => {
|
||||
const campaignId = localStorage.getItem(SELECTED_CAMPAIGN_KEY);
|
||||
if (!campaignId) return false;
|
||||
|
||||
try {
|
||||
const response = await Server().get(`/campaign/retrieve/${campaignId}`);
|
||||
if (response.data.status !== 'ok') {
|
||||
SetCampaign(null);
|
||||
return false;
|
||||
}
|
||||
|
||||
SetCampaign(response.data.campaign);
|
||||
return true;
|
||||
} catch (error) {
|
||||
SetCampaign(null);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
Campaign,
|
||||
SetCampaign
|
||||
SetCampaign,
|
||||
RestoreCampaign
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
import { Marked } from "marked";
|
||||
|
||||
const marker = new Marked();
|
||||
|
||||
// optional: use a shared marked instance inside renderer
|
||||
const renderMarkdown = (text) => marker.parse(text);
|
||||
|
||||
const WidgetMap = {
|
||||
test: () => import("~/components/viewer/widgets/TestWidget.vue"),
|
||||
table: () => import("~/components/viewer/widgets/TableWidget.vue"),
|
||||
};
|
||||
|
||||
const extension = {
|
||||
name: "something",
|
||||
level: "block",
|
||||
|
||||
tokenizer(src) {
|
||||
const rule = /^@(\w+)\n([\s\S]+?)\n@end/;
|
||||
const match = rule.exec(src);
|
||||
|
||||
if (!match) return;
|
||||
|
||||
return {
|
||||
type: "something",
|
||||
raw: match[0],
|
||||
name: match[1],
|
||||
text: match[2],
|
||||
};
|
||||
},
|
||||
|
||||
renderer(token) {
|
||||
return `<div class="vue-component" data-component="${token.name}" data-content="${token.text}"></div>`;
|
||||
},
|
||||
};
|
||||
|
||||
marker.use({
|
||||
extensions: [extension],
|
||||
});
|
||||
|
||||
function ParseMarkdown(source) {
|
||||
return marker.parse(source || "");
|
||||
}
|
||||
|
||||
export { ParseMarkdown, WidgetMap };
|
||||
@@ -64,6 +64,7 @@ function LoadUser(){
|
||||
|
||||
function LogoutUser(){
|
||||
localStorage.removeItem("token");
|
||||
localStorage.removeItem("selectedCampaignId");
|
||||
UserStatus.value = 0;
|
||||
}
|
||||
|
||||
@@ -77,4 +78,4 @@ export {
|
||||
HasAdmin,
|
||||
GetUserSetting,
|
||||
SetUserSetting
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user