Skip to content

Commit

Permalink
feat: allow entering data for years in the past
Browse files Browse the repository at this point in the history
closes #35
  • Loading branch information
simonwep committed Apr 22, 2024
1 parent 6ef45c0 commit 7dcca7a
Show file tree
Hide file tree
Showing 13 changed files with 61 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/app/components/base/context-menu/ContextMenu.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export type ContextMenuOptionId = number | string;

export interface ContextMenuOption {
id: ContextMenuOptionId;
muted?: boolean;
icon?: Component;
label?: string;
}
1 change: 1 addition & 0 deletions src/app/components/base/context-menu/ContextMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
:pad-icon="hasOptionWithIcon"
:text="option.label ?? option.id"
:icon="option.icon"
:muted="option.muted"
:highlight="option.id === highlight"
@click="select(option)"
/>
Expand Down
9 changes: 8 additions & 1 deletion src/app/components/base/context-menu/ContextMenuButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ const props = withDefaults(
class?: ClassNames;
text: string | number;
icon?: Component;
muted?: boolean;
padIcon?: boolean;
highlight?: boolean;
}>(),
{
highlight: false,
padIcon: false
padIcon: false,
muted: false
}
);
Expand All @@ -38,6 +40,7 @@ const classes = computed(() => [
props.class,
styles.btn,
{
[styles.muted]: props.muted,
[styles.highlight]: props.highlight,
[styles.padIcon]: props.padIcon && !props.icon
}
Expand Down Expand Up @@ -86,6 +89,10 @@ const onClick = (evt: MouseEvent) => {
padding-left: calc(12px + 20px);
}
&.muted {
color: var(--context-menu-item-color-muted);
}
&:hover,
&.highlight {
color: var(--context-menu-item-color-hover);
Expand Down
4 changes: 3 additions & 1 deletion src/app/pages/navigation/tools/ToolsButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<ImportButton />
<CopyButton />
<PasteButton />
<DeleteYearButton />
</template>
</ContextMenu>
</template>
Expand All @@ -30,9 +31,10 @@ import { ClassNames } from '@utils';
import ChangePasswordButton from './change-password/ChangePasswordButton.vue';
import CopyButton from './copy-paste/CopyButton.vue';
import PasteButton from './copy-paste/PasteButton.vue';
import LoadDemoDataButton from './demo/LoadDemoDataButton.vue';
import DeleteYearButton from './delete-year/DeleteYearButton.vue';
import ExportButton from './export/ExportButton.vue';
import ImportButton from './import/ImportButton.vue';
import LoadDemoDataButton from './load-demo-data/LoadDemoDataButton.vue';
import PrivacyModeButton from './privacy-mode/PrivacyModeButton.vue';
const props = defineProps<{
Expand Down
24 changes: 24 additions & 0 deletions src/app/pages/navigation/tools/delete-year/DeleteYearButton.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<template>
<ContextMenuButton
v-if="state.activeYear === state.years[0].year && state.years.length > 1"
:text="t('navigation.tools.deleteYear.delete', { year: state.activeYear })"
:icon="RiDeleteBin5Line"
@click="deleteCurrentYear"
/>
</template>

<script lang="ts" setup>
import { RiDeleteBin5Line } from '@remixicon/vue';
import { useI18n } from 'vue-i18n';
import ContextMenuButton from '@components/base/context-menu/ContextMenuButton.vue';
import { useDataStore } from '@store/state';
const { state, shiftYears } = useDataStore();
const { t } = useI18n();
const deleteCurrentYear = () => {
if (window.confirm(t('navigation.tools.deleteYear.confirm'))) {
shiftYears();
}
};
</script>
5 changes: 3 additions & 2 deletions src/app/pages/navigation/year/ChangeYearButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,13 @@ const time = useTime();
const classes = computed(() => props.class);
const options = computed((): ContextMenuOption[] => {
const yearsStored = state.years.map((v) => v.year);
const offset = Math.min(...yearsStored);
const firstYear = Math.min(...yearsStored);
const list: ContextMenuOption[] = [];
for (let year = offset; year <= time.year.value + PRE_PLANNABLE_YEARS; year++) {
for (let year = firstYear - 1; year <= time.year.value + PRE_PLANNABLE_YEARS; year++) {
list.push({
id: year,
muted: year === firstYear - 1,
icon: state.activeYear === year ? RiCalendarCheckLine : RiCalendarTodoLine
});
}
Expand Down
4 changes: 4 additions & 0 deletions src/i18n/locales/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
"demo": {
"loadDemoData": "Demo-Daten laden"
},
"deleteYear": {
"delete": "Jahr {year} entfernen",
"confirm": "Sind Sie sicher, dass Sie das Jahr {year} löschen möchten?"
},
"export": {
"export": "Als JSON-Datei exportieren"
},
Expand Down
4 changes: 4 additions & 0 deletions src/i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
"demo": {
"loadDemoData": "Load demo data"
},
"deleteYear": {
"delete": "Remove {year}",
"confirm": "Are you sure you want to remove {year}?"
},
"export": {
"export": "Export as json file"
},
Expand Down
11 changes: 11 additions & 0 deletions src/store/state/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ interface Store {
deserialize(file: File): Promise<void>;
deserialize(file: DataState): Promise<void>;

shiftYears(): void;
changeYear(year: number): void;
changeLocale(locale: AvailableLocale): void;
changeCurrency(currency: AvailableCurrency): void;
Expand Down Expand Up @@ -181,6 +182,16 @@ export const createDataStore = (storage?: Storage): Store => {
}
},

shiftYears() {
if (state.years.length > 1) {
const item = state.years.shift();

if (item?.year === activeYear.value) {
activeYear.value = state.years.at(0)?.year as number;
}
}
},

changeYear(year: number) {
let data = state.years.find((v) => v.year === year);

Expand Down
1 change: 1 addition & 0 deletions src/styles/themes/dark.scss
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@
--dialog-box-shadow: 0 2px 10px #00000080;

--context-menu-item-color: #c1c1cf;
--context-menu-item-color-muted: #6e6e72;
--context-menu-item-color-hover: #ededf6;
--context-menu-item-background-hover: #00000080;
--context-menu-backdrop: blur(4px) brightness(0.25);
Expand Down
1 change: 1 addition & 0 deletions src/styles/themes/light.scss
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@
--dialog-box-shadow: 0 2px 5px #00000012;

--context-menu-item-color: #777788;
--context-menu-item-color-muted: #cacfda;
--context-menu-item-color-hover: #222228;
--context-menu-item-background-hover: #0000000d;
--context-menu-backdrop: brightness(10);
Expand Down

0 comments on commit 7dcca7a

Please sign in to comment.