Merge pull request 'On list creation, no duplicate entry is shown anymore' (#30) from dev into main
This commit was merged in pull request #30.
This commit is contained in:
@@ -11,6 +11,12 @@ import type {
|
|||||||
|
|
||||||
export interface LocalList extends List {
|
export interface LocalList extends List {
|
||||||
pendingSync?: boolean
|
pendingSync?: boolean
|
||||||
|
// Stable identity for this list on this client, independent of `id`.
|
||||||
|
// `id` starts out as a client-generated placeholder and gets swapped for
|
||||||
|
// the server-assigned one once "createList" syncs (see remapListId) -
|
||||||
|
// clientId never changes, so UI code that needs a stable key across that
|
||||||
|
// swap (e.g. <TransitionGroup>'s :key) can use it instead of `id`.
|
||||||
|
clientId?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface LocalListItem extends ListItem {
|
export interface LocalListItem extends ListItem {
|
||||||
|
|||||||
+8
-2
@@ -147,8 +147,10 @@ export const useListsStore = defineStore('lists', () => {
|
|||||||
|
|
||||||
async function createList(name: string): Promise<LocalList> {
|
async function createList(name: string): Promise<LocalList> {
|
||||||
const now = new Date().toISOString()
|
const now = new Date().toISOString()
|
||||||
|
const id = generateId()
|
||||||
const localList: LocalList = {
|
const localList: LocalList = {
|
||||||
id: generateId(),
|
id,
|
||||||
|
clientId: id,
|
||||||
name,
|
name,
|
||||||
created_at: now,
|
created_at: now,
|
||||||
modified_at: now,
|
modified_at: now,
|
||||||
@@ -538,7 +540,11 @@ export const useListsStore = defineStore('lists', () => {
|
|||||||
for (const serverList of serverLists) {
|
for (const serverList of serverLists) {
|
||||||
const existingList = localById.get(serverList.id)
|
const existingList = localById.get(serverList.id)
|
||||||
if (!existingList || !existingList.pendingSync) {
|
if (!existingList || !existingList.pendingSync) {
|
||||||
toPut.push({ ...serverList, pendingSync: false })
|
toPut.push({
|
||||||
|
...serverList,
|
||||||
|
pendingSync: false,
|
||||||
|
clientId: existingList?.clientId ?? serverList.id,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (toPut.length > 0) {
|
if (toPut.length > 0) {
|
||||||
|
|||||||
@@ -110,7 +110,7 @@ async function handleCreateList() {
|
|||||||
<TransitionGroup v-if="displayedLists.length > 0" tag="ul" name="list-reorder" class="lists">
|
<TransitionGroup v-if="displayedLists.length > 0" tag="ul" name="list-reorder" class="lists">
|
||||||
<li
|
<li
|
||||||
v-for="list in displayedLists"
|
v-for="list in displayedLists"
|
||||||
:key="list.id"
|
:key="list.clientId ?? list.id"
|
||||||
:ref="(el) => setItemRef(list.id, el as Element | null)"
|
:ref="(el) => setItemRef(list.id, el as Element | null)"
|
||||||
class="list-row"
|
class="list-row"
|
||||||
:class="{ 'no-transition': isPointerActive && draggingId === list.id }"
|
:class="{ 'no-transition': isPointerActive && draggingId === list.id }"
|
||||||
|
|||||||
Reference in New Issue
Block a user