Skip to content

Commit

Permalink
Merge pull request #204 from pieces-app/fix-shareable-link
Browse files Browse the repository at this point in the history
fix shareable link button
  • Loading branch information
bishoy-at-pieces authored Oct 10, 2024
2 parents 1ac4fcc + 189dff9 commit 373361e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from Pieces._pieces_lib.pieces_os_client.models.asset_reclassification import AssetReclassification
from Pieces._pieces_lib.pieces_os_client.models.linkify import Linkify
from Pieces._pieces_lib.pieces_os_client.models.shares import Shares
from Pieces._pieces_lib.pieces_os_client.models.share import Share

if TYPE_CHECKING:
from . import BasicAnnotation, BasicTag, BasicWebsite
Expand Down Expand Up @@ -148,6 +149,9 @@ def classification(self, classification):
transferables=False
)

@property
def shares(self) -> List[Share]:
return self.asset.shares.iterable if self.asset.shares else []


@property
Expand Down
13 changes: 8 additions & 5 deletions assets/list_assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,28 @@ def run(self,pieces_asset_id):
def run_async(self):
self.sheet = self.window.new_html_sheet("Loading","")
self.sheet_id = self.sheet.id()
self.update_sheet(self.sheet,self.pieces_asset_id)
self.update_sheet(self.sheet,self.pieces_asset_id, {})


@classmethod
def update_sheet(cls,sheet,asset_id,buttons_kwargs={}):
asset = BasicAsset(asset_id)
try:
api_response = PiecesSettings.api_client.asset_api.asset_specific_asset_export(asset_id, "MD")
markdown_text = asset.markdown
except:
return sublime.error_message("Asset Not Found")

markdown_text = api_response.raw.string.raw
if (not buttons_kwargs.get("share")) and (asset.shares):
buttons_kwargs["share"] = {
"title":"Copy Generated Link",
"url":f'subl:pieces_copy_link {{"content":"{asset.shares[0].link}", "asset_id":"{asset_id}"}}'}

markdown_text_table = tabulate_from_markdown(markdown_text,buttons = cls.create_html_buttons(sheet.id(),**buttons_kwargs))

mdpopups.update_html_sheet(sheet,markdown_text_table,css = ".div_wrapper {margin-left:2rem}",wrapper_class="div_wrapper")


try:
sheet.set_name(api_response.name)
sheet.set_name(asset.name)
except:
pass
cls.sheets_md[sheet.id()] = asset_id
Expand Down
2 changes: 1 addition & 1 deletion assets/share_asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,5 +127,5 @@ class PiecesCopyLinkCommand(sublime_plugin.WindowCommand):
def run(self,content,asset_id):
sublime.set_clipboard(content)
sheet = self.window.active_sheet()
PiecesListAssetsCommand.update_sheet(sheet,asset_id,buttons_kwargs={"share":{"title":"Copied"}})
PiecesListAssetsCommand.update_sheet(sheet,asset_id,buttons_kwargs={"share":{"title":"Copied","url":"noop"}})

0 comments on commit 373361e

Please sign in to comment.