Skip to content

Commit

Permalink
fix: The id does not match expectations
Browse files Browse the repository at this point in the history
  • Loading branch information
haydenull committed May 20, 2022
1 parent b009921 commit dffcaa3
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 22 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "1.0.1",
"main": "dist/index.html",
"logseq": {
"id": "logseq-plugin-git",
"id": "logseq-git",
"icon": "logo.png"
},
"scripts": {
Expand Down
16 changes: 8 additions & 8 deletions src/helper/constants.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { SettingSchemaDesc } from "@logseq/libs/dist/LSPlugin.user"

export const COMMON_STYLE = `
#injected-ui-item-git-logseq-plugin-git {
#injected-ui-item-git-logseq-git {
position: relative;
}
#injected-ui-item-git-logseq-plugin-git #logseq-plugin-git--git #plugin-git-content-wrapper {
#injected-ui-item-git-logseq-git #logseq-git--git #plugin-git-content-wrapper {
position: absolute;
top: 36px;
left: 50%;
Expand All @@ -16,7 +16,7 @@ export const COMMON_STYLE = `
box-shadow: var(--tw-ring-offset-shadow,0 0 #0000),var(--tw-ring-shadow,0 0 #0000),var(--tw-shadow);
display: none;
}
#injected-ui-item-git-logseq-plugin-git #logseq-plugin-git--git #plugin-git-content-wrapper::before {
#injected-ui-item-git-logseq-git #logseq-git--git #plugin-git-content-wrapper::before {
content: '';
position: absolute;
top: -8px;
Expand All @@ -31,25 +31,25 @@ export const COMMON_STYLE = `
`

export const SHOW_POPUP_STYLE = `
#injected-ui-item-git-logseq-plugin-git #logseq-plugin-git--git #plugin-git-content-wrapper {
#injected-ui-item-git-logseq-git #logseq-git--git #plugin-git-content-wrapper {
display: block;
}
`
export const HIDE_POPUP_STYLE = `
#injected-ui-item-git-logseq-plugin-git #logseq-plugin-git--git #plugin-git-content-wrapper {
#injected-ui-item-git-logseq-git #logseq-git--git #plugin-git-content-wrapper {
display: none;
}
`

export const INACTIVE_STYLE = `
${COMMON_STYLE}
#injected-ui-item-git-logseq-plugin-git::after {
#injected-ui-item-git-logseq-git::after {
display: none;
}
`
export const ACTIVE_STYLE = `
${COMMON_STYLE}
#injected-ui-item-git-logseq-plugin-git::after {
#injected-ui-item-git-logseq-git::after {
display: block;
content: '';
position: absolute;
Expand All @@ -64,7 +64,7 @@ ${COMMON_STYLE}

export const LOADING_STYLE = `
${COMMON_STYLE}
#injected-ui-item-git-logseq-plugin-git::after {
#injected-ui-item-git-logseq-git::after {
display: block;
content: '';
position: absolute;
Expand Down
18 changes: 18 additions & 0 deletions src/helper/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,22 @@ export const showPopup = () => {
export const hidePopup = () => {
const _style = getPluginStyle()
setPluginStyle(`${_style}\n${HIDE_POPUP_STYLE}`)
}


export const debounce = (fn, wait: number = 100, environment?: any) => {
let timer = null
return function() {
// @ts-ignore
const context = environment || this
const args = arguments
if (timer) {
clearTimeout(timer)
timer = null
}
// @ts-ignore
timer = setTimeout(function () {
fn.apply(context, args)
}, wait)
}
}
27 changes: 14 additions & 13 deletions src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import ReactDOM from 'react-dom'
import App from './App'
import { BUTTONS, COMMON_STYLE, LOADING_STYLE, SETTINGS_SCHEMA, SHOW_POPUP_STYLE } from './helper/constants'
import { commit, log, push, status } from './helper/git'
import { checkStatus, getPluginStyle, hidePopup, setPluginStyle, showPopup } from './helper/util'
import { checkStatus, debounce, getPluginStyle, hidePopup, setPluginStyle, showPopup } from './helper/util'
import './index.css'

const isDevelopment = import.meta.env.DEV
Expand All @@ -18,7 +18,7 @@ if (isDevelopment) {
checkStatus()

logseq.provideModel({
async check() {
check: debounce(async function() {
console.log('[faiz:] === check click')
const status = await checkStatus()
if (status?.stdout === '') {
Expand All @@ -27,22 +27,22 @@ if (isDevelopment) {
logseq.App.showMsg('Changes detected:\n' + status.stdout, 'error')
}
hidePopup()
},
async commit() {
}),
commit: debounce(async function () {
hidePopup()
console.log('Committing...')
await commit(`[logseq-plugin-git:commit] ${new Date().toISOString()}`)
},
async push() {
}),
push: debounce(async function () {
setPluginStyle(LOADING_STYLE)
hidePopup()
console.log('Pushing...')
await push()
console.log('Checking status...')
checkStatus()
logseq.App.showMsg('Pushed Successfully!')
},
async commitAndPush() {
}),
commitAndPush: debounce(async function () {
setPluginStyle(LOADING_STYLE)
hidePopup()
console.log('Committing...')
Expand All @@ -52,17 +52,18 @@ if (isDevelopment) {
console.log('Checking status...')
checkStatus()
logseq.App.showMsg('Pushed Successfully!')
},
async log() {
}),
log: debounce(async function() {
console.log('[faiz:] === log click')
const res = await log()
logseq.App.showMsg(res?.stdout, 'error')
// logseq.App.showMsg(res?.stdout)
hidePopup()
},
async showPopup() {
}),
showPopup: debounce(async function() {
console.log('[faiz:] === showPopup click')
showPopup()
},
}),
})

logseq.App.registerUIItem('toolbar', {
Expand Down

0 comments on commit dffcaa3

Please sign in to comment.