Browse Source

Feature: Add PinEditorUI filter for buttons

pull/169/head
winkidney 5 years ago
committed by Isaac Bythewood
parent
commit
41851a09a8
3 changed files with 67 additions and 10 deletions
  1. +42
    -5
      pinry-spa/src/components/Pins.vue
  2. +6
    -2
      pinry-spa/src/components/api.js
  3. +19
    -3
      pinry-spa/src/components/editors/PinEditorUI.vue

+ 42
- 5
pinry-spa/src/components/Pins.vue View File

@@ -23,6 +23,8 @@
<EditorUI <EditorUI
v-show="shouldShowEdit(item.id)" v-show="shouldShowEdit(item.id)"
:pin="item" :pin="item"
:currentUsername="editorMeta.user.meta.username"
:currentBoardId="editorMeta.currentBoard.id"
v-on:pin-delete-succeed="reset" v-on:pin-delete-succeed="reset"
></EditorUI> ></EditorUI>
<img :src="item.url" <img :src="item.url"
@@ -105,7 +107,6 @@ function createImageItem(pin) {


function initialData() { function initialData() {
return { return {
currentEditId: null,
blocks: [], blocks: [],
blocksMap: {}, blocksMap: {},
status: { status: {
@@ -113,6 +114,14 @@ function initialData() {
hasNext: true, hasNext: true,
offset: 0, offset: 0,
}, },
editorMeta: {
currentEditId: null,
currentBoard: {},
user: {
loggedIn: false,
meta: {},
},
},
}; };
} }


@@ -133,19 +142,20 @@ export default {
return { return {
tagFilter: null, tagFilter: null,
userFilter: null, userFilter: null,
boardFilter: null,
}; };
}, },
}, },
}, },
methods: { methods: {
shouldShowEdit(id) { shouldShowEdit(id) {
return this.currentEditId === id;
return this.editorMeta.currentEditId === id;
}, },
showEditButtons(id) { showEditButtons(id) {
this.currentEditId = id;
this.editorMeta.currentEditId = id;
}, },
hideEditButtons() { hideEditButtons() {
this.currentEditId = null;
this.editorMeta.currentEditId = null;
}, },
onPinImageLoaded(itemId) { onPinImageLoaded(itemId) {
this.blocksMap[itemId].class = { this.blocksMap[itemId].class = {
@@ -201,8 +211,23 @@ export default {
return true; return true;
}, },
initialize() { initialize() {
this.initializeMeta();
this.fetchMore(true); this.fetchMore(true);
}, },
initializeMeta() {
const self = this;
API.User.fetchUserInfo().then(
(user) => {
if (user === null) {
self.editorMeta.user.loggedIn = false;
self.editorMeta.user.meta = {};
} else {
self.editorMeta.user.meta = user;
self.editorMeta.user.loggedIn = true;
}
},
);
},
reset() { reset() {
const data = initialData(); const data = initialData();
Object.entries(data).forEach( Object.entries(data).forEach(
@@ -224,7 +249,19 @@ export default {
} else if (this.pinFilters.userFilter) { } else if (this.pinFilters.userFilter) {
promise = API.fetchPins(this.status.offset, null, this.pinFilters.userFilter); promise = API.fetchPins(this.status.offset, null, this.pinFilters.userFilter);
} else if (this.pinFilters.boardFilter) { } else if (this.pinFilters.boardFilter) {
promise = API.fetchPinsForBoard(this.pinFilters.boardFilter);
promise = new Promise(
(resolve, reject) => {
API.fetchPinsForBoard(this.pinFilters.boardFilter).then(
(resp) => {
this.editorMeta.currentBoard = resp.data.board;
resolve(resp);
},
(error) => {
reject(error);
},
);
},
);
} else if (this.pinFilters.idFilter) { } else if (this.pinFilters.idFilter) {
promise = API.fetchPin(this.pinFilters.idFilter); promise = API.fetchPin(this.pinFilters.idFilter);
} else { } else {


+ 6
- 2
pinry-spa/src/components/api.js View File

@@ -23,6 +23,10 @@ const Board = {
}, },
); );
}, },
get(boardId) {
const url = `${API_PREFIX}boards/${boardId}/`;
return axios.get(url);
},
fetchFullList(username) { fetchFullList(username) {
const url = `${API_PREFIX}boards-auto-complete/?submitter__username=${username}`; const url = `${API_PREFIX}boards-auto-complete/?submitter__username=${username}`;
return axios.get(url); return axios.get(url);
@@ -123,12 +127,12 @@ function fetchPin(pinId) {
} }


function fetchPinsForBoard(boardId) { function fetchPinsForBoard(boardId) {
const url = `${API_PREFIX}boards/${boardId}`;
const url = `${API_PREFIX}boards/${boardId}/`;
return new Promise( return new Promise(
(resolve, reject) => { (resolve, reject) => {
axios.get(url).then( axios.get(url).then(
(resp) => { (resp) => {
resolve({ data: { results: resp.data.pins_detail, next: null } });
resolve({ data: { results: resp.data.pins_detail, next: null, board: resp.data } });
}, },
error => reject(error), error => reject(error),
); );


+ 19
- 3
pinry-spa/src/components/editors/PinEditorUI.vue View File

@@ -1,7 +1,7 @@
<template> <template>
<div class="editor"> <div class="editor">
<div class="editor-buttons"> <div class="editor-buttons">
<span class="icon-container">
<span class="icon-container" v-if="inBoard">
<b-icon <b-icon
type="is-light" type="is-light"
icon="minus-box" icon="minus-box"
@@ -15,14 +15,14 @@
custom-size="mdi-24px"> custom-size="mdi-24px">
</b-icon> </b-icon>
</span> </span>
<span class="icon-container" @click="deletePin">
<span class="icon-container" @click="deletePin" v-if="isOwner">
<b-icon <b-icon
type="is-light" type="is-light"
icon="delete" icon="delete"
custom-size="mdi-24px"> custom-size="mdi-24px">
</b-icon> </b-icon>
</span> </span>
<span class="icon-container">
<span class="icon-container" v-if="isOwner">
<b-icon <b-icon
type="is-light" type="is-light"
icon="pencil" icon="pencil"
@@ -39,6 +39,14 @@ import API from '../api';
export default { export default {
name: 'Editor', name: 'Editor',
props: { props: {
currentBoardId: {
type: Number,
default: null,
},
currentUsername: {
default: '',
type: String,
},
pin: { pin: {
default() { default() {
return {}; return {};
@@ -46,6 +54,14 @@ export default {
type: Object, type: Object,
}, },
}, },
computed: {
isOwner() {
return this.pin.author === this.currentUsername;
},
inBoard() {
return this.currentBoardId !== null;
},
},
methods: { methods: {
deletePin() { deletePin() {
this.$buefy.dialog.confirm({ this.$buefy.dialog.confirm({


Loading…
Cancel
Save