Skip to content

Commit

Permalink
add wip useUser hook
Browse files Browse the repository at this point in the history
  • Loading branch information
paoloose committed Nov 25, 2024
1 parent 98ee246 commit 01b126b
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions app/src/stores/useUser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { create } from 'zustand';
import { UserContentFileElement } from '@/types';

type MetagalleryUser = {
username: string;
fullname: string;
email: string;
token: string;
};

/**
* Represents the state of the editor and the global actions that can be performed.
* There is no 'dragging' state. Use {draggingFile != null} instead.
*/
interface MetagalleryUserState {
// Represents a sidebar element being dragged.
draggingFile: UserContentFileElement | null,
isDraggingFileVisible: boolean,
startDragging: (f: UserContentFileElement) => void,
dropFile: () => void,
setDraggingFileVisible: (visible: boolean) => void,
}

export const useUser = create<MetagalleryUserState>()(
(set, get) => ({
draggingFile: null,
isDraggingFileVisible: false,
startDragging: (file: UserContentFileElement) => set({ draggingFile: file, isDraggingFileVisible: true }),
dropFile: () => {
if (get().draggingFile) {
set({ draggingFile: null, isDraggingFileVisible: false });
}
},
setDraggingFileVisible: (visible: boolean) => set({ isDraggingFileVisible: visible }),
}),
);

0 comments on commit 01b126b

Please sign in to comment.