-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: admin blocks page + lazy load blocks + block-index
- Loading branch information
Showing
22 changed files
with
511 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
compiled | ||
dist | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,70 +1,109 @@ | ||
import { LitElement, html, css } from 'lit' | ||
import folderByPath from './folderByPath.graphql' | ||
import treeQuery from './folderByPath.graphql' | ||
|
||
/** | ||
* An example element. | ||
* | ||
* @fires count-changed - Indicates when the count changes | ||
* @slot - This element has a slot | ||
* @csspart button - The button | ||
* Block Index | ||
*/ | ||
export class BlockIndexElement extends LitElement { | ||
static get styles() { | ||
return css` | ||
:host { | ||
display: block; | ||
border: solid 1px gray; | ||
padding: 16px; | ||
max-width: 800px; | ||
margin-bottom: 16px; | ||
} | ||
`; | ||
:host-context(body.body--dark) { | ||
background-color: #F00; | ||
} | ||
ul { | ||
padding: 0; | ||
margin: 0; | ||
list-style: none; | ||
} | ||
li { | ||
background-color: #fafafa; | ||
background-image: linear-gradient(180deg,#fff,#fafafa); | ||
border-right: 1px solid #eee; | ||
border-bottom: 1px solid #eee; | ||
border-left: 5px solid #e0e0e0; | ||
box-shadow: 0 3px 8px 0 rgba(116,129,141,.1); | ||
padding: 0; | ||
border-radius: 5px; | ||
font-weight: 500; | ||
} | ||
li:hover { | ||
background-image: linear-gradient(180deg,#fff,#f6fbfe); | ||
border-left-color: #2196f3; | ||
cursor: pointer; | ||
} | ||
li + li { | ||
margin-top: .5rem; | ||
} | ||
li a { | ||
display: block; | ||
color: #1976d2; | ||
padding: 1rem; | ||
text-decoration: none; | ||
} | ||
` | ||
} | ||
|
||
static get properties() { | ||
return { | ||
/** | ||
* The name to say "Hello" to. | ||
* The base path to fetch pages from | ||
* @type {string} | ||
*/ | ||
name: {type: String}, | ||
path: {type: String}, | ||
|
||
/** | ||
* The number of times the button has been clicked. | ||
* A comma-separated list of tags to filter with | ||
* @type {string} | ||
*/ | ||
tags: {type: String}, | ||
|
||
/** | ||
* The maximum number of items to fetch | ||
* @type {number} | ||
*/ | ||
count: {type: Number}, | ||
}; | ||
limit: {type: Number} | ||
} | ||
} | ||
|
||
constructor() { | ||
super(); | ||
this.name = 'World'; | ||
this.count = 0; | ||
super() | ||
this.pages = [] | ||
} | ||
|
||
async connectedCallback() { | ||
super.connectedCallback() | ||
const resp = await APOLLO_CLIENT.query({ | ||
query: treeQuery, | ||
variables: { | ||
siteId: WIKI_STORES.site.id, | ||
locale: 'en', | ||
parentPath: '' | ||
} | ||
}) | ||
this.pages = resp.data.tree | ||
this.requestUpdate() | ||
} | ||
|
||
render() { | ||
return html` | ||
<h1>${this.sayHello(this.name)}!</h1> | ||
<button @click=${this._onClick} part="button"> | ||
Click Count: ${this.count} | ||
</button> | ||
<ul> | ||
${this.pages.map(p => | ||
html`<li><a href="#">${p.title}</a></li>` | ||
)} | ||
</ul> | ||
<slot></slot> | ||
`; | ||
} | ||
|
||
_onClick() { | ||
this.count++; | ||
this.dispatchEvent(new CustomEvent('count-changed')); | ||
` | ||
} | ||
|
||
/** | ||
* Formats a greeting | ||
* @param name {string} The name to say "Hello" to | ||
* @returns {string} A greeting directed at `name` | ||
*/ | ||
sayHello(name) { | ||
return `Hello, ${name}`; | ||
} | ||
// createRenderRoot() { | ||
// return this; | ||
// } | ||
} | ||
|
||
window.customElements.define('block-index', BlockIndexElement); | ||
window.customElements.define('block-index', BlockIndexElement) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { generateError, generateSuccess } from '../../helpers/graph.mjs' | ||
|
||
export default { | ||
Query: { | ||
async blocks (obj, args, context) { | ||
return WIKI.db.blocks.query().where({ | ||
siteId: args.siteId | ||
}) | ||
} | ||
}, | ||
Mutation: { | ||
async setBlocksState(obj, args, context) { | ||
try { | ||
// TODO: update blocks state | ||
return { | ||
operation: generateSuccess('Blocks state updated successfully') | ||
} | ||
} catch (err) { | ||
return generateError(err) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# =============================================== | ||
# BLOCKS | ||
# =============================================== | ||
|
||
extend type Query { | ||
blocks( | ||
siteId: UUID! | ||
): [Block] | ||
} | ||
|
||
extend type Mutation { | ||
setBlocksState( | ||
siteId: UUID! | ||
states: [BlockStateInput]! | ||
): DefaultResponse | ||
|
||
deleteBlock( | ||
id: UUID! | ||
): DefaultResponse | ||
} | ||
|
||
# ----------------------------------------------- | ||
# TYPES | ||
# ----------------------------------------------- | ||
|
||
type Block { | ||
id: UUID | ||
block: String | ||
name: String | ||
description: String | ||
icon: String | ||
isEnabled: Boolean | ||
isCustom: Boolean | ||
config: JSON | ||
} | ||
|
||
input BlockStateInput { | ||
id: UUID! | ||
isEnabled: Boolean! | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { Model } from 'objection' | ||
|
||
/** | ||
* Block model | ||
*/ | ||
export class Block extends Model { | ||
static get tableName () { return 'blocks' } | ||
|
||
static get jsonAttributes () { | ||
return ['config'] | ||
} | ||
|
||
static async addBlock (data) { | ||
return WIKI.db.blocks.query().insertAndFetch({ | ||
block: data.block, | ||
name: data.name, | ||
description: data.description, | ||
icon: data.icon, | ||
isEnabled: true, | ||
isCustom: true, | ||
config: {} | ||
}) | ||
} | ||
|
||
static async deleteBlock (id) { | ||
return WIKI.db.blocks.query().deleteById(id) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.