Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Shopping list UI overhaul - collapsible labels #4378

Merged
merged 9 commits into from
Oct 25, 2024
63 changes: 52 additions & 11 deletions frontend/pages/shopping-lists/_id.vue
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,22 @@
<!-- View By Label -->
<div v-else>
<div v-for="(value, key) in itemsByLabel" :key="key" class="mb-6">
<div class="text-left">
<v-btn
:color="getLabelColor(value[0]) ? getLabelColor(value[0]) : '#959595'"
:style="{
<v-btn
:color="getLabelColor(value[0]) ? getLabelColor(value[0]) : '#959595'"
:style="{
'color': getTextColor(getLabelColor(value[0])),
'letter-spacing': 'normal',
}"
>
{{ key }}
@click="toggleShowLabel(key)"
>
<v-icon>
{{ labelOpenState[key] ? $globals.icons.chevronDown : $globals.icons.chevronRight }}
</v-icon>
{{ key }}
</v-btn>
</div>
<v-divider/>
<v-divider/>
<v-expand-transition group>
<div v-show="labelOpenState[key]">
<draggable :value="value" handle=".handle" delay="250" :delay-on-touch-only="true" @start="loadingCounter += 1" @end="loadingCounter -= 1" @input="updateIndexUncheckedByLabel(key, $event)">
<v-lazy v-for="(item, index) in value" :key="item.id" class="ml-2 my-2">
<ShoppingListItem
Expand All @@ -83,7 +87,9 @@
@delete="deleteListItem(item)"
/>
</v-lazy>
</draggable>
</draggable>
</div>
</v-expand-transition>
</div>
</div>

Expand Down Expand Up @@ -293,7 +299,7 @@
<script lang="ts">
import draggable from "vuedraggable";

import { defineComponent, useRoute, computed, ref, toRefs, onUnmounted, useContext, reactive } from "@nuxtjs/composition-api";
import { defineComponent, useRoute, computed, ref, toRefs, onUnmounted, useContext, reactive, watch } from "@nuxtjs/composition-api";
import { useIdle, useToggle } from "@vueuse/core";
import { useCopyList } from "~/composables/use-copy";
import { useUserApi } from "~/composables/api";
Expand Down Expand Up @@ -455,6 +461,39 @@ export default defineComponent({
};
});

// =====================================
// Collapsables
const labelOpenState = ref<{ [key: string]: boolean }>({});

const initializeLabelOpenStates = () => {
if (!shoppingList.value?.listItems) return;

const existingLabels = new Set(Object.keys(labelOpenState.value));
let hasChanges = false;

for (const item of shoppingList.value.listItems) {
const labelName = item.label?.name;
if (labelName && !existingLabels.has(labelName) && !(labelName in labelOpenState.value)) {
labelOpenState.value[labelName] = true;
hasChanges = true;
}
}

if (hasChanges) {
labelOpenState.value = { ...labelOpenState.value };
}
};

const labelNames = computed(() =>
new Set(shoppingList.value?.listItems?.map(item => item.label?.name).filter(Boolean) ?? [])
);

watch(labelNames, initializeLabelOpenStates, { immediate: true });

function toggleShowLabel(key: string) {
labelOpenState.value[key] = !labelOpenState.value[key];
}

const [showChecked, toggleShowChecked] = useToggle(false);

// =====================================
Expand Down Expand Up @@ -1025,7 +1064,7 @@ export default defineComponent({
}

// update current user
allUsers.value = data.items.sort((a, b) => ((a.fullName || "") < (b.fullName || "") ? -1 : 1));
allUsers.value = data.sort((a, b) => ((a.fullName || "") < (b.fullName || "") ? -1 : 1));
currentUserId.value = shoppingList.value?.userId;
Wetzel402 marked this conversation as resolved.
Show resolved Hide resolved
}

Expand Down Expand Up @@ -1082,6 +1121,8 @@ export default defineComponent({
shoppingList,
showChecked,
sortByLabels,
labelOpenState,
toggleShowLabel,
toggleShowChecked,
uncheckAll,
openUncheckAll,
Expand Down
Loading