diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index 057ac91..050eb11 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -20,10 +20,10 @@ jobs: run: | DOCKER_IMAGE=ghcr.io/${{ github.repository }} VERSION=latest - if [[ $GITHUB_REF == refs/tags/* ]]; then - VERSION=${GITHUB_REF#refs/tags/v} + if [[ '${{ github.head_ref }}' != 'master' ]]; then + VERSION=${{github.head_ref}} fi - TAGS="${DOCKER_IMAGE}:latest,${DOCKER_IMAGE}:${{ steps.date.outputs.date }}" + TAGS="${DOCKER_IMAGE}:${VERSION},${DOCKER_IMAGE}:${{ steps.date.outputs.date }}" echo ::set-output name=tags::${TAGS} - name: Set up QEMU diff --git a/client/src/components/Apps/AppForm/AppForm.tsx b/client/src/components/Apps/AppForm/AppForm.tsx index 83dca72..2a659a4 100644 --- a/client/src/components/Apps/AppForm/AppForm.tsx +++ b/client/src/components/Apps/AppForm/AppForm.tsx @@ -30,7 +30,7 @@ interface ComponentProps { } const AppForm = (props: ComponentProps): JSX.Element => { - const [useCustomIcon, toggleUseCustomIcon] = useState(false); + const [useCustomIcon, setUseCustomIcon] = useState(false); const [customIcon, setCustomIcon] = useState(null); const [categoryData, setCategoryData] = useState({ name: '', @@ -77,13 +77,12 @@ const AppForm = (props: ComponentProps): JSX.Element => { const createFormData = (): FormData => { const data = new FormData(); - + Object.entries(appData).forEach((entry: [string, any]) => { + data.append(entry[0], entry[1]); + }); if (customIcon) { data.append('icon', customIcon); } - data.append('name', appData.name); - data.append('url', appData.url); - data.append('categoryId', appData.categoryId.toString()); return data; }; @@ -150,6 +149,11 @@ const AppForm = (props: ComponentProps): JSX.Element => { [e.target.name]: e.target.value }) } + + const toggleUseCustomIcon = (): void => { + setUseCustomIcon(!useCustomIcon); + setCustomIcon(null); + }; const fileChangeHandler = (e: ChangeEvent): void => { if (e.target.files) { @@ -272,7 +276,7 @@ const AppForm = (props: ComponentProps): JSX.Element => { toggleUseCustomIcon(!useCustomIcon)} + onClick={() => toggleUseCustomIcon()} className={classes.Switch}> Switch to custom icon upload @@ -286,10 +290,10 @@ const AppForm = (props: ComponentProps): JSX.Element => { id='icon' required onChange={(e) => fileChangeHandler(e)} - accept=".jpg,.jpeg,.png,.svg" + accept='.jpg,.jpeg,.png,.svg' /> toggleUseCustomIcon(!useCustomIcon)} + onClick={() => toggleUseCustomIcon()} className={classes.Switch}> Switch to MDI diff --git a/client/src/components/Bookmarks/BookmarkCard/BookmarkCard.tsx b/client/src/components/Bookmarks/BookmarkCard/BookmarkCard.tsx index b9b16e5..8c4014c 100644 --- a/client/src/components/Bookmarks/BookmarkCard/BookmarkCard.tsx +++ b/client/src/components/Bookmarks/BookmarkCard/BookmarkCard.tsx @@ -7,7 +7,7 @@ import classes from './BookmarkCard.module.css'; interface ComponentProps { category: Category; - bookmarks: Bookmark[] + bookmarks: Bookmark[]; pinHandler?: Function; } diff --git a/client/src/components/Bookmarks/BookmarkForm/BookmarkForm.tsx b/client/src/components/Bookmarks/BookmarkForm/BookmarkForm.tsx index 2cc51c6..b023db6 100644 --- a/client/src/components/Bookmarks/BookmarkForm/BookmarkForm.tsx +++ b/client/src/components/Bookmarks/BookmarkForm/BookmarkForm.tsx @@ -26,12 +26,10 @@ interface ComponentProps { addBookmark: (formData: NewBookmark | FormData) => void; updateBookmarkCategory: (id: number, formData: NewCategory) => void; updateBookmark: ( - id: number, - formData: NewBookmark | FormData, - category: { - prev: number, - curr: number - }) => void; + id: number, + formData: NewBookmark | FormData, + previousCategoryId: number + ) => void; createNotification: (notification: NewNotification) => void; } @@ -39,13 +37,13 @@ const BookmarkForm = (props: ComponentProps): JSX.Element => { const [useCustomIcon, setUseCustomIcon] = useState(false); const [customIcon, setCustomIcon] = useState(null); const [categoryData, setCategoryData] = useState({ - name: '', - type: 'bookmarks' - }) + name: "", + type: "bookmarks", + }); const [bookmarkData, setBookmarkData] = useState({ - name: '', - url: '', + name: "", + url: "", categoryId: -1, icon: '', }); @@ -55,7 +53,7 @@ const BookmarkForm = (props: ComponentProps): JSX.Element => { if (props.category) { setCategoryData({ name: props.category.name, type: props.category.type }); } else { - setCategoryData({ name: '', type: "bookmarks" }); + setCategoryData({ name: "", type: "bookmarks" }); } }, [props.category]); @@ -70,8 +68,8 @@ const BookmarkForm = (props: ComponentProps): JSX.Element => { }); } else { setBookmarkData({ - name: '', - url: '', + name: "", + url: "", categoryId: -1, icon: '', }); @@ -86,9 +84,9 @@ const BookmarkForm = (props: ComponentProps): JSX.Element => { if (customIcon) { data.append('icon', customIcon); } - data.append('name', bookmarkData.name); - data.append('url', bookmarkData.url); - data.append('categoryId', `${bookmarkData.categoryId}`); + Object.entries(bookmarkData).forEach((entry: [string, any]) => { + data.append(entry[0], entry[1]); + }); return data; }; @@ -98,7 +96,7 @@ const BookmarkForm = (props: ComponentProps): JSX.Element => { if (props.contentType === ContentType.category) { // Add category props.addBookmarkCategory(categoryData); - setCategoryData({ name: '', type: 'bookmarks' }); + setCategoryData({ name: "", type: "bookmarks" }); } else if (props.contentType === ContentType.bookmark) { // Add bookmark if (bookmarkData.categoryId === -1) { @@ -115,10 +113,10 @@ const BookmarkForm = (props: ComponentProps): JSX.Element => { } else { props.addBookmark(bookmarkData); } - + setBookmarkData({ - name: '', - url: '', + name: "", + url: "", categoryId: bookmarkData.categoryId, icon: '' }); @@ -130,33 +128,18 @@ const BookmarkForm = (props: ComponentProps): JSX.Element => { if (props.contentType === ContentType.category && props.category) { // Update category props.updateBookmarkCategory(props.category.id, categoryData); - setCategoryData({ name: '', type: 'bookmarks' }); + setCategoryData({ name: "", type: "bookmarks" }); } else if (props.contentType === ContentType.bookmark && props.bookmark) { // Update bookmark - if (customIcon) { - const data = createFormData(); - props.updateBookmark( - props.bookmark.id, - data, - { - prev: props.bookmark.categoryId, - curr: bookmarkData.categoryId - } - ) - } else { - props.updateBookmark( - props.bookmark.id, - bookmarkData, - { - prev: props.bookmark.categoryId, - curr: bookmarkData.categoryId - } - ); - } - + props.updateBookmark( + props.bookmark.id, + createFormData(), + props.bookmark.categoryId + ); + setBookmarkData({ - name: '', - url: '', + name: "", + url: "", categoryId: -1, icon: '', }); diff --git a/client/src/components/Bookmarks/Bookmarks.tsx b/client/src/components/Bookmarks/Bookmarks.tsx index c332687..e8c23d0 100644 --- a/client/src/components/Bookmarks/Bookmarks.tsx +++ b/client/src/components/Bookmarks/Bookmarks.tsx @@ -50,10 +50,10 @@ const Bookmarks = (props: ComponentProps): JSX.Element => { updatedAt: new Date(), }); const [bookmarkInUpdate, setBookmarkInUpdate] = useState({ - name: "", - url: "", + name: "string", + url: "string", categoryId: -1, - icon: "", + icon: "string", isPinned: false, orderId: 0, id: 0, @@ -113,10 +113,7 @@ const Bookmarks = (props: ComponentProps): JSX.Element => { {!isInUpdate ? ( - + ) : formContentType === ContentType.category ? ( async (dispatch: Dispatch) => { /** * ADD APP - */ + */ export interface AddAppAction { type: ActionTypes.addAppSuccess; payload: App; } -export const addApp = (formData: NewApp | FormData) => async (dispatch: Dispatch) => { - try { - const res = await axios.post>("/api/apps", formData); +export const addApp = + (formData: NewApp | FormData) => async (dispatch: Dispatch) => { + try { + const res = await axios.post>("/api/apps", formData); - dispatch({ - type: ActionTypes.createNotification, - payload: { - title: "Success", - message: `App ${res.data.data.name} added`, - }, - }); + dispatch({ + type: ActionTypes.createNotification, + payload: { + title: "Success", + message: `App ${res.data.data.name} added`, + }, + }); - await dispatch({ - type: ActionTypes.addAppSuccess, - payload: res.data.data, - }); + await dispatch({ + type: ActionTypes.addAppSuccess, + payload: res.data.data, + }); - // Sort apps - dispatch(sortApps()); - } catch (err) { - console.log(err); - } -}; + // Sort apps + dispatch(sortApps()); + } catch (err) { + console.log(err); + } + }; /** * PIN CATEGORY diff --git a/client/src/store/actions/bookmark.ts b/client/src/store/actions/bookmark.ts index 3f77b03..4115c5b 100644 --- a/client/src/store/actions/bookmark.ts +++ b/client/src/store/actions/bookmark.ts @@ -136,7 +136,8 @@ export const pinBookmark = /** * ADD BOOKMARK - */ export interface AddBookmarkAction { + */ +export interface AddBookmarkAction { type: ActionTypes.addBookmarkSuccess; payload: Bookmark; } @@ -442,7 +443,7 @@ export interface ReorderBookmarkCategoriesAction { payload: Category[]; } -interface ReorderReorderCategoriesQueryuery { +interface ReorderCategoriesQuery { categories: { id: number; orderId: number; @@ -452,7 +453,7 @@ interface ReorderReorderCategoriesQueryuery { export const reorderBookmarkCategories = (categories: Category[]) => async (dispatch: Dispatch) => { try { - const updateQuery: ReorderReorderCategoriesQueryuery = { categories: [] }; + const updateQuery: ReorderCategoriesQuery = { categories: [] }; categories.forEach((category, index) => updateQuery.categories.push({ diff --git a/routes/bookmark.js b/routes/bookmark.js index 4600c5d..e65f2bd 100644 --- a/routes/bookmark.js +++ b/routes/bookmark.js @@ -22,8 +22,8 @@ router .put(upload, updateBookmark) .delete(deleteBookmark); - router - .route('/0/reorder') - .put(reorderBookmarks); +router + .route('/0/reorder') + .put(reorderBookmarks); module.exports = router; \ No newline at end of file