Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support preferred vocabulary name #17

Merged
merged 6 commits into from
Nov 18, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: use Tiles component to render tiles
  • Loading branch information
benjifs committed Nov 18, 2023
commit 668f5cef070ee08303f08fc5b4120ee069dbbd0f
49 changes: 38 additions & 11 deletions src/js/Editors/Tiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import m from 'mithril'

import Tile from '../Components/Tile'

const OMDB_API_KEY = import.meta.env.VITE_OMDB_API_KEY

const NoteTile = {
view: ({ attrs }) => m(Tile, {
href: '/new/note',
Expand Down Expand Up @@ -86,15 +88,40 @@ const BookTile = {
})
}

export {
NoteTile,
ArticleTile,
ReplyTile,
BookmarkTile,
LikeTile,
ImageTile,
RSVPTile,
RecipeTile,
MovieTile,
BookTile
const PostTypes = {
note: NoteTile,
image: ImageTile,
reply: ReplyTile,
bookmark: BookmarkTile,
like: LikeTile,
article: ArticleTile,
rsvp: RSVPTile,
watch: OMDB_API_KEY ? MovieTile : null,
read: BookTile
}

const Tiles = (types, defaultTiles) => {
if (!defaultTiles || !defaultTiles.length) {
defaultTiles = [ 'note', 'image', 'reply', 'bookmark', 'like', 'article', 'rsvp', 'watch', 'read' ]
}
if (!types || !types.length) {
types = defaultTiles.map(t => ({ type: t }))
}
const tiles = types
.filter(pt => PostTypes[pt.type] && defaultTiles.includes(pt.type))
.map(pt => m(PostTypes[pt.type], { name: pt.name })) || []

return {
view: () =>
tiles && tiles.length ? m('.sp-tiles', tiles) : [
m('h3', 'no available tiles'),
m('p', [
'unsupported post types ',
m('a', { href: 'https://github.com/indieweb/micropub-extensions/issues/1', target: '_blank' },
m('i.far.fa-circle-question', { title: 'query for supported vocabulary discussion' }))
])
]
}
}

export default Tiles
43 changes: 2 additions & 41 deletions src/js/Pages/HomePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,56 +2,17 @@ import m from 'mithril'

import { Box } from '../Components/Box'
import { fetchMicropubConfig } from '../Controllers/Helpers'
import {
NoteTile,
ImageTile,
ReplyTile,
BookmarkTile,
LikeTile,
ArticleTile,
RSVPTile,
MovieTile,
BookTile
} from '../Editors/Tiles'
import Tiles from '../Editors/Tiles'
import Store from '../Models/Store'

const OMDB_API_KEY = import.meta.env.VITE_OMDB_API_KEY

const HomePage = () => {
const me = Store.getMe()
const postTypes = Store.getSession('post-types') || []

const getPostType = (type) => {
return postTypes.find(item => item.type === type)
}

const postTypeTile = (type, tile) => {
if (!postTypes) {
return m(tile)
}

const postType = getPostType(type)
return postType ? m(tile, { name: postType.name }) : null
}

return {
oninit: () => fetchMicropubConfig(),
view: () => [
m(Box, [
m('.sp-tiles', [
postTypeTile('note', NoteTile),
m(ImageTile),
postTypeTile('reply', ReplyTile),
postTypeTile('bookmark', BookmarkTile),
postTypeTile('like', LikeTile),
postTypeTile('article', ArticleTile),
postTypeTile('rsvp', RSVPTile),
OMDB_API_KEY
? postTypeTile('watch', MovieTile)
: null,
postTypeTile('read', BookTile)
])
]),
m(Box, m(Tiles(postTypes))),
m('section', [
m('p', [
'Logged in as ',
Expand Down
15 changes: 3 additions & 12 deletions src/js/Pages/SharePage.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import m from 'mithril'

import { Box } from '../Components/Box'
import {
LikeTile,
ReplyTile,
RSVPTile,
BookmarkTile
} from '../Editors/Tiles'
import Tiles from '../Editors/Tiles'
benjifs marked this conversation as resolved.
Show resolved Hide resolved

const SharePage = () => {
const postTypes = Store.getSession('post-types') || []
const parameterList = new URLSearchParams(window.location.search)
const params = {
title: parameterList.get('title'),
Expand Down Expand Up @@ -40,12 +36,7 @@ const SharePage = () => {
m('b', 'url:'),
params.url
]),
m('.sp-tiles', [
m(ReplyTile, { params: parameterList.toString() }),
m(BookmarkTile, { params: parameterList.toString() }),
m(LikeTile, { params: parameterList.toString() }),
m(RSVPTile, { params: parameterList.toString() })
])
m(Tiles(postTypes, [ 'reply', 'bookmark', 'like', 'rsvp' ]))
])
}
}
Expand Down