Skip to content

Commit

Permalink
#10 - Added toasts to shortcut
Browse files Browse the repository at this point in the history
  • Loading branch information
Anders164a committed Oct 18, 2023
1 parent f5682cc commit b3d06eb
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 12 deletions.
26 changes: 20 additions & 6 deletions src/components/item/CreateShortcutModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ import { t } from '@lib/i18n';
import { api } from '@lib/helpers';
import { ItemFactory } from '@lib/items/factory';
import { ItemClass } from '@lib/items/items';
import { addToast } from '@stores/toasts';
import { ToastType } from '@components/base/toast.vue';
const props = defineProps({
item: {
Expand Down Expand Up @@ -134,12 +136,24 @@ async function createShortcut() {
const folder = await folders.value.filter((x) => x.id === selectedFolder)[0];
if (folder || selectedFolder === 0) {
await ShortcutClass.create({
name: item.value.name,
parentId: folder?.id ?? null,
linkedItemId: item.value.id,
});
close();
try {
await ShortcutClass.create({
name: item.value.name,
parentId: folder?.id ?? null,
linkedItemId: item.value.id,
});
close();
addToast({
message: item.value.name + ' ' + t('fileBrowser.shortcut.toast.create.success'),
type: ToastType.Success,
});
} catch (e) {
addToast({
message: t('fileBrowser.shortcut.toast.create.failed') + ' ' + item.value.name,
type: ToastType.Danger,
});
}
}
}
Expand Down
14 changes: 12 additions & 2 deletions src/components/item/docs/EditShortcutModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import BaseButton, { ButtonColor } from '@components/base/button.vue';
import ErrorAlert, { type ErrorObject } from '@components/base/errorAlert.vue';
import { t } from '@lib/i18n';
import type { ShortcutClass } from '@lib/items/shortcuts';
import { addToast } from '@stores/toasts';
import { ToastType } from '@components/base/toast.vue';
const props = defineProps({
shortcut: {
Expand Down Expand Up @@ -65,10 +67,18 @@ async function updateFile() {
updateItem(updatedShortcut);
// TODO: Show success toast
addToast({
message: props.shortcut.name + ' ' + t('fileBrowser.shortcut.toast.update.success'),
type: ToastType.Success,
});
close(false);
} catch (e) {}
} catch (e) {
addToast({
message: t('fileBrowser.folder.toast.update.failed') + ' ' + props.shortcut.name,
type: ToastType.Danger,
});
}
}
function open() {
Expand Down
14 changes: 12 additions & 2 deletions src/components/item/file/EditShortcutModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import BaseButton, { ButtonColor } from '@components/base/button.vue';
import ErrorAlert, { type ErrorObject } from '@components/base/errorAlert.vue';
import { t } from '@lib/i18n';
import type { ShortcutClass } from '@lib/items/shortcuts';
import { addToast } from '@stores/toasts';
import { ToastType } from '@components/base/toast.vue';
const props = defineProps({
shortcut: {
Expand Down Expand Up @@ -65,10 +67,18 @@ async function updateFile() {
updateItem(updatedShortcut);
// TODO: Show success toast
addToast({
message: props.shortcut.name + ' ' + t('fileBrowser.shortcut.toast.update.success'),
type: ToastType.Success,
});
close();
} catch (e) {}
} catch (e) {
addToast({
message: t('fileBrowser.folder.toast.update.failed') + ' ' + props.shortcut.name,
type: ToastType.Danger,
});
}
}
function open() {
Expand Down
14 changes: 12 additions & 2 deletions src/components/item/folder/EditShortcutModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import BaseButton, { ButtonColor } from '@components/base/button.vue';
import ErrorAlert, { type ErrorObject } from '@components/base/errorAlert.vue';
import { t } from '@lib/i18n';
import type { ShortcutClass } from '@lib/items/shortcuts';
import { addToast } from '@stores/toasts';
import { ToastType } from '@components/base/toast.vue';
const props = defineProps({
shortcut: {
Expand Down Expand Up @@ -65,10 +67,18 @@ async function updateFolder() {
updateItem(updatedShortcut);
// TODO: Show success toast
addToast({
message: props.shortcut.name + ' ' + t('fileBrowser.shortcut.toast.update.success'),
type: ToastType.Success,
});
close();
} catch (e) {}
} catch (e) {
addToast({
message: t('fileBrowser.folder.toast.update.failed') + ' ' + props.shortcut.name,
type: ToastType.Danger,
});
}
}
function open() {
Expand Down
14 changes: 14 additions & 0 deletions src/lang/da.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,20 @@ export default {
delete: 'Slet',
openInNewTab: 'Åben i nyt faneblad',
},
toast: {
create: {
success: 'er blevet oprettet (Genvej)',
failed: 'Fejl i opretning af',
},
update: {
success: 'er blevet opdateret',
failed: 'Fejl under opdatering af',
},
delete: {
success: 'er blevet slettet',
failed: 'Fejl i sletning af',
},
},
},
},
layout: {
Expand Down
14 changes: 14 additions & 0 deletions src/lang/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,20 @@ export default {
delete: 'Delete',
openInNewTab: 'Open in new tab',
},
toast: {
create: {
success: 'has been created (Shortcut)',
failed: 'Failed to create',
},
update: {
success: 'has been updated',
failed: 'Failed to update',
},
delete: {
success: 'has been deleted',
failed: 'Failed to delete',
},
},
},
},
layout: {
Expand Down

0 comments on commit b3d06eb

Please sign in to comment.